Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
Commitc81e2f9ba3c23be418c4d44a0242c65d48dc6c4b (patch)
Author
 Syndamia <kamen@syndamia.com>
2025-11-15 12:08:12 +0200
Committer
 Syndamia <kamen@syndamia.com>
2025-11-15 12:08:12 +0200
Files602779dae2716864163b1abecf491e470886057f
syndamia.com-c81e2f9ba3c23be418c4d44a0242c65d48dc6c4b.tar
syndamia.com-c81e2f9ba3c23be418c4d44a0242c65d48dc6c4b.tar.gz
syndamia.com-c81e2f9ba3c23be418c4d44a0242c65d48dc6c4b.zip
Parent044e4f1eef1c70fb0b20aea435ef5513de0becf0 (diff)
feat!: Implement syntax highlighting, based on another tool
4 files changed, 69 insertions, 36 deletions
-rw-r--r--ext/highlight.awk35
-rwxr-xr-xgenerate.sh13
-rw-r--r--meta/header.html3
-rw-r--r--src/styles.css54
diff --git a/ext/highlight.awk b/ext/highlight.awk
new file mode 100644
index 0000000..a1f15fa
--- /dev/null
+++ b/ext/highlight.awk
@@ -0,0 +1,35 @@
+BEGIN {
+ highlight_cmd = ENVIRON["HIGHLIGHT"] " -O html -f -S " # expected language name in the end!
+ highlight_out = "/tmp/__fragment"
+ highlight_langs = "awk,bat,bison,y,bash,sh,zsh,yacc,c,cpp,h,hpp,csharp,cs,css," \
+ "diff,patch,dockerfile,email,go,haskell,hs,html,htm,xhtml," \
+ "httpd,ini,cfg,desktop,java,gradle,javascript,js,json,kotlin," \
+ "lisp,cl,clisp,sbcl,lua,makefile,mk,markdown,md,meson,mssql," \
+ "nix,perl,pl,php,python,py,qmake,rust,rs,s,sql,svg,tex,toml,xml,yaml"
+}
+
+ENVIRON["HIGHLIGHT"] && language && blocks_names[blocks_opened] == "CODE" {
+ hl_lang = tolower(language)
+ if (hl_lang == "yacc") hl_lang = "y"
+ if (hl_lang == "latex") hl_lang = "tex"
+
+ transcludes_file = toupper($1) == "'INCLUDE" || toupper($1) == "'SNIPPET"
+
+ if (highlight_langs ~ hl_lang && (transcludes_file || !/^[ \t]*'/)) {
+ __tmp = FILE_EXTENSION
+ FILE_EXTENSION = ""
+
+ if (transcludes_file)
+ process_command(toupper(substr($1, 2)))
+
+ highlight = highlight_cmd hl_lang " > " highlight_out
+
+ print | highlight
+ close(highlight)
+
+ $0 = getfile(highlight_out)
+ gsub(/\\/, "\\\\")
+
+ FILE_EXTENSION = __tmp
+ }
+}
diff --git a/generate.sh b/generate.sh
index 44df429..a9efe8c 100755
--- a/generate.sh
+++ b/generate.sh
@@ -17,6 +17,7 @@ NO_FIX=
NO_META=
NO_TINY=
FORCE_GEN=
+HIGHLIGHT=
while [ -n "$1" ]
do
case "$1" in
@@ -24,11 +25,22 @@ do
(-m|--no_meta) NO_META=y ;;
(-t|--no_tiny) NO_TINY=y ;;
(-f|--force) FORCE_GEN=y ;;
+ (-hi|--highlight)
+ if command -v highlight >/dev/null 2>&1
+ then
+ HIGHLIGHT="$(command -v highlight)"
+ else
+ echo 'Requested highlighting but could not find "highlight" command!'
+ exit 1
+ fi
+ ;;
(*) echo "Unknown argument '$1'!" ; exit 1 ;;
esac
shift
done
+export HIGHLIGHT
+
#== 0. Check for changes ==#
if [ -z "$FORCE_GEN" ] \
@@ -78,6 +90,7 @@ cp -a "$SRC/." "$DST"
/bin/sh ./dunbar/dunbar_awk/dunbar.sh html \
-i \
-e ./ext/pagenav.awk -e ./ext/presentation.awk \
+ -e ./ext/highlight.awk \
./ext/global.du \
$(find "$DST" -type f -name "*.du")
diff --git a/meta/header.html b/meta/header.html
index 6e0963d..f377483 100644
--- a/meta/header.html
+++ b/meta/header.html
@@ -103,7 +103,8 @@
<a href="https://gitlab.com/Syndamia/syndamiadotcom" target="_blank" class="link-tab">Powered with:</a><span class="br"></span>
<a href="https://gitlab.com/Syndamia/dunbar" target="_blank" class="link-tab">dunbar</a><span class="br"></span><span class="nocss-aid">, </span>
<a href="https://invisible-island.net/mawk/" target="_blank" class="link-tab">mawk</a><span class="br"></span><span class="nocss-aid">, </span>
- <a href="https://www.gnu.org/software/bash/" target="_blank" class="link-tab">GNU bash</a>
+ <a href="https://www.gnu.org/software/bash/" target="_blank" class="link-tab">GNU bash</a><span class="br"></span><span class="nocss-aid">, </span>
+ <a href="http://andre-simon.de/doku/highlight/en/highlight.php" target="_blank" class="link-tab">Highlight</a>
</nav>
</nav>
diff --git a/src/styles.css b/src/styles.css
index 133afe2..747ec72 100644
--- a/src/styles.css
+++ b/src/styles.css
@@ -37,25 +37,15 @@
--hic-orange: #af3a03;
--hi-comment: var(--hic-gray);
- --hi-const: var(--hic-purple);
--hi-string: var(--hic-green);
- --hi-char: var(--hic-purple);
+ --hi-interp: var(--hic-purple);
--hi-number: var(--hic-purple);
- --hi-bool: var(--hic-purple);
- --hi-float: var(--hic-purple);
- --hi-identifier: var(--hic-blue);
--hi-function: var(--hic-green);
- --hi-statement: var(--hic-red);
- --hi-conditional: var(--hic-red);
- --hi-repeat: var(--hic-red);
- --hi-operator: var(--hi-fg);
- --hi-keyword: var(--hic-red); /* Label and Exception are keywords */
+ --hi-operator: var(--hic-orange);
+ --hi-keyword: var(--hic-red);
--hi-preproc: var(--hic-aqua);
--hi-type: var(--hic-yellow);
- --hi-storageclass: var(--hic-orange);
- --hi-structure: var(--hic-aqua);
- --hi-typedef: var(--hic-aqua);
- --hi-ignore: var(--hi-fg);
+ --hi-escape: var(--hic-orange);
}
/*## Global ##*/
@@ -467,27 +457,21 @@ table pre > code {
}
dd code { font-size: 0.8em; }
-.HI-comment { color: var(--hi-comment); }
-.HI-const { color: var(--hi-const); }
-.HI-string { color: var(--hi-string); }
-.HI-char { color: var(--hi-char); }
-.HI-number { color: var(--hi-number); }
-.HI-bool { color: var(--hi-bool); }
-.HI-float { color: var(--hi-float); }
-.HI-identifier { color: var(--hi-identifier); }
-.HI-function { color: var(--hi-function); }
-.HI-statement { color: var(--hi-statement); }
-.HI-conditional { color: var(--hi-conditional); }
-.HI-repeat { color: var(--hi-repeat); }
-.HI-operator { color: var(--hi-operator); }
-.HI-keyword { color: var(--hi-keyword); /* Label and Exception are keywords */ }
-.HI-preproc { color: var(--hi-preproc); }
-.HI-type { color: var(--hi-type); }
-.HI-storageclass { color: var(--hi-storageclass); }
-.HI-structure { color: var(--hi-structure); }
-.HI-typedef { color: var(--hi-typedef); }
-.HI-ignore { color: var(--hi-ignore); }
-.HI-comment * { color: inherit; } /* If text inside a comment is matched, don't show it */
+.hl.erm { color:#ff0000; font-weight:bold; border:solid 1px red; margin-left: 3em; }
+.hl.err { color:#ff0000; font-weight:bold; }
+.hl.kwf { color:#750dc3; }
+
+.hl.slc, .hl.com { color: var(--hi-comment); }
+.hl.pps, .hl.sng { color: var(--hi-string); }
+.hl.kwb, .hl.kwc { color: var(--hi-type); }
+.hl.num { color: var(--hi-number); }
+.hl.ipl { color: var(--hi-interp); }
+.hl.kwd { color: var(--hi-function); font-weight: bold; }
+.hl.kwa { color: var(--hi-keyword); }
+.hl.opt { color: var(--hi-operator); }
+.hl.ppc { color: var(--hi-preproc); }
+.hl.esc { color: var(--hi-escape); }
+.hl.kwe { color: inherit; }
/*### Wrapper > Article > table ###*/