From e0f9a7722da62dec49353abff27cce9caf409113 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Tue, 30 Apr 2024 13:06:57 +0300 Subject: add id's to the headers in html, for ToC references later --- lib/html.source.sh | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'lib/html.source.sh') diff --git a/lib/html.source.sh b/lib/html.source.sh index 8f4da2f..683ea99 100644 --- a/lib/html.source.sh +++ b/lib/html.source.sh @@ -27,12 +27,13 @@ html::make_paragraph () { html::make_heading () { local -r text=$($SED -E 's/^#+ //' <<< "$1"); shift local -r level="$1"; shift + local -r id=$(tr -cd 'A-Za-z0-9' <<< "$text") if [ "$HTML_VARIANT_TO_USE" = exact ]; then #echo "$(html::encode "$text")
" - echo "$(html::encode "$text")
" + echo "$(html::encode "$text")
" else - echo "$(html::encode "$text")
" + echo "$(html::encode "$text")
" fi } @@ -300,13 +301,16 @@ html::test::exact () { assert::equals "$(html::make_paragraph "$line")" "echo foo 2>&1
" line='# Header 1' - assert::equals "$(html::make_heading "$line" 1)" "

Header 1


" + local id=$(tr -cd 'A-Za-z0-9' <<< "$line") + assert::equals "$(html::make_heading "$line" 1)" "

Header 1


" line='## Header 2' - assert::equals "$(html::make_heading "$line" 2)" "

Header 2


" + id=$(tr -cd 'A-Za-z0-9' <<< "$line") + assert::equals "$(html::make_heading "$line" 2)" "

Header 2


" line='### Header 3' - assert::equals "$(html::make_heading "$line" 3)" "

Header 3


" + id=$(tr -cd 'A-Za-z0-9' <<< "$line") + assert::equals "$(html::make_heading "$line" 3)" "

Header 3


" line='> This is a quote' assert::equals "$(html::make_quote "$line")" "This is a quote
" -- cgit v1.2.3