| 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 |
|
| 22 | readonly CMARK_VERSION=0.29.0
|
| 23 | readonly URL="https://github.com/commonmark/cmark/archive/$CMARK_VERSION.tar.gz"
|
| 24 |
|
| 25 | # 5/2020: non-hermetic dependency broke with Python 3 SyntaxError! Gah! TODO:
|
| 26 | # make this hermetic.
|
| 27 | #
|
| 28 | # https://pypi.org/project/Pygments/#history
|
| 29 | #
|
| 30 | # 7/2023: Download the wheel file
|
| 31 | # doctools/oils_doc.py OPTIONALLY uses this
|
| 32 | #
|
| 33 | # It's only used in the blog, so let's just put it in the oilshell.org repo,
|
| 34 | # not the oil repo
|
| 35 | #
|
| 36 | # 12/2024: I want a Markdown highlighter for doc/ul-table.md. It will look
|
| 37 | # nicer.
|
| 38 |
|
| 39 | download-old-pygments() {
|
| 40 | wget --directory _tmp --no-clobber \
|
| 41 | 'https://files.pythonhosted.org/packages/be/39/32da3184734730c0e4d3fa3b2b5872104668ad6dc1b5a73d8e477e5fe967/Pygments-2.5.2-py2.py3-none-any.whl'
|
| 42 | }
|
| 43 |
|
| 44 | demo-theirs() {
|
| 45 | echo '*hi*' | cmark
|
| 46 | }
|
| 47 |
|
| 48 | cmark-py() {
|
| 49 | PYTHONPATH='.:vendor' doctools/cmark.py "$@"
|
| 50 | }
|
| 51 |
|
| 52 | demo-ours() {
|
| 53 | export PYTHONPATH=.
|
| 54 |
|
| 55 | echo '*hi*' | cmark-py
|
| 56 |
|
| 57 | # This translates to <code class="language-sh"> which is cool.
|
| 58 | #
|
| 59 | # We could do syntax highlighting in JavaScript, or simply post-process HTML
|
| 60 |
|
| 61 | cmark-py <<'EOF'
|
| 62 | ```sh
|
| 63 | code
|
| 64 | block
|
| 65 | ```
|
| 66 |
|
| 67 | ```oil
|
| 68 | code
|
| 69 | block
|
| 70 | ```
|
| 71 | EOF
|
| 72 |
|
| 73 | # The $ syntax can be a little language.
|
| 74 | #
|
| 75 | # $oil-issue
|
| 76 | # $cross-ref
|
| 77 | # $blog-tag
|
| 78 | # $oil-source-file
|
| 79 | # $oil-commit
|
| 80 |
|
| 81 | cmark-py <<'EOF'
|
| 82 | [click here]($xref:re2c)
|
| 83 | EOF
|
| 84 |
|
| 85 | # Hm for some reason it gets rid of the blank lines in HTML. When rendering
|
| 86 | # to text, we would have to indent and insert blank lines? I guess we can
|
| 87 | # parse <p> and wrap it.
|
| 88 |
|
| 89 | cmark-py <<'EOF'
|
| 90 | Test spacing out:
|
| 91 |
|
| 92 | echo one
|
| 93 | echo two
|
| 94 |
|
| 95 | Another paragraph with `code`.
|
| 96 | EOF
|
| 97 | }
|
| 98 |
|
| 99 | demo-quirks() {
|
| 100 | ### Cases that came from writing ul-table
|
| 101 |
|
| 102 | export PYTHONPATH=.
|
| 103 |
|
| 104 | cmark-py --common-mark <<'EOF'
|
| 105 | 1. what `<table>`
|
| 106 | EOF
|
| 107 |
|
| 108 | # Very annoying: list items can't be empty
|
| 109 | # <span />
|
| 110 | cmark-py --common-mark <<'EOF'
|
| 111 | <table>
|
| 112 |
|
| 113 | - thead
|
| 114 | - <!-- list item can't be empty -->
|
| 115 | - Proc
|
| 116 | - Func
|
| 117 |
|
| 118 | </table>
|
| 119 | EOF
|
| 120 |
|
| 121 | cmark-py --common-mark <<'EOF'
|
| 122 | - <tr-attrs class=foo /> text required here
|
| 123 | - one
|
| 124 | - two
|
| 125 | EOF
|
| 126 |
|
| 127 | cmark-py --common-mark <<'EOF'
|
| 128 | - tr <tr-attrs class=foo />
|
| 129 | - one
|
| 130 | - two
|
| 131 | EOF
|
| 132 |
|
| 133 | # Weird case - the `proc` is sometimes not expanded to <code>proc</code>
|
| 134 | cmark-py --common-mark <<'EOF'
|
| 135 | - <span /> ... More `proc` features
|
| 136 | - <span />
|
| 137 | More `proc` features
|
| 138 | - <span /> <!-- why does this fix it? -->
|
| 139 | More `proc` features
|
| 140 | EOF
|
| 141 |
|
| 142 | # This has & in an attr value, which our HTML lexer needs to handle
|
| 143 | cmark-py --common-mark <<'EOF'
|
| 144 | from [ampersand][]
|
| 145 |
|
| 146 | [ampersand]: http://google.com/?q=foo&z=z
|
| 147 | EOF
|
| 148 |
|
| 149 | # Only is standard
|
| 150 | cmark-py --common-mark <<'EOF'
|
| 151 | - tr
|
| 152 | - -
|
| 153 | - &sp; -
|
| 154 | - &zwsp; -
|
| 155 | EOF
|
| 156 |
|
| 157 | # BUG: parse error because backticks span a line
|
| 158 |
|
| 159 | return
|
| 160 | cmark-py <<'EOF'
|
| 161 | 1. The Markdown translator produces a `<table> <ul> <li> ... </li> </ul>
|
| 162 | </table>` structure.
|
| 163 | EOF
|
| 164 | }
|
| 165 |
|
| 166 | demo-htm8() {
|
| 167 | ### Cases that came from developing HTM8
|
| 168 |
|
| 169 | export PYTHONPATH=.
|
| 170 |
|
| 171 | cmark-py --common-mark <<'EOF'
|
| 172 | [bash]($xref:bash)
|
| 173 |
|
| 174 | [other][]
|
| 175 |
|
| 176 | [other]: $xref
|
| 177 |
|
| 178 | EOF
|
| 179 | }
|
| 180 |
|
| 181 | demo-quarto() {
|
| 182 | ### Cases that came from developing HTM8
|
| 183 |
|
| 184 | export PYTHONPATH=.
|
| 185 |
|
| 186 | # Standard Markdown
|
| 187 | cmark-py --common-mark <<'EOF'
|
| 188 |
|
| 189 | Hello
|
| 190 |
|
| 191 | code
|
| 192 | block
|
| 193 |
|
| 194 | Python:
|
| 195 |
|
| 196 | ```python
|
| 197 | print("hi")
|
| 198 | ```
|
| 199 | EOF
|
| 200 |
|
| 201 | # Quarto extensions
|
| 202 | # Turns out as class="language-{python} which isn't ideal
|
| 203 | cmark-py --common-mark <<'EOF'
|
| 204 |
|
| 205 | Executable Python
|
| 206 |
|
| 207 | ```{python}
|
| 208 | print("hi")
|
| 209 | ```
|
| 210 |
|
| 211 | With attributes
|
| 212 |
|
| 213 | ```{python}
|
| 214 | #| attr: value
|
| 215 | #| fig-cap: "A line plot"
|
| 216 | print("hi")
|
| 217 | ```
|
| 218 | EOF
|
| 219 |
|
| 220 | # Another syntax I saw
|
| 221 | # This appears to be R Markdown, which is an older syntax that Quarto
|
| 222 | # doesn't use
|
| 223 | # But it accepts
|
| 224 | #
|
| 225 | # Hm cmark omits everything after the space
|
| 226 |
|
| 227 | cmark-py --common-mark <<'EOF'
|
| 228 |
|
| 229 | Executable Python
|
| 230 |
|
| 231 | ```{r setup, include=FALSE}
|
| 232 | print("hi")
|
| 233 | ```
|
| 234 | EOF
|
| 235 | }
|
| 236 |
|
| 237 | "$@"
|