From d592d7ab5fcef86428a0bbf2c9629cbd846b2d59 Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Thu, 6 Apr 2023 11:36:54 -0300 Subject: v2: src/bin/html: Turn extract_plaintext_snippets() into a () function --- v2/src/bin/html | 71 +++++++++++++++++++++++++++------------------------------ 1 file changed, 34 insertions(+), 37 deletions(-) (limited to 'v2/src') 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" = '' ]; then - IN_BLOCK= - fi - - if [ -n "$IN_BLOCK" ]; then - printf '%s\n' "$line" | htmlesc -d >> "$OUT" - fi - - if printf '%s' "$line" | grep -q "^$INDENT
\)\(.*\)$|\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" = '
' ]; then + IN_BLOCK= + fi - if [ "$line" = '' ]; then - printf '%s\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
\)\(.*\)$|\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" = '
' ]; then + printf '%s\n' \ + "$INDENT" \ + "$(basename "${url_part:?}").$BLOCK_NUMBER.txt" + BLOCK_NUMBER=$((BLOCK_NUMBER + 1)) + fi + done < "$F" +) add_line_numbers() { awk ' -- cgit v1.2.3