aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2023-04-06 11:36:54 -0300
committerEuAndreh <eu@euandre.org>2023-04-06 11:36:54 -0300
commitd592d7ab5fcef86428a0bbf2c9629cbd846b2d59 (patch)
tree52b9ac10137bc92c3dbe46eee5241af25d13de10
parentv2: Add support for src/redirect.mappings via symlinks (diff)
downloadeuandre.org-d592d7ab5fcef86428a0bbf2c9629cbd846b2d59.tar.gz
euandre.org-d592d7ab5fcef86428a0bbf2c9629cbd846b2d59.tar.xz
v2: src/bin/html: Turn extract_plaintext_snippets() into a () function
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 '