|
|
@ -1,6 +1,6 @@
|
|
|
|
#lang racket/base
|
|
|
|
#lang racket/base
|
|
|
|
(require xml txexpr sugar/define)
|
|
|
|
(require xml txexpr sugar/define)
|
|
|
|
(require "predicates.rkt" "decode/typography.rkt" "debug.rkt")
|
|
|
|
(require "decode/block.rkt" "decode/typography.rkt" "debug.rkt")
|
|
|
|
|
|
|
|
|
|
|
|
(provide (all-from-out "decode/typography.rkt"))
|
|
|
|
(provide (all-from-out "decode/typography.rkt"))
|
|
|
|
|
|
|
|
|
|
|
@ -17,56 +17,59 @@
|
|
|
|
[(char? x) (format "~a" x)]
|
|
|
|
[(char? x) (format "~a" x)]
|
|
|
|
[else (error)])))) ; put this last so other xexprish things don't get caught
|
|
|
|
[else (error)])))) ; put this last so other xexprish things don't get caught
|
|
|
|
|
|
|
|
|
|
|
|
;; add a block tag to the list
|
|
|
|
|
|
|
|
(define+provide/contract (register-block-tag tag)
|
|
|
|
|
|
|
|
(symbol? . -> . void?)
|
|
|
|
|
|
|
|
(append-block-tag tag))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; decoder wireframe
|
|
|
|
;; decoder wireframe
|
|
|
|
(define+provide/contract (decode txexpr
|
|
|
|
(define+provide/contract (decode txexpr
|
|
|
|
#:exclude-xexpr-tags [excluded-xexpr-tags '()]
|
|
|
|
#:txexpr-tag-proc [txexpr-tag-proc (λ(x)x)]
|
|
|
|
#:xexpr-tag-proc [xexpr-tag-proc (λ(x)x)]
|
|
|
|
#:txexpr-attrs-proc [txexpr-attrs-proc (λ(x)x)]
|
|
|
|
#:xexpr-attrs-proc [xexpr-attrs-proc (λ(x)x)]
|
|
|
|
#:txexpr-elements-proc [txexpr-elements-proc (λ(x)x)]
|
|
|
|
#:xexpr-elements-proc [xexpr-elements-proc (λ(x)x)]
|
|
|
|
#:block-txexpr-proc [block-txexpr-proc (λ(x)x)]
|
|
|
|
#:block-xexpr-proc [block-xexpr-proc (λ(x)x)]
|
|
|
|
#:inline-txexpr-proc [inline-txexpr-proc (λ(x)x)]
|
|
|
|
#:inline-xexpr-proc [inline-xexpr-proc (λ(x)x)]
|
|
|
|
|
|
|
|
#:string-proc [string-proc (λ(x)x)]
|
|
|
|
#:string-proc [string-proc (λ(x)x)]
|
|
|
|
#:symbol-proc [symbol-proc (λ(x)x)]
|
|
|
|
#:symbol-proc [symbol-proc (λ(x)x)]
|
|
|
|
#:valid-char-proc [valid-char-proc (λ(x)x)]
|
|
|
|
#:valid-char-proc [valid-char-proc (λ(x)x)]
|
|
|
|
#:cdata-proc [cdata-proc (λ(x)x)])
|
|
|
|
#:cdata-proc [cdata-proc (λ(x)x)]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#:exclude-tags [excluded-tags '()])
|
|
|
|
((xexpr/c)
|
|
|
|
((xexpr/c)
|
|
|
|
(#:exclude-xexpr-tags list?
|
|
|
|
(#:txexpr-tag-proc (txexpr-tag? . -> . txexpr-tag?)
|
|
|
|
#:xexpr-tag-proc procedure?
|
|
|
|
#:txexpr-attrs-proc (txexpr-attrs? . -> . txexpr-attrs?)
|
|
|
|
#:xexpr-attrs-proc procedure?
|
|
|
|
#:txexpr-elements-proc (txexpr-elements? . -> . txexpr-elements?)
|
|
|
|
#:xexpr-elements-proc procedure?
|
|
|
|
#:block-txexpr-proc (block-txexpr? . -> . block-txexpr?)
|
|
|
|
#:block-xexpr-proc procedure?
|
|
|
|
#:inline-txexpr-proc (txexpr? . -> . txexpr?)
|
|
|
|
#:inline-xexpr-proc procedure?
|
|
|
|
#:string-proc (string? . -> . string?)
|
|
|
|
#:string-proc procedure?
|
|
|
|
#:symbol-proc (symbol? . -> . symbol?)
|
|
|
|
#:symbol-proc procedure?
|
|
|
|
#:valid-char-proc (valid-char? . -> . valid-char?)
|
|
|
|
#:valid-char-proc procedure?
|
|
|
|
#:cdata-proc (cdata? . -> . cdata?)
|
|
|
|
#:cdata-proc procedure?) . ->* . txexpr?)
|
|
|
|
#:exclude-tags (listof symbol?) ) . ->* . txexpr?)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(let loop ([x txexpr])
|
|
|
|
(let loop ([x txexpr])
|
|
|
|
(cond
|
|
|
|
(cond
|
|
|
|
[(txexpr? x) (let-values([(tag attrs elements) (txexpr->values x)])
|
|
|
|
[(txexpr? x) (let-values([(tag attrs elements) (txexpr->values x)])
|
|
|
|
(if (member tag excluded-xexpr-tags)
|
|
|
|
(if (member tag excluded-tags)
|
|
|
|
x ; because it's excluded
|
|
|
|
x ; because it's excluded
|
|
|
|
|
|
|
|
|
|
|
|
;; we apply processing here rather than do recursive descent on the pieces
|
|
|
|
;; we apply processing here rather than do recursive descent on the pieces
|
|
|
|
;; because if we send them back through loop, certain element types are ambiguous
|
|
|
|
;; because if we send them back through loop, certain element types are ambiguous
|
|
|
|
;; e.g., ((p "foo")) tests out as both txexpr-attrs and txexpr-elements
|
|
|
|
;; e.g., ((p "foo")) tests out as both txexpr-attrs and txexpr-elements
|
|
|
|
(let ([decoded-xexpr
|
|
|
|
(let ([decoded-txexpr
|
|
|
|
(apply make-txexpr (list (xexpr-tag-proc tag)
|
|
|
|
(apply make-txexpr (list (txexpr-tag-proc tag)
|
|
|
|
(xexpr-attrs-proc attrs)
|
|
|
|
(txexpr-attrs-proc attrs)
|
|
|
|
(map loop (xexpr-elements-proc elements))))])
|
|
|
|
(map loop (txexpr-elements-proc elements))))])
|
|
|
|
((if (block-xexpr? decoded-xexpr)
|
|
|
|
((if (block-txexpr? decoded-txexpr)
|
|
|
|
block-xexpr-proc
|
|
|
|
block-txexpr-proc
|
|
|
|
inline-xexpr-proc) decoded-xexpr))))]
|
|
|
|
inline-txexpr-proc) decoded-txexpr))))]
|
|
|
|
[(string? x) (string-proc x)]
|
|
|
|
[(string? x) (string-proc x)]
|
|
|
|
[(symbol? x) (symbol-proc x)]
|
|
|
|
[(symbol? x) (symbol-proc x)]
|
|
|
|
[(valid-char? x) (valid-char-proc x)]
|
|
|
|
[(valid-char? x) (valid-char-proc x)]
|
|
|
|
[(cdata? x) (cdata-proc x)]
|
|
|
|
[(cdata? x) (cdata-proc x)]
|
|
|
|
[else (error "decode: can't decode" x)])))
|
|
|
|
[else (error "decode: can't decode" x)])))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|