forb

Forb is static blog generator inspired by jekyll
git clone https://noulin.net/git/forb.git
Log | Files | Refs | README | LICENSE

commit 1c3f71af53ca08c767c759f782cf4ef28fb74558
parent 7a2e4e3d317d4232e77213091755ed76b6f6cd67
Author: Remy Noulin <loader2x@gmail.com>
Date:   Thu, 11 Jun 2020 11:59:48 +0200

fix bug when no language is specified for a code block

forb.c | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)

Diffstat:
Mforb.c | 16++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/forb.c b/forb.c @@ -392,7 +392,7 @@ bool generateAPageOrAPost(char *filename, smallJsont *cfg, smallArrayt *postsFee // add class in <code> // process {% post_url 2015-12-22-test %} // add syntax highlighting - enum {searchCode, bash, javascript, python, html, coffeescript}; + enum {searchCode, notspecified, bash, javascript, python, html, coffeescript}; int status = searchCode; int lastCodeHighlightingLine = -1; iter(pHtml, L) { @@ -413,7 +413,15 @@ bool generateAPageOrAPost(char *filename, smallJsont *cfg, smallArrayt *postsFee //lv(l); } // code highlighting - replaceG(l, "<code>", "<code class=\"highlighter-rouge\">", 0); + if (status == searchCode and hasG(l, "<code>")) { + if (hasG(l, "<pre><code>")) { + replaceG(l, "<pre><code>", "<figure class=\"highlight\"><pre><code class=\"highlighter-rouge\">", 0); + status = notspecified; + } + else { + replaceG(l, "<code>", "<code class=\"highlighter-rouge\">", 0); + } + } if (status == searchCode and hasG(l, "<pre><code class=\"language-")) { lastCodeHighlightingLine = iterIndexG(pHtml); } @@ -435,10 +443,10 @@ bool generateAPageOrAPost(char *filename, smallJsont *cfg, smallArrayt *postsFee if (hasG(l, "</code></pre>")) { if (status == searchCode) { if (lastCodeHighlightingLine == -1) { - logE("line %d in html for "BLD"%s"RST", code highlighting not found.", iterIndexG(pHtml), &filename[18]); + logW("line %d in html for "BLD"%s"RST", code highlighting not found. This code block doesn't have highlighting.", iterIndexG(pHtml), &filename[18]); } else { - logE("line %d in html for "BLD"%s"RST", code highlighting not recognize: '%s'", iterIndexG(pHtml), &filename[18], $(pHtml, lastCodeHighlightingLine)); + logW("line %d in html for "BLD"%s"RST", code highlighting not recognize: '%s'. This code block doesn't have highlighting.", iterIndexG(pHtml), &filename[18], $(pHtml, lastCodeHighlightingLine)); } } else replaceG(l, "</code></pre>", "</code></pre></figure>", 0);