bkyk8rc3zvpnsf5inmcqq4n3k98cv6hj-my-site-hyper-literate-git.test.suzanne.soy-0.0.1

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 624b8ef7e44f62b251224bb3745eb03146a35b07
parent 042f013e13a9f365f6fe1ee42601c3d7b0f0f511
Author: Greg Hendershott <greghendershott@gmail.com>
Date:   Tue, 18 Dec 2012 18:23:08 -0500

Render Scribble margin-note as Markdown block-quote.

More precisely, do this for nested flows with the "refcontent" style.

For instance this Scribble:

    @margin-note{Note: This is a note. Let's make it long enough that the
    markdown output will have to line-wrap, to make sure the > mark starts
    each line properly.}

Will render as this Markdown:

    > Note: This is a note. Let's make it long enough that the markdown output
    > will have to line-wrap, to make sure the > mark starts each line
    > properly.

A site like GitHub.com will render this in a block-quote style
suitable for notes:

> Note: This is a note. Let's make it long enough that the markdown output
> will have to line-wrap, to make sure the > mark starts each line
> properly.

original commit: a3800cdc94d5f0c1b361d6e3ead6c1ebceb66288

Diffstat:
Mcollects/scribble/markdown-render.rkt | 15+++++++++++++--
Mcollects/tests/scribble/markdown-docs/example.md | 4++++
Mcollects/tests/scribble/markdown-docs/example.scrbl | 4++++
3 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/collects/scribble/markdown-render.rkt b/collects/scribble/markdown-render.rkt @@ -18,6 +18,7 @@ (define table-ticks-depth (make-parameter 0)) (define phrase-ticks-depth (make-parameter 0)) +(define note-depth (make-parameter 0)) (define (render-mixin %) (class % @@ -140,14 +141,19 @@ (render-flow d part ht #f))))))) (define/override (render-paragraph p part ri) + (define (write-note) + (write-string (make-string (note-depth) #\>)) + (unless (zero? (note-depth)) + (write-string " "))) (define o (open-output-string)) (parameterize ([current-output-port o]) (super render-paragraph p part ri)) (define to-wrap (regexp-replace* #rx"\n" (get-output-string o) " ")) (define lines (wrap-line (string-trim to-wrap) (- 72 (current-indent)))) + (write-note) (write-string (car lines)) (for ([line (in-list (cdr lines))]) - (newline) (indent) (write-string line)) + (newline) (indent) (write-note) (write-string line)) (newline) null) @@ -207,7 +213,12 @@ (define/override (render-nested-flow i part ri starting-item?) (define s (nested-flow-style i)) (unless (memq 'decorative (style-properties s)) - (super render-nested-flow i part ri starting-item?))) + (define note? (equal? (style-name s) "refcontent")) + (when note? + (note-depth (add1 (note-depth)))) + (begin0 (super render-nested-flow i part ri starting-item?) + (when note? + (note-depth (sub1 (note-depth))))))) (define/override (render-other i part ht) (cond diff --git a/collects/tests/scribble/markdown-docs/example.md b/collects/tests/scribble/markdown-docs/example.md @@ -43,3 +43,7 @@ The end. Returns a new mutable string of length `k` where each position in the string is initialized with the character `char` + +> Note: This is a note. Let’s make it long enough that the markdown output +> will have to line-wrap, to make sure the > mark starts each line +> properly. diff --git a/collects/tests/scribble/markdown-docs/example.scrbl b/collects/tests/scribble/markdown-docs/example.scrbl @@ -52,3 +52,7 @@ Returns a new mutable string of length @racket[k] where each position in the string is initialized with the character @racket[char] } + +@margin-note{Note: This is a note. Let's make it long enough that the +markdown output will have to line-wrap, to make sure the > mark starts +each line properly.}