Skip to content

Instantly share code, notes, and snippets.

@samdphillips
Created November 9, 2022 22:16
Show Gist options
  • Save samdphillips/e7a7bcde83f8702e96ac9410a617f59a to your computer and use it in GitHub Desktop.
Save samdphillips/e7a7bcde83f8702e96ac9410a617f59a to your computer and use it in GitHub Desktop.
Scribble pre-processing for Commonmark
#lang cmark-scribble
# This is a test document
1 + 1 is **@+[1 1]**
#lang racket/base
;; This needs to be in a package/collection called "cmark-scribble" to work the example.
(require (for-syntax racket/base)
commonmark/parse
commonmark/render/html
racket/format
syntax/parse/define)
(provide (except-out (all-from-out racket/base) #%module-begin)
(rename-out [mb #%module-begin])
render-html)
(module reader syntax/module-reader
cmark-scribble
#:read read-inside
#:read-syntax read-syntax-inside
#:whole-body-readers? #t
(require scribble/reader))
(define-syntax-parse-rule (mb rest ...)
(#%module-begin
(define doc (string-append (~a rest) ...))
(provide doc)
(module* render #f
(render-html doc))))
(define (render-html s)
(write-document-html (string->document s)))
$ raco run example-doc.rkt render
<h1>This is a test document</h1><p>1 + 1 is <strong>2</strong></p>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment