Summary Files Commits Branches @commit @diff @stats
path: root / ext
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 /ext
syndamia.com-c81e2f9ba3c23be418c4d44a0242c65d48dc6c4b.tar
syndamia.com-c81e2f9ba3c23be418c4d44a0242c65d48dc6c4b.tar.gz
syndamia.com-c81e2f9ba3c23be418c4d44a0242c65d48dc6c4b.zip
Parent044e4f1eef1c70fb0b20aea435ef5513de0becf0 (diff)
feat!: Implement syntax highlighting, based on another tool
1 files changed, 35 insertions, 0 deletions
-rw-r--r--ext/highlight.awk35
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
+ }
+}