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 | download-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 |
|
42 | demo-theirs() {
|
43 | echo '*hi*' | cmark
|
44 | }
|
45 |
|
46 | cmark-py() {
|
47 | PYTHONPATH='.:vendor' doctools/cmark.py "$@"
|
48 | }
|
49 |
|
50 | demo-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
|
61 | code
|
62 | block
|
63 | ```
|
64 |
|
65 | ```oil
|
66 | code
|
67 | block
|
68 | ```
|
69 | EOF
|
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)
|
81 | EOF
|
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'
|
88 | Test spacing out:
|
89 |
|
90 | echo one
|
91 | echo two
|
92 |
|
93 | Another paragraph with `code`.
|
94 | EOF
|
95 | }
|
96 |
|
97 | demo-quirks() {
|
98 | ### Cases that came from writing ul-table
|
99 |
|
100 | export PYTHONPATH=.
|
101 |
|
102 | cmark-py <<'EOF'
|
103 | 1. what `<table>`
|
104 | EOF
|
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>
|
117 | EOF
|
118 |
|
119 | cmark-py --common-mark <<'EOF'
|
120 | - <tr-attrs class=foo /> text required here
|
121 | - one
|
122 | - two
|
123 | EOF
|
124 |
|
125 | cmark-py --common-mark <<'EOF'
|
126 | - tr <tr-attrs class=foo />
|
127 | - one
|
128 | - two
|
129 | EOF
|
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
|
138 | EOF
|
139 |
|
140 | # This has & in an attr value, which our HTML lexer needs to handle
|
141 | cmark-py --common-mark <<'EOF'
|
142 | from [ampersand][]
|
143 |
|
144 | [ampersand]: http://google.com/?q=foo&z=z
|
145 | EOF
|
146 |
|
147 | # Only is standard
|
148 | cmark-py --common-mark <<'EOF'
|
149 | - tr
|
150 | - -
|
151 | - &sp; -
|
152 | - &zwsp; -
|
153 | EOF
|
154 |
|
155 | # BUG: parse error because backticks span a line
|
156 |
|
157 | return
|
158 | cmark-py <<'EOF'
|
159 | 1. The Markdown translator produces a `<table> <ul> <li> ... </li> </ul>
|
160 | </table>` structure.
|
161 | EOF
|
162 |
|
163 | }
|
164 |
|
165 | "$@"
|