Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/render.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ jobs:
- name: Compile ZIPs
run: nix develop --profile /tmp/dev-profile --command make all-zips

- name: Render regression tests
run: nix develop --profile /tmp/dev-profile --command make test
Comment thread
daira marked this conversation as resolved.

- name: Set base ref
run: |
git show --format=%H --no-notes --no-patch "HEAD~1" -- |tee base_ref
Expand Down
25 changes: 21 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ all-zips: .Makefile.uptodate
echo "$(patsubst zips/%,%,$(sort $(wildcard zips/draft-*.rst) $(wildcard zips/draft-*.md)))" >.draftfilelist.new
diff .draftfilelist.current .draftfilelist.new || cp -f .draftfilelist.new .draftfilelist.current
rm -f .draftfilelist.new
mkdir -p rendered
cp -r static/* rendered/
$(MAKE) README.rst
$(MAKE) rendered/index.html $(addprefix rendered/,$(addsuffix .html,$(basename $(patsubst zips/%,%,$(sort $(wildcard zips/*.rst) $(wildcard zips/*.md))))))

Expand All @@ -37,8 +35,10 @@ discard:
rm -r rendered
git checkout -- 'README.rst'

.Makefile.uptodate: Makefile render.sh
.Makefile.uptodate: Makefile render.sh $(wildcard static/assets/fonts/*) $(wildcard static/assets/images/*) $(wildcard static/css/*)
$(MAKE) clean
mkdir -p rendered
cp -r static/* rendered
touch .Makefile.uptodate

rendered/index.html: README.rst render.sh
Expand All @@ -50,10 +50,27 @@ rendered/%.html: zips/%.rst render.sh
rendered/%.html: zips/%.md render.sh
./render.sh $(MARKDOWN_OPTION) $< $@

# Render-regression test fixtures, kept out of zips/ so the ZIP set stays clean.
# Output goes under rendered/test/, with css/ and assets/ symlinked from the parent
# rendered/ dir so the pages are viewable with correct styling in a browser.
rendered/test/%.html: test/render/%.rst render.sh | rendered/test
./render.sh --rst $< $@

rendered/test/%.html: test/render/%.md render.sh | rendered/test
./render.sh $(MARKDOWN_OPTION) $< $@

rendered/test:
mkdir -p rendered/test
ln -sfn ../css rendered/test/css
ln -sfn ../assets rendered/test/assets

README.rst: .zipfilelist.current .draftfilelist.current makeindex.sh README.template $(wildcard zips/zip-*.rst) $(wildcard zips/zip-*.md) $(wildcard zips/draft-*.rst) $(wildcard zips/draft-*.md)
./makeindex.sh | cat README.template - >README.rst

.PHONY: linkcheck updatecheck clean all-clean
.PHONY: linkcheck updatecheck clean all-clean test
test:
./test/render-test.sh

linkcheck: all
./links_and_dests.py --check $(filter-out $(wildcard rendered/draft-*.html),$(wildcard rendered/*.html)) $(filter-out rendered/protocol/sprout.pdf,$(wildcard rendered/protocol/*.pdf))

Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ written.
<tr> <td><span class="reserved">240</span></td> <td class="left"><a class="reserved" href="zips/zip-0240.md">Standard Transaction Rules</a></td> <td>Reserved</td> <td class="left"><a href="https://github.com/zcash/zips/issues/648">zips#648</a></td>
<tr> <td>245</td> <td class="left"><a href="zips/zip-0245.rst">Transaction Identifier Digests & Signature Validation for Transparent Zcash Extensions</a></td> <td>Draft</td> <td class="left"><a href="https://github.com/zcash/zips/issues/384">zips#384</a></td>
<tr> <td>246</td> <td class="left"><a href="zips/zip-0246.rst">Digests for the Version 6 Transaction Format</a></td> <td>Draft</td> <td class="left"></td>
<tr> <td>258</td> <td class="left"><a href="zips/zip-0258.md">Deployment of the NU6.3 Network Upgrade</a></td> <td>Draft</td> <td class="left"></td>
<tr> <td>258</td> <td class="left"><a href="zips/zip-0258.md">Deployment of the NU6.3 Network Upgrade</a></td> <td>Draft</td> <td class="left"><a href="https://github.com/zcash/zips/issues/1304">zips#1304</a></td>
<tr> <td><span class="reserved">260</span></td> <td class="left"><a class="reserved" href="zips/zip-0260.md">Extending Block Messages with Additional Authentication Data</a></td> <td>Reserved</td> <td class="left"><a href="https://github.com/zcash/zips/issues/522">zips#522</a></td>
<tr> <td><span class="reserved">270</span></td> <td class="left"><a class="reserved" href="zips/zip-0270.md">Key Rotation for Tracked Signing Keys</a></td> <td>Reserved</td> <td class="left"><a href="https://github.com/zcash/zips/issues/1047">zips#1047</a></td>
<tr> <td>302</td> <td class="left"><a href="zips/zip-0302.rst">Standardized Memo Field Format</a></td> <td>Draft</td> <td class="left"><a href="https://github.com/zcash/zips/issues/366">zips#366</a></td>
Expand Down
62 changes: 44 additions & 18 deletions render.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ if ! [ -f "${inputfile}" ]; then
exit
fi

# Set RENDER_INTERMEDIATE to a path to capture the post-sed, pre-renderer stream
# (used by the render regression tests; see test/). Defaults to /dev/null, so normal
# runs are unaffected and the `tee` below is a harmless pass-through.
intermediate="${RENDER_INTERMEDIATE:-/dev/null}"

if [ "x$1" = "x--rst" ]; then
filetype='.rst'
else
Expand All @@ -38,34 +43,54 @@ Math3='<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.33/dist/contri

Mermaid='<script defer src="https://cdn.jsdelivr.net/npm/mermaid@11.12.3/dist/mermaid.min.js" integrity="sha384-jFhLSLFn4m565eRAS0CDMWubMqOtfZWWbE8kqgGdU+VHbJ3B2G/4X8u+0BM8MtdU" crossorigin="anonymous" onload="mermaid.initialize({ startOnLoad: true });"></script>'

# Our `style.css` must load *after* KaTeX's CSS so that our `.katex .*` overrides win the
# cascade (several KaTeX font rules have the same specificity as ours). Both paths inject
# `ViewAndStyle` at the end of `<head>`, so our stylesheet always loads last. (Unlike
# `<meta charset>`, the viewport meta has no early-placement requirement.)
ViewAndStyle='<meta name="viewport" content="width=device-width, initial-scale=1"><link rel="stylesheet" href="css/style.css">'

cat <(
if [ "x$1" = "x--rst" ]; then
# These are basic regexps so \+ is needed, not +.
# We use the Unicode 💲 character to move an escaped $ out of the way,
# which is much easier than trying to handle escapes within a capture.
# These are basic regexps so \+ is needed, not +, and similarly for \?.
# We use the Unicode 💲 character to move an escaped $ out of the way,
# which is much easier than trying to handle escapes within a capture.
# In both rst and Markdown, we must be careful not to rewrite a math span
# so that it has a non-whitespace character immediately after it.

cat "${inputfile}" \
| sed 's|[\][$]|💲|g;
s|[$]\([^$]\+\)[$]\([.,:;!?)-]\)|:math:`\1\\!`\2|g;
if [ "x$1" = "x--rst" ]; then
# For rst we want to unescape `\$`, because $ is not reserved without our $ extension.
cat "${inputfile}" |
sed 's|[\][$]|💲|g;
s|[$]\([^$]\+\)[$]\([—)-]\)|:math:`\1\\kern-0.15em` \2|g;
s|[$]\([^$]\+\)[$]\([.,:;!?]\)$|:math:`\1\\kern-0.03em\\textsf{\2}`|g;
s|[$]\([^$]\+\)[$]\([.,:;!?]\)\ |:math:`\1\\kern-0.03em\\textsf{\2}` |g;
s|[$]\([^$]\+\)[$]|:math:`\1`|g;
s|💲|$|g' \
| rst2html5 -v --title="${title}" - \
| sed "s|<script src=\"http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML\"></script>|${Math1}\n ${Math2}\n ${Math3}|;
s|💲|$|g' |
tee "${intermediate}" |
rst2html5 -v --title="${title}" - |
sed "s|<script src=\"http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML\"></script>|${Math1}\n ${Math2}\n ${Math3}|;
s|</head>|${ViewAndStyle}</head>|"
else
if [ "x$1" = "x--pandoc" ]; then
# Not actually MathJax. KaTeX is compatible if we use the right headers.
pandoc --mathjax --from=markdown --to=html "${inputfile}" --output="${outputfile}.temp"
else
cat "${inputfile}" \
| sed 's|[\][$]|💲|g;
s|[$]\([.,:;!?-][^ $]\)|💲\1|g;
s|[$]\([.,:;!?-]\)|\\kern-0.05em\\textsf{\\small \1}$|g;
s|[$]—|\\kern-0.3em$ —|g;
s|💲|$|g' \
| multimarkdown -o "${outputfile}.temp"
# For Markdown we just want to protect `\$`.
# We match a whole `$...$` span (as the rst rules above do), so we only
# ever rewrite a *closing* delimiter. Matching a lone `$` would misfire
# on the *opening* `$` of a span whose content starts with punctuation
# (e.g. `$-x$`). Caveat: this is line-by-line, so a multi-line `$...$`
# span (which Markdown allows) is not matched. Punctuation just after
# such a span won't be fixed, and a line carrying both one span's close
# and another's open can still mismatch. These cases are rare, would show
# up when reviewing rendered output, and are easy to work around.
cat "${inputfile}" |
sed 's|[\][$]|💲|g;
s|[$]\([^$]\+\)[$]\([—)-]\)|$\1\\kern-0.15em$ \2|g;
s|[$]\([^$]\+\)[$]\([.,:;!?]\)$|$\1\\kern-0.05em\\textsf{\2}$|g;
s|[$]\([^$]\+\)[$]\([.,:;!?]\)\ |$\1\\kern-0.05em\\textsf{\2}$ |g;
s|💲|\\$|g' |
tee "${intermediate}" |
multimarkdown -o "${outputfile}.temp"
fi

# Both pandoc and multimarkdown just output the HTML body.
Expand All @@ -74,7 +99,6 @@ cat <(
echo "<head>"
echo " <title>${title}</title>"
echo " <meta charset=\"utf-8\" />"
echo " ${ViewAndStyle}"
if grep -q -E 'class="mermaid"' "${outputfile}.temp"; then
echo " ${Mermaid}"
fi
Expand All @@ -83,6 +107,8 @@ cat <(
echo " ${Math2}"
echo " ${Math3}"
fi
# ViewAndStyle last, so our `style.css` loads after the KaTeX CSS (as in rst).
echo " ${ViewAndStyle}"
echo "</head>"
echo "<body>"
cat "${outputfile}.temp"
Expand Down
33 changes: 24 additions & 9 deletions static/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -310,14 +310,14 @@ div.warning + p {
@font-face {
font-family: raleway;
src: url('../assets/fonts/Raleway-VariableFont_wght.ttf') format('truetype');
font-weight: normal;
font-weight: 100 900;
font-style: normal;
}

@font-face {
font-family: ralewayitalic;
src: url('../assets/fonts/Raleway-Italic-VariableFont_wght.ttf') format('truetype');
font-weight: normal;
font-weight: 100 900;
font-style: italic;
}

Expand Down Expand Up @@ -478,13 +478,28 @@ pre {
font-size: 1.2em;
}

/* Render \textit{...} inside KaTeX in the body font, so slanted identifiers
in math (e.g. pool names such as IronwoodPool) match the slanted look of
Markdown emphasis *foo* in surrounding text. */
/*
Render `\textit{...}` inside KaTeX in Raleway Italic. This is used for pool names
such as IronwoodPool, matching *Ironwood pool* in surrounding text.
*/
.katex .textit {
font-family: 'ralewayitalic', Arial, 'Helvetica Neue', Helvetica, sans-serif;
font-style: italic;
font-size: 0.92em;
font-family: 'ralewayitalic', Arial, 'Helvetica Neue', Helvetica, sans-serif !important;
font-style: italic !important;
font-weight: 500 !important;
font-size: 0.92em !important;
}

