From f5e2d2edc4ab9f2842ef5cdca0ce1a130ce6f0a7 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Mon, 30 Dec 2024 10:21:09 +0200 Subject: fix toc when there are tags in them --- lib/template.source.sh | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/template.source.sh b/lib/template.source.sh index 83dfb21..7bd3f93 100644 --- a/lib/template.source.sh +++ b/lib/template.source.sh @@ -103,6 +103,7 @@ template::inline::index () { done | sort | uniq } +# TODO: Write unit test. # To generate a table of contents template::inline::toc () { echo '## Table of Contents' @@ -110,8 +111,9 @@ template::inline::toc () { < "$(basename "$CURRENT_TPL")" $SED -E -n ' /^```/,/^```/! { /^#+ / { - s/#/* ⇢/ - s/#/ ⇢/g + s/^###/* ⇢ ⇢ ⇢/ + s/^##/* ⇢ ⇢/ + s/^#/* ⇢/ p } } @@ -171,4 +173,28 @@ Just so that you know' assert::equals "$(template::_generate <<< "$template5")" "$expect5" assert::equals "$(template::_generate <<< ']')" '>' + +# local -r template6='# Hello world + +# << template::inline::toc + +# ## Heading 1 + +# ### Heading 1b + +# foo bar baz + +# ## Heading 2 + +# ### Heading 2b + +# foo bar baz' + +# local -r expect6='<< echo foo +# <<< +# echo bar +# >>>' +# assert::equals "$(template::_generate <<< "$template6")" "$expect6" + +# assert::equals "$(template::_generate <<< ']')" '>' } -- cgit v1.2.3