OILS / doctools / cmark.sh View on Github | oilshell.org

165 lines, 37 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
37download-old-pygments() {
38 wget --directory _tmp --no-clobber \
39 'https://files.pythonhosted.org/packages/be/39/32da3184734730c0e4d3fa3b2b5872104668ad6dc1b5a73d8e477e5fe967/Pygments-2.5.2-py2.py3-none-any.whl'
40}
41
42demo-theirs() {
43 echo '*hi*' | cmark
44}
45
46cmark-py() {
47 PYTHONPATH='.:vendor' doctools/cmark.py "$@"
48}
49
50demo-ours() {
51 export PYTHONPATH=.
52
53 echo '*hi*' | cmark-py
54
55 # This translates to <code class="language-sh"> which is cool.
56 #
57 # We could do syntax highlighting in JavaScript, or simply post-process HTML
58
59 cmark-py <<'EOF'
60```sh
61code
62block
63```
64
65```oil
66code
67block
68```
69EOF
70
71 # The $ syntax can be a little language.
72 #
73 # $oil-issue
74 # $cross-ref
75 # $blog-tag
76 # $oil-source-file
77 # $oil-commit
78
79 cmark-py <<'EOF'
80[click here]($xref:re2c)
81EOF
82
83 # Hm for some reason it gets rid of the blank lines in HTML. When rendering
84 # to text, we would have to indent and insert blank lines? I guess we can
85 # parse <p> and wrap it.
86
87 cmark-py <<'EOF'
88Test spacing out:
89
90 echo one
91 echo two
92
93Another paragraph with `code`.
94EOF
95}
96
97demo-quirks() {
98 ### Cases that came from writing ul-table
99
100 export PYTHONPATH=.
101
102 cmark-py <<'EOF'
1031. what `<table>`
104EOF
105
106 # Very annoying: list items can't be empty
107 # <span />
108 cmark-py --common-mark <<'EOF'
109<table>
110
111- thead
112 - <!-- list item can't be empty -->
113 - Proc
114 - Func
115
116</table>
117EOF
118
119 cmark-py --common-mark <<'EOF'
120- <tr-attrs class=foo /> text required here
121 - one
122 - two
123EOF
124
125cmark-py --common-mark <<'EOF'
126- tr <tr-attrs class=foo />
127 - one
128 - two
129EOF
130
131 # Weird case - the `proc` is sometimes not expanded to <code>proc</code>
132 cmark-py --common-mark <<'EOF'
133- <span /> ... More `proc` features
134- <span />
135 More `proc` features
136- <span /> <!-- why does this fix it? -->
137 More `proc` features
138EOF
139
140 # This has &amp; in an attr value, which our HTML lexer needs to handle
141 cmark-py --common-mark <<'EOF'
142from [ampersand][]
143
144[ampersand]: http://google.com/?q=foo&z=z
145EOF
146
147 # Only &nbsp; is standard
148 cmark-py --common-mark <<'EOF'
149- tr
150 - &nbsp; -
151 - &sp; -
152 - &zwsp; -
153EOF
154
155 # BUG: parse error because backticks span a line
156
157 return
158 cmark-py <<'EOF'
1591. The Markdown translator produces a `<table> <ul> <li> ... </li> </ul>
160 </table>` structure.
161EOF
162
163}
164
165"$@"