/*
Render `\textsf{...}` inside KaTeX in the body font. This is used to render trailing
punctuation, e.g. `$x$.` gets transformed by `render.sh` to `$x\kern-0.05em\textsf{.}$`
(or the equivalent using :math:`...`), to avoid a line break between the math and the
punctuation. It's also useful to make text-in-math match the surrounding font, e.g.
in `\cases` where we can't just skip out of math mode.
*/
.katex .textsf {
font-family: 'robotoregular', Arial, 'Helvetica Neue', Helvetica, sans-serif !important;
font-style: normal !important;
font-size: 0.83em !important;
}

div.math {
Expand Down Expand Up @@ -594,7 +609,7 @@ a.footnote-ref sup, a.footnote sup {

em {
font-family: 'ralewayitalic',Arial,Helvetica Neue,Helvetica,sans-serif;
font-weight: 720;
font-weight: 500;
font-stretch: 85%;
}

Expand Down
59 changes: 59 additions & 0 deletions test/render-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash
# Regression test for render.sh's math-punctuation rewriting and stylesheet ordering.
#
# For each fixture under test/render/, render it via the Makefile (capturing render.sh's
# post-sed, pre-renderer stream through RENDER_INTERMEDIATE) and compare that intermediate
# against the checked-in golden. Also check, in the rendered HTML, that our style.css loads
# after the KaTeX CSS (so our `.katex .*` font overrides win the cascade).
#
# Update goldens after an intended render.sh change with:
# RENDER_INTERMEDIATE=test/render/<stem>.intermediate make rendered/test/<stem>.html
set -euo pipefail

cd "$(dirname "$0")/.." # repo root

# `.Makefile.uptodate` runs `make clean` (which removes temp/), so create temp/ after it.
make .Makefile.uptodate >/dev/null
mkdir -p temp
# Clean up our own intermediates on exit, so we don't leave files that would trip
# update_check.sh's `rmdir temp` (it shares temp/ but expects to empty it).
trap 'rm -f temp/test-render-*.intermediate' EXIT

status=0

check() {
stem="$1"
html="rendered/test/${stem}.html"
golden="test/render/${stem}.intermediate"
got="temp/${stem}.intermediate"

rm -f "$html"
RENDER_INTERMEDIATE="$got" make "$html" >/dev/null

if diff -u "$golden" "$got"; then
echo "PASS intermediate ${stem}"
else
echo "FAIL intermediate ${stem} (diff above: golden vs actual)"
status=1
fi

# Our style.css must load after the KaTeX CSS, else our `.katex .*` overrides lose.
katex_line="$(grep -n 'katex\.min\.css' "$html" | head -1 | cut -d: -f1 || true)"
style_line="$(grep -n 'href="css/style\.css"' "$html" | head -1 | cut -d: -f1 || true)"
if [ -n "$katex_line" ] && [ -n "$style_line" ] && [ "$style_line" -gt "$katex_line" ]; then
echo "PASS css-order ${stem} (style.css@${style_line} after katex@${katex_line})"
else
echo "FAIL css-order ${stem} (katex=${katex_line:-none} style=${style_line:-none})"
status=1
fi
}

check test-render-rst
check test-render-md

if [ "$status" -eq 0 ]; then
echo "render tests: PASS"
else
echo "render tests: FAIL"
fi
exit "$status"
26 changes: 26 additions & 0 deletions test/render/test-render-md.intermediate
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Title: Render test (Markdown)

Trailing period: $x\kern-0.05em\textsf{.}$

Comma then space: $a\kern-0.05em\textsf{,}$ then.

Hyphen after span: $n\kern-0.15em$ -bit.

Threshold: $t\kern-0.15em$ -of-$n\kern-0.05em\textsf{.}$

Close paren: (see $i\kern-0.15em$ ).

Em-dash directly after: $x\kern-0.15em$ —note.

Leading minus preserved: $-x$ stays.

Leading minus then period: $-y\kern-0.05em\textsf{.}$

Punctuation mid-token unchanged: $x$.5 here.

Plain span: $z$ here.

Escaped dollars: \$5 and \$10.

Multi-line span left alone: $a +
b$.
26 changes: 26 additions & 0 deletions test/render/test-render-md.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Title: Render test (Markdown)

Trailing period: $x$.

Comma then space: $a$, then.

Hyphen after span: $n$-bit.

Threshold: $t$-of-$n$.

Close paren: (see $i$).

Em-dash directly after: $x$—note.

Leading minus preserved: $-x$ stays.

Leading minus then period: $-y$.

Punctuation mid-token unchanged: $x$.5 here.

Plain span: $z$ here.

Escaped dollars: \$5 and \$10.

Multi-line span left alone: $a +
b$.
26 changes: 26 additions & 0 deletions test/render/test-render-rst.intermediate
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
.. Title: Render test (rst)

Trailing period: :math:`x\kern-0.03em\textsf{.}`

Comma then space: :math:`a\kern-0.03em\textsf{,}` then.

Hyphen after span: :math:`n\kern-0.15em` -bit.

Threshold: :math:`t\kern-0.15em` -of-:math:`n\kern-0.03em\textsf{.}`

Close paren: (see :math:`i\kern-0.15em` ).

Em-dash directly after: :math:`x\kern-0.15em` —note.

Leading minus preserved: :math:`-x` stays.

Leading minus then period: :math:`-y\kern-0.03em\textsf{.}`

Punctuation mid-token unchanged: :math:`x`.5 here.

Plain span: :math:`z` here.

Escaped dollars: $5 and $10.

Multi-line span left alone: $a +
b$.
26 changes: 26 additions & 0 deletions test/render/test-render-rst.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
.. Title: Render test (rst)

Trailing period: $x$.

Comma then space: $a$, then.

Hyphen after span: $n$-bit.

Threshold: $t$-of-$n$.

Close paren: (see $i$).

Em-dash directly after: $x$—note.

Leading minus preserved: $-x$ stays.

Leading minus then period: $-y$.

Punctuation mid-token unchanged: $x$.5 here.

Plain span: $z$ here.

Escaped dollars: \$5 and \$10.

Multi-line span left alone: $a +
b$.
Loading
Loading