(if(ormapexplicit-or-implicit-paragraph-break?elements); need this condition to prevent infinite recursion
;; use append-map on wrap-paragraph rather than map to permit return of multiple elements
(append-mapwrap-paragraph(append-map(λ(es)(filter-splitesparagraph-break?))(slicefelementsblock-txexpr?))); split into ¶¶, using both implied and explicit paragraph breaks
(append-mapwrap-paragraph(append-map(λ(es)(filter-splitesparagraph-break?))(slicefelementsblock-txexpr?))); split into ¶¶, using both implied and explicit paragraph breaks
(ifforce-paragraph
(append-mapwrap-paragraph(slicefelementsblock-txexpr?)); upconverts non-block elements to paragraphs
@ -64,7 +64,7 @@ This illustrates another important point: even though @racket[decode] presents a
(decode tx)
]
Right —nothing. That's because the default value for the decoding arguments is the identity function, @racket[(λ(x)x)]. So all the input gets passed through intact unless another action is specified.
Right —nothing. That's because the default value for the decoding arguments is the identity function, @racket[(λ(x)x)]. So all the input gets passed through intact unless another action is specified.
The @racket[_*-proc] arguments of @racket[decode] take procedures that are applied to specific categories of elements within @racket[_txexpr].
@ -73,7 +73,7 @@ The @racket[_txexpr-tag-proc] argument is a procedure that handles X-expression
@examples[#:eval my-eval
(define tx '(p "I'm from a strange" (strong "namespace")))
(code:comment @#,t{Tags are symbols, so a tag-proc should return a symbol})
The @racket[_txexpr-attrs-proc] argument is a procedure that handles lists of X-expression attributes. (The @racketmodname[txexpr] module, included at no extra charge with Pollen, includes useful helper functions for dealing with these attribute lists.)
@ -81,7 +81,7 @@ The @racket[_txexpr-attrs-proc] argument is a procedure that handles lists of X-
@examples[#:eval my-eval
(define tx '(p ((id "first")) "If I only had a brain."))
(code:comment @#,t{Attrs is a list, so cons is OK for simple cases})
Note that @racket[_txexpr-attrs-proc] will change the attributes of every tagged X-expression, even those that don't have attributes. This is useful, because sometimes you want to add attributes where none existed before. But be careful, because the behavior may make your processing function overinclusive.
@ -90,10 +90,10 @@ Note that @racket[_txexpr-attrs-proc] will change the attributes of every tagged
(define tx '(div (p ((id "first")) "If I only had a brain.")
(p "Me too.")))
(code:comment @#,t{This will insert the new attribute everywhere})
(code:comment @#,t{Every element gets doubled ...})
(decode tx #:txexpr-elements-proc (λ(es) (append-map (λ(e) (list e e)) es)))
(decode tx #:txexpr-elements-proc (λ(es) (append-map (λ(e) (list e e)) es)))
(code:comment @#,t{... but only strings get capitalized})
(decode tx #:txexpr-elements-proc (λ(es) (append-map (λ(e) (list e e)) es))
#:string-proc (λ(s) (string-upcase s)))
(decode tx #:txexpr-elements-proc (λ(es) (append-map (λ(e) (list e e)) es))
#:string-proc (λ(s) (string-upcase s)))
]
So why do you need @racket[_txexpr-elements-proc]? Because some types of element decoding depend on context, thus it's necessary to handle the elements as a group. For instance, paragraph decodeion. The behavior is not merely a @racket[map] across each element, because elements are being removed and altered contextually:
@ -125,7 +125,7 @@ The @racket[_txexpr-proc], @racket[_block-txexpr-proc], and @racket[_inline-txex
@examples[#:eval my-eval
(define tx '(div "Please" (em "mind the gap") (h1 "Tuesdays only")))
(define add-ns (λ(tx) (txexpr
(define add-ns (λ(tx) (txexpr
(string->symbol (format "ns:~a" (get-tag tx)))
(get-attrs tx)
(get-elements tx))))
@ -144,7 +144,7 @@ The @racket[_string-proc], @racket[_entity-proc], and @racket[_cdata-proc] argum
@examples[#:eval my-eval
(code:comment @#,t{A div with string, entity, and cdata elements})
#:linebreak-proc (λ(x) (decode-linebreaks x '(newline))))
#:linebreak-proc (λ(x) (decode-linebreaks x '(newline))))
]
The @racket[#:force?] option will wrap a paragraph tag around @racket[_elements], even if no explicit or implicit paragraph breaks are found. The @racket[#:force?] option is useful for when you want to guarantee that you always get a list of blocks.