diff options
Diffstat (limited to 'v2/src/development/genhtml.sh')
-rwxr-xr-x | v2/src/development/genhtml.sh | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/v2/src/development/genhtml.sh b/v2/src/development/genhtml.sh index 8950b1d..f3a6e3a 100755 --- a/v2/src/development/genhtml.sh +++ b/v2/src/development/genhtml.sh @@ -92,11 +92,33 @@ slugify_once() { fi } +INDENT=' ' markdown_to_html() { - md2html + md2html | awk -vINDENT="$INDENT" ' + BEGIN { + in_block = 0 + } + + { + if (in_block == 0) { + printf "%s", INDENT + } + print + } + + /^<\/code><\/pre>$/ { + in_block = 0 + } + + /^<pre><code/ { + in_block = 1 + } + ' } extract_plaintext_snippets() { + SNIPPETS="${FILENAME%.md}.snippets" + rm -f "$SNIPPETS" F="$(mkstemp)" cat > "$F" ( @@ -112,13 +134,14 @@ extract_plaintext_snippets() { printf '%s\n' "$line" | htmlesc -d >> "$OUT" fi - if printf '%s' "$line" | grep -q '^<pre><code.*>'; then + if printf '%s' "$line" | grep -q "^$INDENT<pre><code"; then IN_BLOCK=1 OUT="${FILENAME%.md}.html.$BLOCK_NUMBER.txt" BLOCK_NUMBER=$((BLOCK_NUMBER + 1)) printf '%s\n' "$line" | - sed 's|^\(<pre><code.*>\)\(.*\)$|\2|' | + sed "s|^\($INDENT<pre><code.*>\)\(.*\)$|\2|" | htmlesc -d > "$OUT" + printf '%s\n' "$OUT" >> "$SNIPPETS" fi done < "$F" @@ -127,7 +150,9 @@ extract_plaintext_snippets() { printf '%s\n' "$line" if [ "$line" = '</code></pre>' ]; then - printf '<p class="plaintext-link"><a href="%s.%s.txt">plaintext</a></p>\n' "$(url-for "$URL")" "$BLOCK_NUMBER" + printf '%s<p class="plaintext-link"><a href="%s">plaintext</a></p>\n' \ + "$INDENT" \ + "$(basename "${url_part:?}").$BLOCK_NUMBER.txt" BLOCK_NUMBER=$((BLOCK_NUMBER + 1)) fi done < "$F" @@ -143,7 +168,7 @@ add_line_numbers() { next } - match($0, /^(<pre><code.*>)(.*)$/, a) { + match($0, /^( +<pre><code.*>)(.*)$/, a) { printf "%s<table rules=columns class=\"code-block\"><tbody>", a[1] n = 1 @@ -194,4 +219,5 @@ emit_body() { } envsubst < src/lib/preamble.html +emit_body envsubst < src/lib/postamble.html |