OILS / doctools / cmark.sh View on Github | oils.pub

182 lines, 41 significant
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
13set -o nounset
14set -o pipefail
15set -o errexit
16
17REPO_ROOT=$(cd $(dirname $0)/.. && pwd)
18readonly REPO_ROOT
19
20readonly TAR_DIR=$REPO_ROOT/_cache
21readonly DEPS_DIR=$REPO_ROOT/../oil_DEPS
22
23readonly CMARK_VERSION=0.29.0
24readonly 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
40download-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
45demo-theirs() {
46 echo '*hi*' | cmark
47}
48
49cmark-py() {
50 PYTHONPATH='.:vendor' doctools/cmark.py "$@"
51}
52
53demo-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
64code
65block
66```
67
68```oil
69code
70block
71```
72EOF
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)
84EOF
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'
91Test spacing out:
92
93 echo one
94 echo two
95
96Another paragraph with `code`.
97EOF
98}
99
100demo-quirks() {
101 ### Cases that came from writing ul-table
102
103 export PYTHONPATH=.
104
105 cmark-py --common-mark <<'EOF'
1061. what `<table>`
107EOF
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>
120EOF
121
122 cmark-py --common-mark <<'EOF'
123- <tr-attrs class=foo /> text required here
124 - one
125 - two
126EOF
127
128cmark-py --common-mark <<'EOF'
129- tr <tr-attrs class=foo />
130 - one
131 - two
132EOF
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
141EOF
142
143 # This has &amp; in an attr value, which our HTML lexer needs to handle
144 cmark-py --common-mark <<'EOF'
145from [ampersand][]
146
147[ampersand]: http://google.com/?q=foo&z=z
148EOF
149
150 # Only &nbsp; is standard
151 cmark-py --common-mark <<'EOF'
152- tr
153 - &nbsp; -
154 - &sp; -
155 - &zwsp; -
156EOF
157
158 # BUG: parse error because backticks span a line
159
160 return
161 cmark-py <<'EOF'
1621. The Markdown translator produces a `<table> <ul> <li> ... </li> </ul>
163 </table>` structure.
164EOF
165}
166
167demo-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
179EOF
180}
181
182"$@"