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 +++++++++----- lib/template.source.sh | 6 ++++-- 2 files changed, 13 insertions(+), 7 deletions(-) (limited to 'lib') 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
" diff --git a/lib/template.source.sh b/lib/template.source.sh index 29d0bf4..519f2cf 100644 --- a/lib/template.source.sh +++ b/lib/template.source.sh @@ -93,12 +93,14 @@ template::inline::index () { # To generate a table of contents template::inline::toc () { echo '```' - echo 'Table of contents:' + echo 'Table of contents' + echo '=================' + echo '' < "$(basename "$CURRENT_TPL")" $SED -E -n ' /^```/,/^```/! { /^#+ / { s/#/ /g - s/^ // + s/^ // p } } -- cgit v1.2.3