Summary Files Commits Branches @commit @diff @stats
path: root / awk-edits
diff options
context:
space:
mode:
Commit42815619367b9294d1b1c69f556a93f7c8693f1f (patch)
Author
 Kamen Mladenov <kamen@syndamia.com>
2024-02-26 08:33:26 +0000
Committer
 Kamen Mladenov <kamen@syndamia.com>
2024-02-26 08:33:26 +0000
Files7a55ac562669ca7c30cea980fd7135d1d82b65dd /awk-edits
syndamia.com-42815619367b9294d1b1c69f556a93f7c8693f1f.tar
syndamia.com-42815619367b9294d1b1c69f556a93f7c8693f1f.tar.gz
syndamia.com-42815619367b9294d1b1c69f556a93f7c8693f1f.zip
Parent795d04783d25c0ada4ca3a5a4b56dbc18ff34bd6 (diff)
Parent88bb1fbdfe8dbcb6a4f6490683627a229f873dfd (diff)
Merge branch 'MEL' into 'master'
MEL syntax overhaul See merge request Syndamia/syndamiadotcom!14
4 files changed, 296 insertions, 0 deletions
-rw-r--r--awk-edits/#stack.awk26
-rw-r--r--awk-edits/MEL-Iconified.awk42
-rw-r--r--awk-edits/MEL-Presentation.awk94
-rw-r--r--awk-edits/MEL-parser.awk134
diff --git a/awk-edits/#stack.awk b/awk-edits/#stack.awk
new file mode 100644
index 0000000..a8b0b2a
--- /dev/null
+++ b/awk-edits/#stack.awk
@@ -0,0 +1,26 @@
+function newStack(name) {
+ __stacks[name, "length"] = 0
+}
+
+function topStack(name) {
+ return __stacks[name, __stacks[name, "length"] - 1]
+}
+
+function lengthStack(name) {
+ return __stacks[name, "length"]
+}
+
+function pushStack(name, value) {
+ __stacks[name, __stacks[name, "length"]++] = value
+}
+
+function popStack(name, value) {
+ delete __stacks[name, --__stacks[name, "length"]]
+}
+
+function deleteStack(name) {
+ for (i = 0; i < __stacks[name, "length"]; i++) {
+ delete __stacks[name, i]
+ }
+ delete __stacks[name, "length"]
+}
diff --git a/awk-edits/MEL-Iconified.awk b/awk-edits/MEL-Iconified.awk
new file mode 100644
index 0000000..332be46
--- /dev/null
+++ b/awk-edits/MEL-Iconified.awk
@@ -0,0 +1,42 @@
+# .*html
+
+BEGIN {
+ usesMEL()
+ #
+ # Flags
+ #
+
+ melFlagTag("gb", "ENG")
+ melFlagTag("bg", "BGN")
+
+ #
+ # Noteworthy paragraphs
+ #
+
+ melParTag("question", "dialog-question.png")
+ melParTag("warn", "dialog-warning.png")
+ melParTag("important", "dialog-important.png")
+
+ #
+ # File type
+ #
+
+ melFiletypeTag("ft-photo", "&#xeb0a;")
+ melFiletypeTag("ft-text", "&#xeaa2;")
+ melFiletypeTag("ft-zip", "&#xed4e;")
+ melFiletypeTag("ft-movie", "&#xeafa;")
+ melFiletypeTag("ft-markdown", "&#xec41;")
+ melFiletypeTag("ft-browser", "&#xebb7;")
+}
+
+function melFlagTag(name, alt) {
+ MEL[name, MELINSERT] = "<img src=\"/img/" name ".svg\" class=\"flag unzoomable svg\" alt=\"" name "\" height=18>"
+}
+
+function melParTag(name, image) {
+ MEL[name, MELPARAGRAPH] = "class=\"special-par " name "-par\"><img src=\"/img/" image "\" class=\"special-par-icon borderless unzoomable\" alt=\"" name "\">"
+}
+
+function melFiletypeTag(name, repl) {
+ MEL[name, MELINSERT] = "<span class=\"file-type-icon\">" repl "</span>"
+}
diff --git a/awk-edits/MEL-Presentation.awk b/awk-edits/MEL-Presentation.awk
new file mode 100644
index 0000000..cabc928
--- /dev/null
+++ b/awk-edits/MEL-Presentation.awk
@@ -0,0 +1,94 @@
+# .*(slides|teaching)/.*html
+
+BEGIN {
+ usesMEL()
+ #
+ # Elements, dependent (and semidependent) on available font size
+ #
+
+ fontSizes[1] = "18"
+ fontSizes[2] = "20"
+ fontSizes[3] = "22"
+ fontSizes[4] = "25"
+ fontSizes[5] = "27"
+ fontSizes[6] = "35"
+
+ # Certain tags can exist without explicitly defining the font size
+ # while others cannot
+ # fontSizes[0] is used for simpler code for the tags which don't
+ # require font size
+ fontSizes[0] = ""
+
+ # Tags which can exist without specified font-size
+ for (ind in fontSizes) {
+ fontClass = (ind != 0) ? " font" fontSizes[ind] : ""
+
+ MEL["slide" fontSizes[ind], MELOPEN] = "<div id=\"[SLIDEID]\" class=\"slide" fontClass "\">"
+ MEL["slide" fontSizes[ind], MELCLOSE] = "</div>"
+ MEL["middle" fontSizes[ind], MELOPEN] = "<div id=\"[SLIDEID]\" class=\"slide centered-slide" fontClass "\"><div></div><div>"
+ MEL["middle" fontSizes[ind], MELCLOSE] = "</div><div></div></div>"
+ MEL["title" fontSizes[ind], MELOPEN] = "<div id=\"[SLIDEID]\" class=\"slide centered-slide centered" fontClass "\"><div></div><div>"
+ MEL["title" fontSizes[ind], MELCLOSE] = "</div><div></div></div>"
+
+ standardPresentationTag("centered" fontSizes[ind], "centered" fontClass)
+ }
+
+ # refer to definition of fontSizes[0]
+ delete fontSizes[0]
+
+ # Tags which cannot exist without specified font-size
+ for (ind in fontSizes) {
+ standardPresentationTag("font" fontSizes[ind])
+ }
+
+ #
+ # Special cases
+ #
+
+ MEL["presentation", MELINSERT] = ORS \
+"<nav id=\"presentCont\">" ORS \
+" <span id=\"prevSlideBtn\" class=\"btn nodisplay\">&#x2190;</span>" ORS \
+" <a id=\"slideIndex\" class=\"nodisplay\" href=\"#slide-0\">0</a>" ORS \
+" <span id=\"nextSlideBtn\" class=\"btn nodisplay\">&#x2192;</span>" ORS \
+" <span id=\"articleBtn\" class=\"btn setting-btn\">Article view &#x2632;</span>" ORS \
+" <span id=\"presentBtn\" class=\"btn setting-btn\">Present &#x239A;</span>" ORS \
+" <span id=\"printBtn\" class=\"btn setting-btn\">Print &#x2399;</span>" ORS \
+" </nav><br><br>" ORS \
+" <script type=\"text/javascript\" src=\"/scripts/presentation.js\" crossorigin=\"anonymous\"></script>"
+
+ MEL["row", MELOPEN] = "<div class=\"layout-table\"><div class=\"layout-row\">" # <table><tr> (layout-row > * is td)
+ MEL["row", MELCLOSE] = "</div></div>" # </tr><table>
+
+ MEL["sqrow", MELOPEN] = "<div class=\"layout-table fixed-layout\"><div class=\"layout-row\">" # <table><tr> (layout-row > * is td)
+ MEL["sqrow", MELCLOSE] = "</div></div>"
+
+ MEL["newrow", MELINSERT] = "</div><div class=\"layout-row\">" # </tr><tr>
+
+ #
+ # Generated tags
+ #
+
+ for (i = 1; i <= 9; i++) {
+ MEL["br" i, MELINSERT] = "<div class=\"br" i "\"></div>"
+ }
+ for (i = 5; i <= 95; i++) {
+ standardPresentationTag("width" i "%", "width" i "per")
+ }
+
+ #
+ # Ordinary
+ #
+
+ standardPresentationTag("fright", "float-right")
+ standardPresentationTag("column")
+}
+
+function standardPresentationTag(name, class) {
+ if (class == "") class = name
+ MEL[name, MELOPEN] = "<div class=\"" class "\">"
+ MEL[name, MELCLOSE] = "</div>"
+}
+
+/\[SLIDEID\]/ {
+ sub(/\[SLIDEID\]/, "slide-" slideIndex++)
+}
diff --git a/awk-edits/MEL-parser.awk b/awk-edits/MEL-parser.awk
new file mode 100644
index 0000000..f0a8f84
--- /dev/null
+++ b/awk-edits/MEL-parser.awk
@@ -0,0 +1,134 @@
+# .*html
+#
+# == About ==
+#
+# MEL is the "Markdown Extensions Language"
+# It's a general metalanguage (I made) for adding custom syntax to Markdown (via awk)
+# The idea is it provides parsing for general constructs, and you only need to define
+# the names of those constructs and with what they get replaced with
+#
+# Slightly based on ftags, this system allows you to easily implement the following construts:
+# &(name ... &) Multiline "tag", everything inside is formatted by "name"
+# &{name ... &} In practice, it just replaces "&[name" and "&]" with the appropriate HTML
+# &[name ... &] All three can be used interchangeably, though it's preferrable if
+# you use the matching braces and semantically, in your "language"
+# square brackets are used for the largest components
+# curly for structural components and normal braces for styling
+# &:name Format/encapsulate everything until the end of the paragraph
+# &::name Format/encapsulate everything until the end of the line
+# &.name Insert standalone element as-is
+#
+# Though it's not decided (or implemented) yet, potentially there will also be:
+# &)-( Used to simplify cases of &(name1 ... &) &(name1 ... &) &(name1 ... &)
+# &}-{ into &(name1 ... &)-( ... &)-( ... &)
+# &]-[ Or maybe for special cases, where rather than doing something like
+# &{elementsList &(element1 ... &) &(element2 ... &) &}
+# you could simply do
+# &{elementsList ... &}-{ ... &}-{ ... &}
+# So it will surf as a separator between direct subelements
+
+BEGIN {
+ usesMEL()
+ newStack("mel")
+}
+
+function usesMEL() {
+ MELOPEN = "o"
+ MELCLOSE = "c"
+ MELLINEOPEN = "lo"
+ MELLINECLOSE = "lc"
+ MELINSERT = "i"
+ MELPARAGRAPH = "p"
+ MELLINE = "l"
+}
+
+function printErr(message, column, columnPointer) {
+ column = length($0) - length(lineCopy) + RSTART - 5
+ print "ERROR by MEL-parser.awk: " message " | Found in " FILENAME " at line " FNR " & column " column ":" > "/dev/stderr"
+ columnPointer = ""
+ for (i = 1; i < column; i++)
+ columnPointer = columnPointer " "
+ for (i = -5; i < RLENGTH; i++)
+ columnPointer = columnPointer "^"
+ print $0 "\n" columnPointer "\n" > "/dev/stderr"
+}
+
+/<code>/ {
+ melInsideCode = 1
+}
+
+/<\/code>/ {
+ melInsideCode = 0
+}
+
+melInsideCode == 0 && /^[ \t]*(<p>|<dt>)?&#38;[{[()\]}:.]/ {
+ newLine = ""
+ lineCopy = $0
+ paragraphed = 0
+ append = ""
+ while (match(lineCopy, /&#38;(((::|[[{(:.])[^[:space:].:;[{(<>)}\]&]+)|[\]})])/)) {
+ RSTART += 5
+ RLENGTH -= 5
+
+ # Inside closing tag
+ if (RLENGTH == 1) {
+ replaceWith = MEL[topStack("mel"), MELCLOSE]
+
+ if (replaceWith == "")
+ printErr("Missing closing tag for \"" topStack("mel") "\"")
+
+ popStack("mel")
+ }
+ # Inside insert
+ else if (substr(lineCopy, RSTART, 1) == ".") {
+ name = substr(lineCopy, RSTART + 1, RLENGTH - 1)
+
+ replaceWith = MEL[name, MELINSERT]
+
+ if (replaceWith == "")
+ printErr("Unknown insertion tag \"" name "\"")
+ }
+ # Inside one line
+ else if (substr(lineCopy, RSTART, 2) == "::") {
+ name = substr(lineCopy, RSTART + 2, RLENGTH - 2)
+
+ replaceWith = MEL[name, MELLINEOPEN]
+ append = append MEL[name, MELLINECLOSE]
+
+ if (replaceWith == "" && append == "")
+ printErr("Unknown single line tag \"" name "\"")
+ else if (replaceWith == "")
+ printErr("Missing beginning for line tag \"" name "\"")
+ else
+ printErr("Missing ending for line tag \"" name "\"")
+ }
+ # Inside paragraph
+ else if (substr(lineCopy, RSTART, 1) == ":") {
+ name = substr(lineCopy, RSTART + 1, RLENGTH - 1)
+
+ replaceWith = " " MEL[name, MELPARAGRAPH]
+
+ if (replaceWith == " ")
+ printErr("Unknown paragraph tag \"" name "\"")
+
+ RSTART -= 1
+ RLENGTH += 1
+ paragraphed = 1
+ }
+ # Inside opening tag
+ else {
+ name = substr(lineCopy, RSTART + 1, RLENGTH - 1)
+
+ replaceWith = MEL[name, MELOPEN]
+ pushStack("mel", name)
+
+ if (replaceWith == "")
+ printErr("Unknown opening tag \"" name "\"")
+ }
+ newLine = newLine substr(lineCopy, 0, RSTART - 6) replaceWith
+ lineCopy = substr(lineCopy, RSTART + RLENGTH)
+ }
+ $0 = newLine lineCopy append
+ if (paragraphed == 0 && newLine != "")
+ gsub(/(<p>|<\/p>)/, "")
+}