diff --git a/scribble-doc/scribblings/scribble/core.scrbl b/scribble-doc/scribblings/scribble/core.scrbl index 44382638..fff95af0 100644 --- a/scribble-doc/scribblings/scribble/core.scrbl +++ b/scribble-doc/scribblings/scribble/core.scrbl @@ -2,6 +2,7 @@ @(require scribble/manual (except-in "utils.rkt" url) "struct-hierarchy.rkt" + (only-in scribble/eval as-examples) (for-label scribble/manual-struct racket/serialize file/convertible @@ -910,6 +911,9 @@ The following @tech{style properties} are currently recognized: @item{@racket[script-property] structure --- For HTML, supplies a script alternative to @racket[content].} + @item{@racket[xexpr-property] structure --- For HTML, supplies literal + HTML to render before and after @racket[content].} + @item{@racket[body-id] structure --- For HTML uses the given string as an @tt{id} attribute of the @tt{} tag.} @@ -931,7 +935,8 @@ The following @tech{style properties} are currently recognized: ] @history[#:changed "1.6" @elem{Changed @racket['exact-chars] handling to - take effect when the style name is @racket[#f].}]} + take effect when the style name is @racket[#f].} + #:changed "1.27" @elem{Changed to support @racket[xexpr-property].}]} @defstruct[(image-element element) ([path (or/c path-string? @@ -1746,6 +1751,30 @@ Used as a @tech{style property} with @racket[element] to supply a script alternative to the element content.} +@defstruct[xexpr-property ([before xexpr/c] + [after xexpr/c])]{ + +Used as a @tech{style property} with @racket[element] to supply literal +HTML that is rendered before and after element content. + +@as-examples["Example:" +@codeblock[#:keep-lang-line? #t]|{ + #lang scribble/base + @(require scribble/core + scribble/html-properties + (only-in xml cdata)) + + @(define comments (xexpr-property + (cdata #f #f "") + (cdata #f #f ""))) + + Here is some + @elem[#:style (style #f (list comments))]{content with comments around}. +}|] + +@history[#:added "1.27"]} + + @defstruct[css-addition ([path (or/c path-string? (cons/c 'collects (listof bytes?)) url? diff --git a/scribble-lib/info.rkt b/scribble-lib/info.rkt index 9e816460..c7ec9bf9 100644 --- a/scribble-lib/info.rkt +++ b/scribble-lib/info.rkt @@ -23,4 +23,4 @@ (define pkg-authors '(mflatt eli)) -(define version "1.26") +(define version "1.27") diff --git a/scribble-lib/scribble/html-properties.rkt b/scribble-lib/scribble/html-properties.rkt index 6ba51790..28802365 100644 --- a/scribble-lib/scribble/html-properties.rkt +++ b/scribble-lib/scribble/html-properties.rkt @@ -8,6 +8,7 @@ [body-id ([value string?])] [document-source ([module-path module-path?])] + [xexpr-property ([before xexpr/c] [after xexpr/c])] [hover-property ([text string?])] [script-property ([type string?] [script (or/c path-string? (listof string?))])] diff --git a/scribble-lib/scribble/html-render.rkt b/scribble-lib/scribble/html-render.rkt index 89e8517a..7ec0a174 100644 --- a/scribble-lib/scribble/html-render.rkt +++ b/scribble-lib/scribble/html-render.rkt @@ -1231,6 +1231,14 @@ (element-style->attribs (style-name s) s extras) (element-style->attribs s #f extras)))) + (define (element-style-property-matching e pred) + (and (or (element? e) (multiarg-element? e)) + (ormap (lambda (v) (and (pred v) v)) + (let ([s (if (element? e) + (element-style e) + (multiarg-element-style e))]) + (if (style? s) (style-properties s) null))))) + (define/override (render-content e part ri) (define (attribs [extras null]) (content-attribs e extras)) (cond @@ -1320,13 +1328,8 @@ ,@(if svg? `((param ([name "src"] [value ,srcref]))) null)))))] - [(and (or (element? e) (multiarg-element? e)) - (ormap (lambda (v) (and (script-property? v) v)) - (let ([s (if (element? e) - (element-style e) - (multiarg-element-style e))]) - (if (style? s) (style-properties s) null)))) - => + [(element-style-property-matching e script-property?) + => (lambda (v) (let* ([t `[type ,(script-property-type v)]] [s (script-property-script v)] @@ -1335,6 +1338,12 @@ `(script (,t ,@(attribs) [src ,s])))]) (list s `(noscript ,@(render-plain-content e part ri)))))] + [(element-style-property-matching e xexpr-property?) + => + (lambda (v) + (cons (xexpr-property-before v) + (append (render-plain-content e part ri) + (list (xexpr-property-after v)))))] [(target-element? e) `((a ([name ,(format "~a" (anchor-name (add-current-tag-prefix (tag-key (target-element-tag e)