Skip to content

Commit 20fcb61

Browse files
committed
Colorize Emacs Lisp code
1 parent 3afbe98 commit 20fcb61

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

www-lowdown-colorize.scm

+19-3
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,20 @@
5454
(result `(verbatim (info ,(string-trim-both info))
5555
(code ,@code-lines)))))))
5656

57+
(define (dashes->spaces string)
58+
(string-map (lambda (c) (if (char=? c #\-) #\space c)) string))
59+
60+
(define (spaces->dashes string)
61+
(string-map (lambda (c) (if (char=? c #\space) #\- c)) string))
62+
63+
(define (coloring-type-string->symbol string)
64+
(let ((string (dashes->spaces string)))
65+
(let loop ((names (coloring-type-names)))
66+
(and (not (null? names))
67+
(if (string-ci= string (cdar names))
68+
(caar names)
69+
(loop (cdr names)))))))
70+
5771
(define fenced-code-block-conversion-rules*
5872
`((verbatim
5973
. ,(lambda (_ contents)
@@ -63,11 +77,13 @@
6377
(code (alist-ref 'code contents))
6478
(code* (string-intersperse code ""))
6579
(raw-lang (car info))
66-
(lang-str (string-downcase raw-lang))
67-
(lang-sym (string->symbol lang-str)))
80+
(lang-sym (coloring-type-string->symbol raw-lang))
81+
(lang-dashed (spaces->dashes
82+
(string-downcase raw-lang))))
6883
(if (coloring-type-exists? lang-sym)
6984
`(pre (code (@ (class ,(string-append
70-
"colorize language-" lang-str)))
85+
"colorize"
86+
" language-" lang-dashed)))
7187
,@(->> code*
7288
(html-colorize lang-sym)
7389
(html->sxml)

0 commit comments

Comments
 (0)