From 867b5015fda689bc5414557557a00cd8ad62699d Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sun, 25 Feb 2024 12:51:29 +0200 Subject: (awk-edits) Properly implemented MEL paragraph tag --- awk-edits/MEL-parser.awk | 53 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 18 deletions(-) (limited to 'awk-edits/MEL-parser.awk') diff --git a/awk-edits/MEL-parser.awk b/awk-edits/MEL-parser.awk index ebd68bd..d1eb4d5 100644 --- a/awk-edits/MEL-parser.awk +++ b/awk-edits/MEL-parser.awk @@ -1,4 +1,4 @@ -# .*(slides|teaching)/.*html +# .*html # # == About == # @@ -29,9 +29,11 @@ BEGIN { newStack("mel") - MELSINGLE = "s" - MELOPEN = "o" - MELCLOSE = "c" + MELOPEN = "o" + MELCLOSE = "c" + MELINSERT = "s" + MELPARAGRAPH = "p" + MELLINE = "l" } // { @@ -42,37 +44,52 @@ BEGIN { melInsideCode = 0 } -melInsideCode == 0 && /^[ \t]*(

)?&/ { +melInsideCode == 0 && /^[ \t]*(

|

)?&[{[()\]}:.]/ { newLine = "" lineCopy = $0 - while (match(lineCopy, /&(((::|[[{(:.])[^[:space:].:[{(<>)}\]&]+)|[\]})])/)) { - RSTART = RSTART + 5 - RLENGTH = RLENGTH - 5 + paragraphed = 0 + while (match(lineCopy, /&(((::|[[{(:.])[^[:space:].:;[{(<>)}\]&]+)|[\]})])/)) { + RSTART += 5 + RLENGTH -= 5 # Inside closing tag if (RLENGTH == 1) { replaceWith = MEL[topStack("mel"), MELCLOSE] popStack("mel") } - # Inside opening tag - else if (substr(lineCopy, RSTART, 1) ~ /[[{(]/) { + # Inside insert + else if (substr(lineCopy, RSTART, 1) == ".") { name = substr(lineCopy, RSTART + 1, RLENGTH - 1) - replaceWith = MEL[name, MELOPEN] - pushStack("mel", name) + replaceWith = MEL[name, MELINSERT] + } + # Inside one line TODO + else if (substr(lineCopy, RSTART, 2) == "::") { + name = substr(lineCopy, RSTART + 2, RLENGTH - 2) + + # RLENGTH = length(lineCopy) + replaceWith = MEL[name, MELLINE] + } + # Inside paragraph + else if (substr(lineCopy, RSTART, 1) == ":") { + name = substr(lineCopy, RSTART + 1, RLENGTH - 1) + + replaceWith = " " MEL[name, MELPARAGRAPH] + RSTART -= 1 + RLENGTH += 1 + paragraphed = 1 } - # Inside paragraph/one line/insert - # TODO: currently all work as insert + # Inside opening tag else { - nameStart = 1 + (substr(lineCopy, RSTART + 1, 1) == ":") - name = substr(lineCopy, RSTART + nameStart, RLENGTH - nameStart) + name = substr(lineCopy, RSTART + 1, RLENGTH - 1) - replaceWith = MEL[name, MELSINGLE] + replaceWith = MEL[name, MELOPEN] + pushStack("mel", name) } newLine = newLine substr(lineCopy, 0, RSTART - 6) replaceWith lineCopy = substr(lineCopy, RSTART + RLENGTH) } $0 = newLine lineCopy - if (length(newLine) > 0) + if (paragraphed == 0 && length(newLine) > 0) gsub(/(

|<\/p>)/, "") } -- cgit v1.3.1-26-gb76a