d640698414d29b0e107f94aba233a2e2ac0f9289 — Phil Hagelberg 6 months ago a8d9682
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.
2 files changed, 16 insertions(+), 5 deletions(-)

M Makefile
M see.fnl
M Makefile => Makefile +1 -1
@@ 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

M see.fnl => see.fnl +15 -4
@@ 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