diff options
| Commit | bf13dac3035d59bb9463b924a4efbef32b549f27 (patch) | |
|---|---|---|
| Author | 2024-07-22 16:00:23 +0300 | |
| Committer | 2024-07-22 16:00:23 +0300 | |
| Files | 1f7131c6dce527383e7176658a68631de5c2b369 | |
| csg-bf13dac3035d59bb9463b924a4efbef32b549f27.tar csg-bf13dac3035d59bb9463b924a4efbef32b549f27.tar.gz csg-bf13dac3035d59bb9463b924a4efbef32b549f27.zip | ||
| Parent | 9c0695c3838734301f09e91797747f94c8328713 (diff) | |
(csg) Implemented a rough user.begin.awk system
5 files changed, 181 insertions, 112 deletions
| -rwxr-xr-x | csg | 5 | ||||
| -rw-r--r-- | demo.md | 98 | ||||
| -rw-r--r-- | demo/src/index.md | 101 | ||||
| -rw-r--r-- | single.awk | 85 | ||||
| -rw-r--r-- | user.begin.awk | 4 |
@@ -1,4 +1,5 @@ #/usr/bin/env sh +# vim:ft=sh ### Preprocessing 1 ### Help message @@ -100,7 +101,7 @@ EOF ### Stage 2 ### Meta -echo 'BEGIN {' > meta.begin.awk +echo 'BEGIN { FILENAME=ARGV[1];FIRST="f";ALL="a"' > meta.begin.awk while read -r file do $CSG_AWK -f meta.awk "$file" >> meta.begin.awk & @@ -118,7 +119,7 @@ convert_file() { local outf="${file%md}html" $CSG_AWK \ - -f meta.begin.awk -f lib_stack.awk -f single.awk \ + -f meta.begin.awk -f lib_stack.awk -f user.begin.awk -f single.awk \ "$file" > "$outf" rm "$file" } diff --git a/demo.md b/demo.md deleted file mode 100644 index e167f19..0000000 --- a/demo.md +++ /dev/null @@ -1,98 +0,0 @@ ---HTML-- - -This is a regular paragraph. - -<table> - <tr> - <td>Foo</td> - </tr> -</table> - -This is another regular paragraph. - -© AT&T 4 < 5 - -This is an H1 -============= - -This is an H2 -------------- - -# This is an H1 - -## This is an H2 - -###### This is an H6 - -# This is an H1 # - -## This is an H2 ## - -### This is an H3 ###### - ->a - -> a - ->>a - -> > a - -> This is the first level of quoting. -> -> > This is nested blockquote. -> -> Back to the first level. - -> This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet, -consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus. -Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus. - -> Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse -id sem consectetuer libero luctus adipiscing. - -> ## This is a header. -> -> 1. This is the first list item. -> 2. This is the second list item. -> -> Here's some example code: -> -> return shell_exec("echo $input | $markdown_script"); - -*single asterisks* - -_single underscores_ - -**double asterisks** - -__double underscores__ - -***a*** test _**b**_ - -un*frigging*believable - -* a - b - c - 1. Sublist a - 2. b - 3. c - -* o - *Hello* - - **World** - -This is [an example](http://example.com/ "Title") inline link. - -[This link](http://example.net/) has no title attribute. - -See my [About](/about/) page for details. - -This is __a__ itali__cised__ text - -x~2~^e^ = y^някоя си^~търсно то~ -: **Common** [programmer](https://wikipedia.org "Me") phrase - -Lorem `ipsum` dolor tiada ad;l ``kfj `skigj`` jjsa diff --git a/demo/src/index.md b/demo/src/index.md index 986d6ad..6958e44 100644 --- a/demo/src/index.md +++ b/demo/src/index.md @@ -1,3 +1,100 @@ -# Welcome to my site - This is a demo webpage, made with [csg](https://gitlab.com/Syndamia/csg). + +--HTML-- + +This is a regular paragraph. + +<table> + <tr> + <td>Foo</td> + </tr> +</table> + +This is another regular paragraph. + +© AT&T 4 < 5 + +This is an H1 +============= + +This is an H2 +------------- + +# This is an H1 + +## This is an H2 + +###### This is an H6 + +# This is an H1 # + +## This is an H2 ## + +### This is an H3 ###### + +>a + +> a + +>>a + +> > a + +> This is the first level of quoting. +> +> > This is nested blockquote. +> +> Back to the first level. + +> This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet, +consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus. +Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus. + +> Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse +id sem consectetuer libero luctus adipiscing. + +> ## This is a header. +> +> 1. This is the first list item. +> 2. This is the second list item. +> +> Here's some example code: +> +> return shell_exec("echo $input | $markdown_script"); + +*single asterisks* + +_single underscores_ + +**double asterisks** + +__double underscores__ + +***a*** test _**b**_ + +un*frigging*believable + +* a + b + c + 1. Sublist a + 2. b + 3. c + +* o + *Hello* + + **World** + +This is [an example](http://example.com/ "Title") inline link. + +[This link](http://example.net/) has no title attribute. + +See my [About](/about/) page for details. + +This is __a__ itali__cised__ text + +x~2~^e^ = y^някоя си^~търсно то~ +: **Common** [programmer](https://wikipedia.org "Me") phrase + +Lorem `ipsum` dolor tiada ad;l ``kfj `skigj`` jjsa @@ -41,9 +41,26 @@ BEGIN { function println(line) { if (0 == line) line = $0 - if (!skipprint) print prev + print prev prev = line - skipprint = 0 +} + +function autoinsert(arrname, isbefore) { + if (isbefore == "") isbefore = 0 + for (confstr in arrname) { + split(confstr, conf, SUBSEP) + + ## FILENAME regex, ".*" (default) + if (2 in conf && FILENAME !~ conf[2]) { continue } + ## Text regex, ".*" (default) + if (3 in conf && text !~ conf[3]) { continue } + + if (isbefore) prev = arrname[confstr] prev + else prev = prev arrname[confstr] + + ## When, FIRST | ALL + if (conf[1] == FIRST) { delete arrname[confstr] } + } } { @@ -86,10 +103,14 @@ function println(line) { level += RSTART while (topStack("bq-level") > level) { println("</blockquote>") + autoinsert(user_BLOCKQUOTE_AFTER) + popStack("bq-level") } if (topStack("bq-level") < level) { + autoinsert(user_BLOCKQUOTE_BEFORE, 1) println("<blockquote>") + pushStack("bq-level", level) } } @@ -102,7 +123,25 @@ function println(line) { ## Remove prefix/suffix gsub(/^[[:blank:]]*#+[[:blank:]]*/, "") gsub(/[[:blank:]]*#+[[:blank:]]*$/, "") + + if (RLENGTH == 1) autoinsert(user_H1_BEFORE, 1) + else if (RLENGTH == 2) autoinsert(user_H2_BEFORE, 1) + else if (RLENGTH == 3) autoinsert(user_H3_BEFORE, 1) + else if (RLENGTH == 4) autoinsert(user_H4_BEFORE, 1) + else if (RLENGTH == 5) autoinsert(user_H5_BEFORE, 1) + else if (RLENGTH == 6) autoinsert(user_H6_BEFORE, 1) + autoinsert(user_H_BEFORE, 1) + println("<h" RLENGTH ">" $0 "</h" RLENGTH ">") + + autoinsert(user_H_AFTER) + if (RLENGTH == 1) autoinsert(user_H1_AFTER) + else if (RLENGTH == 2) autoinsert(user_H2_AFTER) + else if (RLENGTH == 3) autoinsert(user_H3_AFTER) + else if (RLENGTH == 4) autoinsert(user_H4_AFTER) + else if (RLENGTH == 5) autoinsert(user_H5_AFTER) + else if (RLENGTH == 6) autoinsert(user_H6_AFTER) + blankline = 1 next } @@ -111,15 +150,26 @@ function println(line) { !prev_blankline && /^[[:blank:]]*(=|-)+[[:blank:]]*$/ { sub(/^<p>/, "", prev) ## from paragraph logic hlevel = 1 + ($0 ~ /-/) - print "<h" hlevel ">" prev "</h" hlevel ">" + + prev = "<h" hlevel ">" prev "</h" hlevel ">" + + if (hlevel == 1) autoinsert(user_H1_BEFORE, 1) + else autoinsert(user_H2_BEFORE, 1) + autoinsert(user_H_BEFORE, 1) + + autoinsert(user_H_AFTER) + if (hlevel == 1) autoinsert(user_H1_AFTER) + else autoinsert(user_H2_AFTER) + blankline = 1 - skipprint = 1 next } # Horizontal rules /^(-|\*|_) ?(-|\*|_) ?(-|\*|_|[[:blank:]])+$/ { + autoinsert(user_HR_BEFORE, 1) println("<hr>") + autoinsert(user_HR_AFTER) blankline = 1 next } @@ -143,16 +193,31 @@ function abs(x) { return ((x < 0) ? -x : x) } if (RLENGTH == -1) RLENGTH = 0 ## indent + RLENGTH = length(" * " or " 1. ") while (indent + RLENGTH < abs(topStack("list-level"))) { - if (topStack("list-level") < 0) println("</ol>") - else println("</ul>") + if (topStack("list-level") < 0) { + println("</ol>") + autoinsert(user_L_AFTER) + autoinsert(user_OL_AFTER) + } + else { + println("</ul>") + autoinsert(user_L_AFTER) + autoinsert(user_UL_AFTER) + } popStack("list-level") } } /^[[:blank:]]*(\*|\+|-|[[:digit:]]+\.) / { match($0, /(\*|\+|-|[[:digit:]]+\.) /) if (abs(topStack("list-level")) < RSTART) { - if (RLENGTH > 2) { xl = "<ol>"; mult = -1 } - else { xl = "<ul>"; mult = 1 } + if (RLENGTH > 2) { + xl = "<ol>"; mult = -1 + autoinsert(user_OL_BEFORE, 1) + } + else { + xl = "<ul>"; mult = 1 + autoinsert(user_UL_BEFORE, 1) + } + autoinsert(user_L_BEFORE, 1) println(xl "<li>") pushStack("list-level", mult * (RSTART + RLENGTH - 1)) } @@ -170,6 +235,7 @@ prev_blankline && !blankline && lengthStack("bq-level") == 0 && lengthStack("lis blankline { while (lengthStack("bq-level") > 0) { println("</blockquote>") + autoinsert(user_BLOCKQUOTE_AFTER) popStack("bq-level") } } @@ -218,8 +284,7 @@ function surround(brace, opening, closing) { !prev_blankline && /^: / { sub(/^<p>/, "", prev) sub(/^: /, "") - print "<dl><dt>" prev "</dt>" ORS "<dd>" $0 "</dd></dl>" - skipprint = 1 + prev = "<dl><dt>" prev "</dt>" ORS "<dd>" $0 "</dd></dl>" blankline = 1 next } diff --git a/user.begin.awk b/user.begin.awk new file mode 100644 index 0000000..c2f31a0 --- /dev/null +++ b/user.begin.awk @@ -0,0 +1,4 @@ +BEGIN { + user_H1_BEFORE[ALL, ".*index.*"] = \ + "<div>Words: " meta[FILENAME, "words"] "</div>" +} |
