From d640698414d29b0e107f94aba233a2e2ac0f9289 Mon Sep 17 00:00:00 2001 From: Phil Hagelberg Date: Tue, 28 Feb 2023 08:52:56 -0800 Subject: [PATCH] Use fennel-highlight for Lua code too. We can just swap out the keywords and get a decent highlighting of Lua code as well as Fennel. Of course, it doesn't cover: * single-quote strings * multi-line strings * comments However, none of those things are present in the compiler output or the provided Lua examples. --- Makefile | 2 +- see.fnl | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 854b7f1..84e319f 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ .DEFAULT_GOAL := build -TAGS := $(shell git --git-dir=./fennel/.git tag -l | grep '^[0-9]' | grep -v - | grep -v 0.0.1 | tac) +TAGS ?= $(shell git --git-dir=./fennel/.git tag -l | grep '^[0-9]' | grep -v - | grep -v 0.0.1 | tac) TAGDIRS := main $(foreach tag, $(TAGS), v${tag}) # which fennel/$.md files build a tag index diff --git a/see.fnl b/see.fnl index 406518a..7c116b5 100644 --- a/see.fnl +++ b/see.fnl @@ -49,14 +49,25 @@ ;; and ensure the input textarea and output pre have the same dimensions ;; using a bunch of CSS +(local fennel-syntax (require :syntax-table)) + (fn highlight-fennel [] - (let [highlight (require :highlight) - syntax-table (require :syntax-table)] + (let [highlight (require :highlight)] (set fennel-highlighted.innerHTML - (highlight.for-html syntax-table fennel-source.value)))) + (highlight.for-html fennel-syntax fennel-source.value)))) + +(local lua-syntax (collect [k v (pairs fennel-syntax)] + (if v.global? (values k v)))) + +(each [_ k (ipairs [:and :break :do :else :elseif :end :false :for :function + :if :in :local :nil :not :or :repeat :return :then :true + :until :while :goto])] + (tset lua-syntax k {:special? true})) (fn highlight-lua [] - (set lua-highlighted.innerHTML lua-source.value)) + (let [highlight (require :highlight)] + (set lua-highlighted.innerHTML + (highlight.for-html lua-syntax lua-source.value)))) ;; initial run, since there could be something left in the textarea ;; after a page refresh -- 2.45.2