From f6781edad8bed29c4249960fd80827cee12d0581 Mon Sep 17 00:00:00 2001 From: simonpetit Date: Wed, 10 Dec 2025 17:11:41 +0000 Subject: [PATCH] testing --- css/indexstyle.css | 9 + css/poststyle.css | 6 + drafts/published/awk_static_blog_generator.md | 14 +- drafts/published/awk_to_parse_markdown.md | 36 +-- index.html | 5 +- posts/awk_static_blog_generator.html | 141 ++++++++++++ posts/awk_to_parse_markdown.html | 207 ++++++++++++++++++ posts/markdown_testing_suite.html | 83 +++++++ posts/test.html | 0 9 files changed, 474 insertions(+), 27 deletions(-) create mode 100644 posts/awk_static_blog_generator.html create mode 100644 posts/awk_to_parse_markdown.html create mode 100644 posts/markdown_testing_suite.html delete mode 100644 posts/test.html diff --git a/css/indexstyle.css b/css/indexstyle.css index f415e14..0537a5e 100644 --- a/css/indexstyle.css +++ b/css/indexstyle.css @@ -26,6 +26,15 @@ ul li a:hover { color: #AAA; } +ul li div { + display: flex; + flex-direction: row; +} + +ul li div p { + font-size: 0.8em; +} + .title { margin-top: 5vh; margin-bottom: 7vh; diff --git a/css/poststyle.css b/css/poststyle.css index f639a39..2969be6 100644 --- a/css/poststyle.css +++ b/css/poststyle.css @@ -19,6 +19,12 @@ body { color: #AAA; } +.dates { + display: flex; + flex-direction: row; + justify-content: space-around; +} + article { width: 70vw; margin-right: auto; diff --git a/drafts/published/awk_static_blog_generator.md b/drafts/published/awk_static_blog_generator.md index 0446683..4342d89 100644 --- a/drafts/published/awk_static_blog_generator.md +++ b/drafts/published/awk_static_blog_generator.md @@ -50,21 +50,21 @@ and I use `awk` to replace `{{article}}` with the actual content of the posts, l # Storing the path of the post/article to publish # The path is supposed to have this format "./drafts/published/
.* article_path=$1 - + # from the relative path, only retrieving the name of the article (without file extension) article_name=$(echo $article_path | cut -d '/' -f 4 | cut -d '.' -f 1) - + # Convert the markdown draft into an html article and storing it locally post=$(awk -f ${BOB_LIB}/markdown.awk ./$article_path) - + # Retrieving the html article template template="${BOB_LIB}/template/post.html" - + # Escaping the & for next step to not confuse awk - escaped_post=$(echo "$post" | sed 's/&/\\&/g') - + escaped_post=$(echo "$post" | sed 's/&/\\\\&/g') + # In the template, replacing the string {{article}} by the actual content parsed above - awk -v content="$escaped_post" '{gsub(/\{\{article\}\}/, content); print}' "$template" > "./posts/$article_name.html" + awk -v content="$escaped_post" '{gsub(/{{article}}/, content); print}' "$template" > "./posts/$article_name.html" } The home page template is similar : diff --git a/drafts/published/awk_to_parse_markdown.md b/drafts/published/awk_to_parse_markdown.md index 722674e..6661631 100644 --- a/drafts/published/awk_to_parse_markdown.md +++ b/drafts/published/awk_to_parse_markdown.md @@ -23,18 +23,18 @@ AWK works as follow : it takes an optional regex and execute some code between b For example : /^#/ { - print "<h1>" $0 "</h1>" + print "

" $0 "

" } Although `$n` refers to the n-th records in the line (according to a delimiter, like in a csv), the special `$0` refers to the whole line. -In this case, for each line starting with `#`, awk will print (to the standard output), `<h1> [content of the line] </h1>`. +In this case, for each line starting with `#`, awk will print (to the standard output), `

[content of the line]

`. This is the beginning to parse headers in markdown. However, by trying this, we immediatly see that `#` is part of the whole line, hence it also appear in the html whereas it sould not. AWK has a way to prevent this, as it is a complete scripting language, with built-in functions, that enable further manipulations. `substr` acts as its name indicates, it return a substring of its argument. /^#/ { - print "<h1>" substr($0, 3) "</h1>" + print "

" substr($0, 3) "

" } In the example above, as per the [documentation](https://www.gnu.org/software/gawk/manual/html_node/String-Functions.html#index-substr_0028_0029-function) @@ -46,11 +46,11 @@ and allows the script to dynamically determine which depth of header it parses. /^#+ / { match($0, /#+ /); n = RLENGTH; - print "<h" n-1 ">" substr($0, n + 1) "</h" n-1 ">" + print "" substr($0, n + 1) "" } Reproducing this technique to parse the rest proves to be difficult, as lists for example, are not contained in a single line, hence -how to know when to close it with `</ul>` or `</ol>` +how to know when to close it with `` or `` ## Introducing a LIFO stack @@ -82,7 +82,7 @@ Turns out it came out to be easy, I only needed a pointer to track the size of t } The stack does not have to be strictly declared. The value of inside the LIFO correspond to the current markdown environment. -This is a clever trick, because when I need to close an html tag, I use the poped element between a `</` and a `>` instead of having a matching table. +This is a clever trick, because when I need to close an html tag, I use the poped element between a `` instead of having a matching table. I also used a simple `last()` function to return the last pushed value in the stack without popping it out : @@ -99,11 +99,11 @@ This way, parsing lists became trivial : env = last() if (env == "ul" ) { # In a unordered list block, print a new item - print "<li>" substr($0, 3) "</li>" + print "
  • " substr($0, 3) "
  • " } else { # Otherwise, init the unordered list block push("ul") - print "<ul>\n<li>" substr($0, 3) "</li>" + print "