| 1 | #!/usr/bin/env bash
|
| 2 | #
|
| 3 | # Usage:
|
| 4 | # doctools/cmark.sh <function name>
|
| 5 | #
|
| 6 | # Example:
|
| 7 | # doctools/cmark.sh download
|
| 8 | # doctools/cmark.sh extract
|
| 9 | # doctools/cmark.sh build
|
| 10 | # doctools/cmark.sh make-symlink
|
| 11 | # doctools/cmark.sh demo-ours # smoke test
|
| 12 |
|
| 13 | set -o nounset
|
| 14 | set -o pipefail
|
| 15 | set -o errexit
|
| 16 |
|
| 17 | REPO_ROOT=$(cd $(dirname $0)/.. && pwd)
|
| 18 | readonly REPO_ROOT
|
| 19 |
|
| 20 | readonly TAR_DIR=$REPO_ROOT/_cache
|
| 21 | readonly DEPS_DIR=$REPO_ROOT/../oil_DEPS
|
| 22 |
|
| 23 | readonly CMARK_VERSION=0.29.0
|
| 24 | readonly URL="https://github.com/commonmark/cmark/archive/$CMARK_VERSION.tar.gz"
|
| 25 |
|
| 26 | # 5/2020: non-hermetic dependency broke with Python 3 SyntaxError! Gah! TODO:
|
| 27 | # make this hermetic.
|
| 28 | #
|
| 29 | # https://pypi.org/project/Pygments/#history
|
| 30 | #
|
| 31 | # 7/2023: Download the wheel file
|
| 32 | # doctools/oils_doc.py OPTIONALLY uses this
|
| 33 | #
|
| 34 | # It's only used in the blog, so let's just put it in the oilshell.org repo,
|
| 35 | # not the oil repo
|
| 36 | #
|
| 37 | # 12/2024: I want a Markdown highlighter for doc/ul-table.md. It will look
|
| 38 | # nicer.
|
| 39 |
|
| 40 | download-old-pygments() {
|
| 41 | wget --directory _tmp --no-clobber \
|
| 42 | 'https://files.pythonhosted.org/packages/be/39/32da3184734730c0e4d3fa3b2b5872104668ad6dc1b5a73d8e477e5fe967/Pygments-2.5.2-py2.py3-none-any.whl'
|
| 43 | }
|
| 44 |
|
| 45 | demo-theirs() {
|
| 46 | echo '*hi*' | cmark
|
| 47 | }
|
| 48 |
|
| 49 | cmark-py() {
|
| 50 | PYTHONPATH='.:vendor' doctools/cmark.py "$@"
|
| 51 | }
|
| 52 |
|
| 53 | demo-ours() {
|
| 54 | export PYTHONPATH=.
|
| 55 |
|
| 56 | echo '*hi*' | cmark-py
|
| 57 |
|
| 58 | # This translates to <code class="language-sh"> which is cool.
|
| 59 | #
|
| 60 | # We could do syntax highlighting in JavaScript, or simply post-process HTML
|
| 61 |
|
| 62 | cmark-py <<'EOF'
|
| 63 | ```sh
|
| 64 | code
|
| 65 | block
|
| 66 | ```
|
| 67 |
|
| 68 | ```oil
|
| 69 | code
|
| 70 | block
|
| 71 | ```
|
| 72 | EOF
|
| 73 |
|
| 74 | # The $ syntax can be a little language.
|
| 75 | #
|
| 76 | # $oil-issue
|
| 77 | # $cross-ref
|
| 78 | # $blog-tag
|
| 79 | # $oil-source-file
|
| 80 | # $oil-commit
|
| 81 |
|
| 82 | cmark-py <<'EOF'
|
| 83 | [click here]($xref:re2c)
|
| 84 | EOF
|
| 85 |
|
| 86 | # Hm for some reason it gets rid of the blank lines in HTML. When rendering
|
| 87 | # to text, we would have to indent and insert blank lines? I guess we can
|
| 88 | # parse <p> and wrap it.
|
| 89 |
|
| 90 | cmark-py <<'EOF'
|
| 91 | Test spacing out:
|
| 92 |
|
| 93 | echo one
|
| 94 | echo two
|
| 95 |
|
| 96 | Another paragraph with `code`.
|
| 97 | EOF
|
| 98 | }
|
| 99 |
|
| 100 | demo-quirks() {
|
| 101 | ### Cases that came from writing ul-table
|
| 102 |
|
| 103 | export PYTHONPATH=.
|
| 104 |
|
| 105 | cmark-py --common-mark <<'EOF'
|
| 106 | 1. what `<table>`
|
| 107 | EOF
|
| 108 |
|
| 109 | # Very annoying: list items can't be empty
|
| 110 | # <span />
|
| 111 | cmark-py --common-mark <<'EOF'
|
| 112 | <table>
|
| 113 |
|
| 114 | - thead
|
| 115 | - <!-- list item can't be empty -->
|
| 116 | - Proc
|
| 117 | - Func
|
| 118 |
|
| 119 | </table>
|
| 120 | EOF
|
| 121 |
|
| 122 | cmark-py --common-mark <<'EOF'
|
| 123 | - <tr-attrs class=foo /> text required here
|
| 124 | - one
|
| 125 | - two
|
| 126 | EOF
|
| 127 |
|
| 128 | cmark-py --common-mark <<'EOF'
|
| 129 | - tr <tr-attrs class=foo />
|
| 130 | - one
|
| 131 | - two
|
| 132 | EOF
|
| 133 |
|
| 134 | # Weird case - the `proc` is sometimes not expanded to <code>proc</code>
|
| 135 | cmark-py --common-mark <<'EOF'
|
| 136 | - <span /> ... More `proc` features
|
| 137 | - <span />
|
| 138 | More `proc` features
|
| 139 | - <span /> <!-- why does this fix it? -->
|
| 140 | More `proc` features
|
| 141 | EOF
|
| 142 |
|
| 143 | # This has & in an attr value, which our HTML lexer needs to handle
|
| 144 | cmark-py --common-mark <<'EOF'
|
| 145 | from [ampersand][]
|
| 146 |
|
| 147 | [ampersand]: http://google.com/?q=foo&z=z
|
| 148 | EOF
|
| 149 |
|
| 150 | # Only is standard
|
| 151 | cmark-py --common-mark <<'EOF'
|
| 152 | - tr
|
| 153 | - -
|
| 154 | - &sp; -
|
| 155 | - &zwsp; -
|
| 156 | EOF
|
| 157 |
|
| 158 | # BUG: parse error because backticks span a line
|
| 159 |
|
| 160 | return
|
| 161 | cmark-py <<'EOF'
|
| 162 | 1. The Markdown translator produces a `<table> <ul> <li> ... </li> </ul>
|
| 163 | </table>` structure.
|
| 164 | EOF
|
| 165 | }
|
| 166 |
|
| 167 | demo-htm8() {
|
| 168 | ### Cases that came from developing HTM8
|
| 169 |
|
| 170 | export PYTHONPATH=.
|
| 171 |
|
| 172 | cmark-py --common-mark <<'EOF'
|
| 173 | [bash]($xref:bash)
|
| 174 |
|
| 175 | [other][]
|
| 176 |
|
| 177 | [other]: $xref
|
| 178 |
|
| 179 | EOF
|
| 180 | }
|
| 181 |
|
| 182 | "$@"
|