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
This commit is contained in:
Greg Hendershott 2012-12-18 18:23:08 -05:00 committed by Matthew Flatt
parent 042f013e13
commit 624b8ef7e4
3 changed files with 21 additions and 2 deletions

View File

@ -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

View File

@ -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. Lets make it long enough that the markdown output
> will have to line-wrap, to make sure the > mark starts each line
> properly.

View File

@ -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.}