From cb9c7547ddc6d7e8e4bfd783d10fea38bc418277 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stig-=C3=98rjan=20Smelror?= Date: Sat, 3 Feb 2024 08:30:39 +0100 Subject: [PATCH] New function: _zhtml. Cleaned up a bit and moved bits around. --- qsgen2 | 98 ++++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 75 insertions(+), 23 deletions(-) diff --git a/qsgen2 b/qsgen2 index 17d636b..e20d308 100755 --- a/qsgen2 +++ b/qsgen2 @@ -112,7 +112,7 @@ fi # We define the variable 'engine' based on what's in the 'config' file. if [[ ${generator} == "native" ]]; then # Usage: ${engine} ${1} - Where 1 is the file you want to convert - engine=_html + engine=_zhtml export file_ext=tpl elif [[ ${generator} == "markdown" ]]; then if [[ ! -f /usr/local/bin/pandoc ]]; then @@ -122,18 +122,6 @@ elif [[ ${generator} == "markdown" ]]; then else # Usage: ${engine} ${1} - Where 1 is the file you want parsed engine=/usr/local/bin/pandoc -# function engine() { -# -# local command="/usr/bin/Markdown.pl" -# local c-opts= -# -# $(command) "$1" -# -# # Assign the output to the global variable named by $1 -# # eval "$1=\${result}" -# -# # echo "${(P)1}" -# } export file_ext=md fi fi @@ -293,13 +281,14 @@ function _pages_cache() { function _last_updated() { # This function updates #updated and #version tags in the provided string for buffers - local content="${1}" local debug=true - - local upd_msg="Last updated ${today} by ${QSGEN} ${VERSION}" if (${debug}) _msg debug "_last_updated: Setting date and version in footer" if (${debug}) _msg debug "_last_updated: ${upd_msg}" + + local upd_msg="Last updated ${today} by ${QSGEN} ${VERSION}" + + local content="${1}" # Perform the replacements local updated_content=$(echo "${content}" | sed \ @@ -311,15 +300,16 @@ function _last_updated() { function _f_last_updated() { # This function updates #updated and #version tags in the provided string in files - - local content="${1}" + local debug=true - local upd_msg="Last updated ${today} by ${QSGEN} ${VERSION}" - if (${debug}) _msg debug "_f_last_updated: Setting date and version in footer of file ${1}" if (${debug}) _msg debug "_f_last_updated: ${upd_msg}" - + + local upd_msg="Last updated ${today} by ${QSGEN} ${VERSION}" + + local content="${1}" + # Perform the replacements tee < ${content} | sed \ -e "s|#updated|${upd_msg}|" \ @@ -826,7 +816,7 @@ function _cleanup() { echo "${cleaned_content}" } -_html() { +function _html() { local content="$1" local debug=false @@ -880,7 +870,69 @@ _html() { ' <<< "$content" } -# Time to test the first function +function _zhtml() { + # This function uses the regex module from Zsh to parse the QStags + + local content="$1" + local debug=false + + if ${debug}; then + echo "_html: Converting QStags in content" + fi + + # Load regex module + zmodload zsh/regex + + # Define tag replacements as an associative array + typeset -A tags=( + "#BR" "
\n" + "#BD" "" "#EBD" "" + "#I" "" "#EI" "\n" + "#P" "

" "#EP" "

\n" + "#Q" "
" "#EQ" "
\n" + "#C" "" "#EC" "\n" + "#H1" "

" "#EH1" "

\n" + "#H2" "

" "#EH2" "

\n" + "#H3" "

" "#EH3" "

\n" + "#H4" "

" "#EH4" "

\n" + "#H5" "
" "#EH5" "
\n" + "#H6" "
" "#EH6" "
\n" + "#STRONG" "" "#ESTRONG" "\n" + "#EM" "" "#EEM" "\n" + "#DV" "
" "#EDV" "
\n" + "#SPN" "" "#ESPN" "\n" + "#UL" "\n" + "#OL" "
    " "#EOL" "
\n" + "#LI" "
  • " "#ELI" "
  • \n" + "#U" "" "#EU" "\n" + "#TBL" "" "#ETBL" "
    \n" + "#TR" "" "#ETR" "\n" + "#TD" "" "#ETD" "\n" + "#TH" "" "#ETH" "\n" + "#ART" "
    " "#EART" "
    \n" + "#SEC" "
    " "#ESEC" "
    \n" + "#ASIDE" "\n" + "#NAV" "\n" + "#BTN" "\n" + "#SEL" "\n" + "#OPT" "\n" + "#LT" "<" "#GT" ">" "#NUM" "#" + ) + + for tag html (${(kv)tags}); do + # Escape tag for regex use + local escapedTag=$(printf '%s' "$tag" | sed 's/[].\[^$*]/\\&/g') + if [[ "$content" =~ "$escapedTag" ]]; then + content=${content//($tag)/$html} + fi + done + + echo "$content" +} + + + +# Time to run the first function _blogs _pages _add_blog_list_to_index