From f100f12f0f6154ca8859114c3f88d7e32f94458e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Tue, 15 Sep 2026 17:58:47 +0200 Subject: [PATCH] Squashed 'cgilite/' changes from 221c2b7d..ca8a3d61 ca8a3d61 general improved performance for POST/GET, performance switch for large HTML escapes b233ce08 improved attribute parsing in headlines git-subtree-dir: cgilite git-subtree-split: ca8a3d6191c280af0e9841b079521ed085a2af4e --- cgilite.sh | 49 ++++++++++++++++++++++++++++++++++--------------- markdown.awk | 8 +++++--- 2 files changed, 39 insertions(+), 18 deletions(-) diff --git a/cgilite.sh b/cgilite.sh index ac23f40..f261f9c 100755 --- a/cgilite.sh +++ b/cgilite.sh @@ -224,10 +224,10 @@ cgilite_count(){ } cgilite_value(){ - local str="&$1" name="$2" cnt="${3:-1}" + local ref="&$1" str="&$1" name="$2" cnt="${3:-1}" while [ $cnt -gt 0 ]; do - [ "${str}" = "${str#*&${name}=}" ] && return 1 str="${str#*&${name}=}" + [ "${str}" = "${ref}" ] && return 1 || ref="${str}" cnt=$((cnt - 1)) done HEX_DECODE % "$(printf %s "${str%%&*}" |tr + \ )" @@ -294,19 +294,38 @@ HTML(){ # Also escape [, ], and \n for use in html-sh local str out [ $# -eq 0 ] && str="$(cat)" || str="$*" - while [ "$str" ]; do case $str in - \&*) out="${out}&"; str="${str#?}";; - \<*) out="${out}<"; str="${str#?}";; - \>*) out="${out}>"; str="${str#?}";; - \"*) out="${out}""; str="${str#?}";; - \'*) out="${out}'"; str="${str#?}";; - \[*) out="${out}["; str="${str#?}";; - \]*) out="${out}]"; str="${str#?}";; - "${CR}"*) out="${out} "; str="${str#?}";; - "${BR}"*) out="${out} "; str="${str#?}";; - *) out="${out}${str%%[]&<>\"\'${CR}${BR}[]*}"; str="${str#"${str%%[]&<>\"\'${CR}${BR}[]*}"}";; - esac; done - printf %s "$out" + if [ "${#str}" -ge 1000 ]; then + HTML_large "$str" + else + while [ "$str" ]; do case $str in + \&*) out="${out}&"; str="${str#?}";; + \<*) out="${out}<"; str="${str#?}";; + \>*) out="${out}>"; str="${str#?}";; + \"*) out="${out}""; str="${str#?}";; + \'*) out="${out}'"; str="${str#?}";; + \[*) out="${out}["; str="${str#?}";; + \]*) out="${out}]"; str="${str#?}";; + "${CR}"*) out="${out} "; str="${str#?}";; + "${BR}"*) out="${out} "; str="${str#?}";; + *) out="${out}${str%%[]&<>\"\'${CR}${BR}[]*}"; str="${str#"${str%%[]&<>\"\'${CR}${BR}[]*}"}";; + esac; done + printf %s "$out" + fi +} + +HTML_large(){ + # Better performance for large strings + printf %s "$*" | sed -zE ' + s;&;\&\;;g; + s;<;\<\;;g; + s;>;\>\;;g; + s;";\"\;;g; + s;\[;\[\;;g; + s;\];\]\;;g; + s;\r;\ \;;g; + s;\n;\ \;;g; + s;'\'';\'\;;g; + ' } URL(){ diff --git a/markdown.awk b/markdown.awk index d1f6616..b60285e 100755 --- a/markdown.awk +++ b/markdown.awk @@ -650,7 +650,8 @@ function _block( block, LOCAL, st, len, text, title, attrib, href, guard, code, # First Order Heading H1 + Attrib } else if ( match( block, "^([^\n]+)([ \t]*"rattr")\n===+(\n|$)" ) ) { len = RLENGTH; text = attrib = block; - sub(/([ \t]*\{([^\}\n]+)\})\n===+(\n.*)?$/, "", text); + sub("([ \t]*"rattr")\n===+(\n.*)?$", "", text); + sub(/\n===+(\n.*)?$/, "", attrib); attrib = _attr(attrib); ret = ret headline(1, text, attrib) ; block = substr( block, len + 1 ); @@ -667,7 +668,8 @@ function _block( block, LOCAL, st, len, text, title, attrib, href, guard, code, # Second Order Heading H2 + Attrib } else if ( match( block, "^([^\n]+)([ \t]*"rattr")\n---+(\n|$)" ) ) { len = RLENGTH; text = attrib = block; - sub(/([ \t]*\{([^\}\n]+)\})\n---+(\n.*)?$/, "", text); + sub("([ \t]*"rattr")\n---+(\n.*)?$", "", text); + sub(/\n---+(\n.*)?$/, "", attrib); attrib = _attr(attrib); ret = ret headline(2, text, attrib) ; block = substr( block, len + 1); @@ -686,7 +688,7 @@ function _block( block, LOCAL, st, len, text, title, attrib, href, guard, code, len = RLENGTH; text = attrib = substr(block, 1, len); match(block, /^##?#?#?#?#?[^#]/); n = RLENGTH - 1; text = substr(text, n + 1); sub(/^[ \t]*/, "", text); - sub(/[ \t]*#*([ \t]*\{([a-zA-Z \t-]*)\})(\n.*)?$/, "", text); + sub("[ \t]*#*([ \t]*"rattr")(\n.*)?$", "", text); attrib = _attr(attrib); -- 2.47.3