From ab0ff28184b83587297ac1c9f11e110d6b76a80f Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sun, 21 Jul 2024 13:12:42 +0300 Subject: (single) Implemented ordered lists --- single.awk | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'single.awk') diff --git a/single.awk b/single.awk index 0262a1a..eadb7d1 100644 --- a/single.awk +++ b/single.awk @@ -6,7 +6,7 @@ # [x] Line break # [.] Headers (atx and setex) # [x] Blockquotes -# [ ] Lists +# [x] Lists # [ ] Code blocks # [x] Horizontal rules # [ ] Span elements @@ -98,20 +98,26 @@ BEGIN { } # Unordered lists +function abs(x) { return ((x < 0) ? -x : x) } !blankline && lengthStack("list-level") > 0 { match($0, /^ */) + indent = RLENGTH # Compensating factor for list items - li_offset = 2 * (substr($0, RSTART + RLENGTH, 2) ~ /(\*|\+|-) /) - while (RLENGTH + li_offset < topStack("list-level")) { - print "" + match($0, /(\*|\+|-|[[:digit:]]+\.) /) + if (RLENGTH == -1) RLENGTH = 0 + while (indent + RLENGTH < abs(topStack("list-level"))) { + if (topStack("list-level") < 0) print "" + else print "" popStack("list-level") } } -/^[[:blank:]]*(\*|\+|-) / { - match($0, /(\*|\+|-) /) - if (topStack("list-level") < RSTART) { - print "" popStack("list-level") } } -- cgit v1.3.1-26-gb76a