From 5bdc2703db9c046109fdbc950864c6d95deb619a Mon Sep 17 00:00:00 2001
From: =?utf8?q?Paul=20H=C3=A4nsch?=
Date: Mon, 7 Jul 2025 05:50:44 +0200
Subject: [PATCH] Squashed 'cgilite/' changes from 290cc672..71de6234
71de6234 use attributes in wrapper class for fenced code blocks
0c39114d bugfix: prevent content duplication when deleting nonexist key
b8dae070 updated copyright info
ac4031bc allow `check` function for field indexes
git-subtree-dir: cgilite
git-subtree-split: 71de6234b23a22b2ceee6252fe6d2fa843afeaa8
---
db23.sh | 14 +++++++++++---
markdown.awk | 5 +++--
tests-markdown.sh | 4 ++--
3 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/db23.sh b/db23.sh
index e8a0d64..b7ab548 100755
--- a/db23.sh
+++ b/db23.sh
@@ -31,8 +31,12 @@ DB2() {
open|load) file="$1"
cat "$file" || return 1
;;
- check|contains) key="$(STRING "$1")" val=''
+ check|contains) key="$(STRING "$1")" seq="${2:-1}"
val="${data##*"${BR}${key}" }" val="${val%%"${BR}"*}"
+ [ "$val" = '' ] && return 1 || val="${val} "
+ while [ $seq -gt 1 ]; do
+ seq=$((seq - 1)) val="${val#* }"
+ done
[ "$val" = '' ] && return 1
;;
count) key="$(STRING "$1")" val='' seq=0
@@ -61,8 +65,12 @@ DB2() {
delete|remove) key="$(STRING "$1")"
val="${data#*"${BR}${key}" *"${BR}"}"
key="${data%"${BR}${key}" *"${BR}"*}"
- [ "${key}${BR}${val}" = "${data}" ] && return 1
- printf '%s' "${key#"${BR}"}${BR}${val%"${BR}"}"
+ if [ "${val}" = "${data}" ]; then
+ printf %s\\n "${data}"
+ return 1
+ else
+ printf '%s' "${key#"${BR}"}${BR}${val%"${BR}"}"
+ fi
;;
set|store) key="$(STRING "$1")" val=""
shift 1
diff --git a/markdown.awk b/markdown.awk
index bef97d1..60599af 100755
--- a/markdown.awk
+++ b/markdown.awk
@@ -5,7 +5,7 @@
# Meant to support all features of John Grubers basic Markdown
# + a number of common extensions, mostly inspired by Pandoc Markdown
-# Copyright 2021 - 2023 Paul Hänsch
+# Copyright 2021 - 2024 Paul Hänsch
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
@@ -657,7 +657,8 @@ function _block( block, LOCAL, st, len, text, title, attrib, href, guard, code,
gsub(/(^ | $)/, "", attrib);
if ( match(code, "(^|\n)" guard "+(\n|$)" ) && attrib ) {
len = RLENGTH; st = RSTART;
- ret = ret "" HTML( substr(code, 1, st - 1) ) "
\n";
+ ret = ret "" \
+ HTML( substr(code, 1, st - 1) ) "
\n";
block = substr( code, st + len );
continue;
diff --git a/tests-markdown.sh b/tests-markdown.sh
index 6df4224..30442cc 100755
--- a/tests-markdown.sh
+++ b/tests-markdown.sh
@@ -185,7 +185,7 @@ not be
*formatted*
but
```' \
-'fenced code will
+'fenced code will
not be
*formatted*
but ­ <escaped>
' \
@@ -762,7 +762,7 @@ list item.
-Fenced Code Block
+Fenced Code Block
# with verbatim Text
`and an attribute`
The limerick packs laughs anatomical
--
2.39.5