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

94 lines, 22 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
46demo-ours() {
47 export PYTHONPATH=.
48
49 echo '*hi*' | doctools/cmark.py
50
51 # This translates to <code class="language-sh"> which is cool.
52 #
53 # We could do syntax highlighting in JavaScript, or simply post-process HTML
54
55 doctools/cmark.py <<'EOF'
56```sh
57code
58block
59```
60
61```oil
62code
63block
64```
65EOF
66
67 # The $ syntax can be a little language.
68 #
69 # $oil-issue
70 # $cross-ref
71 # $blog-tag
72 # $oil-source-file
73 # $oil-commit
74
75 doctools/cmark.py <<'EOF'
76[click here]($xref:re2c)
77EOF
78
79 # Hm for some reason it gets rid of the blank lines in HTML. When rendering
80 # to text, we would have to indent and insert blank lines? I guess we can
81 # parse <p> and wrap it.
82
83 doctools/cmark.py <<'EOF'
84Test spacing out:
85
86 echo one
87 echo two
88
89Another paragraph with `code`.
90EOF
91
92}
93
94"$@"