Summary Files Commits Branches @commit @diff @stats
path: root / single.awk
diff options
context:
space:
mode:
Commit71fd4ce667980be72f7c8f9265ccb345ceb37f6a (patch)
Author
 Syndamia <kamen@syndamia.com>
2025-01-01 14:38:19 +0200
Committer
 Syndamia <kamen@syndamia.com>
2025-01-01 14:38:19 +0200
Filesb5934892c0c75b1352b64a1771c467e79eab500c /single.awk
csg-71fd4ce667980be72f7c8f9265ccb345ceb37f6a.tar
csg-71fd4ce667980be72f7c8f9265ccb345ceb37f6a.tar.gz
csg-71fd4ce667980be72f7c8f9265ccb345ceb37f6a.zip
Parent7dc4331d9309a1427051b2aa48fee4556f8a1c3a (diff)
fix(single): Properly remove identation of list item contents
1 files changed, 11 insertions, 6 deletions
-rw-r--r--single.awk17
diff --git a/single.awk b/single.awk
index b4b4c89..2a92373 100644
--- a/single.awk
+++ b/single.awk
@@ -161,7 +161,7 @@ function end_list() {
PNappnd("</li></" (lists[list_level] == "." ? "o" : "u") "l>")
--list_level
}
-function start_list(level, type) {
+function start_list(level, type, shift) {
## Every two columns we define a new level
level = int((level + 2) / 2)
## If list definition is the first line inside a code block
@@ -182,6 +182,7 @@ function start_list(level, type) {
if (list_level < level || lists[list_level] != type) {
P1 = P1 ORS "<" (type == "." ? "o" : "u") "l><li>"
lists[level] = type
+ lists_shift[level] = shift
list_level = level
}
else {
@@ -195,23 +196,27 @@ function start_list(level, type) {
match($0, /^[ \t]*[*+-] /)
level = RLENGTH - 2
type = char($0, RSTART + RLENGTH - 2)
- sub(/^[^*+-]*[*+-] /, "")
+ match($0, /^[^*+-]*[*+-] /)
+ shift = RLENGTH
+ sub_match("")
- start_list(level, type)
+ start_list(level, type, shift)
}
!inside_codeblock && /^[ \t]*[0-9]+\. / { ## Ordered list
match($0, /^[ \t]*/)
level = RLENGTH
type = "."
- sub(/^[^.]+\. /, "")
+ match($0, /^[^.]+\. /)
+ shift = RLENGTH
+ sub_match("")
- start_list(level, type)
+ start_list(level, type, shift)
}
list_level > 0 && !list_started && /[^ \t]/ { ## Non-list line
match($0, /^[ \t]*/)
level = int((RLENGTH + 2) / 2)
- $0 = substr($0, 2 * level - 1)
not_paragraph = 1
+ sub("^[ \t]{1," lists_shift[list_level] "}", "")
while (list_level >= level && emptyP1) {
end_list()