Make @emph nestable, logical markup

This commit is contained in:
Reuben Thomas 2019-11-11 13:44:07 +00:00 committed by Matthew Flatt
parent 8168a22492
commit 9b1f9bc1d2
6 changed files with 35 additions and 3 deletions

View File

@ -467,7 +467,9 @@ gets progressively smaller.}
gets progressively larger.}
@defproc[(emph [pre-content pre-content?] ...) element?]{
The same as @racket[italic].}
Like @racket[elem], but emphasised. Typically, italics are used for
emphasis. Uses of @racket[emph] can be nested; typically this causes
the text to alternate between italic and upright.}
@defproc[(literal [str string?] ...+) element?]{

View File

@ -258,7 +258,7 @@
(make-element 'larger (decode-content str)))
(define (emph . str)
(make-element 'italic (decode-content str)))
(make-element 'emph (decode-content str)))
(define (tt . str)
(let* ([l (decode-content str)]

View File

@ -1607,6 +1607,7 @@
(cond
[(symbol? name)
(case name
[(emph) '([class "emph"])]
[(italic) '([style "font-style: italic"])]
[(bold) '([style "font-weight: bold"])]
[(tt) '([class "stt"])]

View File

@ -471,6 +471,7 @@
(cond
[(symbol? style-name)
(case style-name
[(emph) (wrap e "emph" tt?)]
[(italic) (wrap e "textit" tt?)]
[(bold) (wrap e "textbf" tt?)]
[(tt) (wrap e "Scribtexttt" #t)]

View File

@ -216,6 +216,9 @@
(define (italic? i)
(and (element? i) (eq? (element-style i) 'italic)))
(define (emph? i)
(and (element? i) (eq? (element-style i) 'emph)))
(define (code? i)
(and (element? i)
(let ([s (element-style i)])
@ -259,6 +262,12 @@
[(and (italic? i) (not (in-italic?)) (not (in-code?)))
(recurse-wrapped "_" in-italic?)]
[(and (emph? i) (not (in-code?)))
(display "_") ;; zero-width space, underscore
(begin0
(super render-content i part ri)
(display "_"))] ;; underscore, zero-width space
[(and (preserve-spaces? i) (not (preserving-spaces?)))
(parameterize ([preserving-spaces? #t])
(render-content i part ri))]
@ -378,4 +387,3 @@
([ptn (map car ptns&reps)]
[rep (map cdr ptns&reps)])
(regexp-replace* ptn str rep)))

View File

@ -30,6 +30,26 @@
font-weight: bold;
}
/* Emphasis: alternate italics and normal as we nest */
.emph {
font-style: italic;
}
.emph .emph {
font-style: normal;
}
.emph .emph .emph {
font-style: italic;
}
.emph .emph .emph .emph {
font-style: normal;
}
.emph .emph .emph .emph .emph {
font-style: italic;
}
.emph .emph .emph .emph .emph .emph {
font-style: normal;
}
/* ---------------------------------------- */
p, .SIntrapara {