summaryrefslogtreecommitdiff
path: root/highlight.scm
diff options
context:
space:
mode:
Diffstat (limited to 'highlight.scm')
-rw-r--r--highlight.scm31
1 files changed, 31 insertions, 0 deletions
diff --git a/highlight.scm b/highlight.scm
new file mode 100644
index 0000000..51f2b02
--- /dev/null
+++ b/highlight.scm
@@ -0,0 +1,31 @@
+(define-module (highlight)
+ #:use-module (ice-9 match)
+ #:use-module (sxml match)
+ #:use-module (syntax-highlight)
+ #:use-module (syntax-highlight scheme)
+ #:use-module (syntax-highlight xml)
+ #:use-module (syntax-highlight c)
+ #:export (highlight-code
+ highlight-scheme))
+
+(define (maybe-highlight-code lang source)
+ (let ((lexer (match lang
+ ('scheme lex-scheme)
+ ('xml lex-xml)
+ ('c lex-c)
+ (_ #f))))
+ (if lexer
+ (highlights->sxml (highlight lexer source))
+ source)))
+
+(define (highlight-code . tree)
+ (sxml-match tree
+ ((code (@ (class ,class) . ,attrs) ,source)
+ (let ((lang (string->symbol
+ (string-drop class (string-length "language-")))))
+ `(code (@ ,@attrs)
+ ,(maybe-highlight-code lang source))))
+ (,other other)))
+
+(define (highlight-scheme code)
+ `(pre (code ,(highlights->sxml (highlight lex-scheme code)))))