Created
November 9, 2022 22:16
-
-
Save samdphillips/e7a7bcde83f8702e96ac9410a617f59a to your computer and use it in GitHub Desktop.
Scribble pre-processing for Commonmark
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang cmark-scribble | |
# This is a test document | |
1 + 1 is **@+[1 1]** |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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