As a continuation to this StackOverflow question, I now want to hilight Idris2 code using Scribble. I like Scribble for the styling and the programmability in general, but the code of my documentation is not Scheme/Racket.
So I've modified Katla, which is a Idris code formatter, to output Scribble code with Racket syntax. But my issue is that I think the code is really weird, and I had to do a bunch of hacks.
My generated code looks like this. First, a preamble where I map some Idris syntactic concepts to some racket colors. These mappings make no sense, I have based it on whether the colors looked nice.
#lang racket
(require scribble/decode scribble/core scribble/manual "katla.scr")
(define IdrisData racketidfont)
(define IdrisType racketresultfont)
(define IdrisBound racketparenfont)
(define IdrisFunction racketkeywordfont)
(define IdrisKeyword racketoutput)
Then, named generated code snippets are emitted:
(provide 8main)
(define 8main
(let [(lines (list
(list IdrisKeyword "partial") 'nl
(list IdrisFunction "main") " " (list IdrisKeyword ":") " " (list IdrisType "IO") " " (list IdrisType "Unit") 'nl
(list IdrisFunction "main") " " (list IdrisKeyword "=") " " (list IdrisFunction "H2.runHttp2WithPostgres") " " (list IdrisFunction "okReplyAndBody2") 'nl
))]
(if (empty? lines)
(error "code block is empty")
(make-nested-flow (make-style 'code-inset '(box-mode))
(decode-flow (list (apply verbatim (append-map wp lines))))
)
)))
which is the highlighted version of
partial
main : IO Unit
main = H2.runHttp2WithPostgres okReplyAndBody2
That function can then be used in a regular Scribble document.
My issue is that all this make-nested-flow
and decode-flow
stuff is derived my trial-and-error, and I don't understand it at all. Isn't there a nicer way to tell Scribble to just include some monospaced code that I have hilighted myself? I understand that Scribble is designed first and foremost for Scheme, but I thought it would make sense if there is a lower-level API I could use. What I am currently doing technically works, but I haven't shown the worst part, which is moving around white space because it seems that Scribble doesn't like highlighted white space.