aboutsummaryrefslogtreecommitdiff
path: root/v2/src/bin
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xv2/src/bin/html71
1 files changed, 34 insertions, 37 deletions
diff --git a/v2/src/bin/html b/v2/src/bin/html
index 38270b1..f995753 100755
--- a/v2/src/bin/html
+++ b/v2/src/bin/html
@@ -98,49 +98,46 @@ markdown_to_html() {
'
}
-extract_plaintext_snippets() {
+extract_plaintext_snippets() (
SNIPPETS="${FILENAME%.md}.snippets"
printf '' > "$SNIPPETS"
F="$(mkstemp)"
cat > "$F"
- (
- IFS=''
- BLOCK_NUMBER=0
- IN_BLOCK=
- while read -r line; do
- if [ "$line" = '</code></pre>' ]; then
- IN_BLOCK=
- fi
-
- if [ -n "$IN_BLOCK" ]; then
- printf '%s\n' "$line" | htmlesc -d >> "$OUT"
- fi
-
- 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|^\($INDENT<pre><code.*>\)\(.*\)$|\2|" |
- htmlesc -d > "$OUT"
- printf '%s\n' "$OUT" >> "$SNIPPETS"
- fi
- done < "$F"
-
- BLOCK_NUMBER=0
- while read -r line; do
- printf '%s\n' "$line"
+ IFS=''
+ BLOCK_NUMBER=0
+ IN_BLOCK=
+ while read -r line; do
+ if [ "$line" = '</code></pre>' ]; then
+ IN_BLOCK=
+ fi
- if [ "$line" = '</code></pre>' ]; then
- 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"
- )
+ if [ -n "$IN_BLOCK" ]; then
+ printf '%s\n' "$line" | htmlesc -d >> "$OUT"
+ fi
-}
+ 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|^\($INDENT<pre><code.*>\)\(.*\)$|\2|" |
+ htmlesc -d > "$OUT"
+ printf '%s\n' "$OUT" >> "$SNIPPETS"
+ fi
+ done < "$F"
+
+ BLOCK_NUMBER=0
+ while read -r line; do
+ printf '%s\n' "$line"
+
+ if [ "$line" = '</code></pre>' ]; then
+ 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"
+)
add_line_numbers() {
awk '