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:
parent
042f013e13
commit
624b8ef7e4
|
@ -18,6 +18,7 @@
|
||||||
|
|
||||||
(define table-ticks-depth (make-parameter 0))
|
(define table-ticks-depth (make-parameter 0))
|
||||||
(define phrase-ticks-depth (make-parameter 0))
|
(define phrase-ticks-depth (make-parameter 0))
|
||||||
|
(define note-depth (make-parameter 0))
|
||||||
|
|
||||||
(define (render-mixin %)
|
(define (render-mixin %)
|
||||||
(class %
|
(class %
|
||||||
|
@ -140,14 +141,19 @@
|
||||||
(render-flow d part ht #f)))))))
|
(render-flow d part ht #f)))))))
|
||||||
|
|
||||||
(define/override (render-paragraph p part ri)
|
(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))
|
(define o (open-output-string))
|
||||||
(parameterize ([current-output-port o])
|
(parameterize ([current-output-port o])
|
||||||
(super render-paragraph p part ri))
|
(super render-paragraph p part ri))
|
||||||
(define to-wrap (regexp-replace* #rx"\n" (get-output-string o) " "))
|
(define to-wrap (regexp-replace* #rx"\n" (get-output-string o) " "))
|
||||||
(define lines (wrap-line (string-trim to-wrap) (- 72 (current-indent))))
|
(define lines (wrap-line (string-trim to-wrap) (- 72 (current-indent))))
|
||||||
|
(write-note)
|
||||||
(write-string (car lines))
|
(write-string (car lines))
|
||||||
(for ([line (in-list (cdr lines))])
|
(for ([line (in-list (cdr lines))])
|
||||||
(newline) (indent) (write-string line))
|
(newline) (indent) (write-note) (write-string line))
|
||||||
(newline)
|
(newline)
|
||||||
null)
|
null)
|
||||||
|
|
||||||
|
@ -207,7 +213,12 @@
|
||||||
(define/override (render-nested-flow i part ri starting-item?)
|
(define/override (render-nested-flow i part ri starting-item?)
|
||||||
(define s (nested-flow-style i))
|
(define s (nested-flow-style i))
|
||||||
(unless (memq 'decorative (style-properties s))
|
(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)
|
(define/override (render-other i part ht)
|
||||||
(cond
|
(cond
|
||||||
|
|
|
@ -43,3 +43,7 @@ The end.
|
||||||
|
|
||||||
Returns a new mutable string of length `k` where each position in the
|
Returns a new mutable string of length `k` where each position in the
|
||||||
string is initialized with the character `char`
|
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.
|
||||||
|
|
|
@ -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]
|
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.}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user