@@ -6,16 +6,43 @@ ;; Pollen “tag functions” that return elements of a Yarn AST. This AST can be ;; rendered into HTML or other formats (using, e.g., the yarn/render/html module). (require pollen/decode pollen/tag + racket/string + txexpr "index.rkt" "string.rkt" - "tools.rkt") + "tools.rkt" + yarn/path) (provide (all-defined-out)) +(define (root . elems) + (print (validate-txexpr `(test ,@elems))) + (check-title elems) + (serialize-article-placeholder) + `(document ,@(decode-hardwrapped-paragraphs elems))) + +;; Customized paragraph decoder replaces single newlines within paragraphs +;; with single spaces instead of
tags (allow hard-wrapped paragraphs) +(define (decode-hardwrapped-paragraphs xs) + (define (no-linebreaks xs) + (decode-linebreaks xs " ")) + (decode-paragraphs xs 'paragraph #:linebreak-proc no-linebreaks)) + +;; Set a title if not already set +(define (check-title elems) + (cond + [(and (not (meta-set? 'title)) + (pair? elems) + ((tx-is? 'poetry #:has-attrs 'title) (car elems))) + (set-meta 'title (format "‘~a’" (attr-ref (car elems) 'title))) + (set-meta 'title-supplied? #t)] + [(not (meta-set? 'title)) + (set-meta 'title (if (pair? elems) (first-words elems 5) ""))])) + ;; Yarn AST: ;; (document Block-Contents) ;; Footnote definitions, index entry keys are stored in the metas ;; Block-Content := @@ -108,5 +135,18 @@ (define (saylines interlocutor elems) `(speech ,interlocutor ,@(decode-linebreaks elems 'line-break))) (define verse (default-tag-function 'poetry)) ; #:title, #:style +(define-tag-function (note attrs elems) + (let* ([note-count (update-meta 'note-count add1 0)] + [note-id (string-append (attr-ref attrs 'date) (format "_~a" note-count))] + [maybe-disp (string-split (attr-ref attrs 'disposition ""))] + [the-note (attr-set* `(note ,attrs ,@elems) 'id note-id 'parent (here-output-path))]) + (cond + [(> (length maybe-disp) 1) + (set-meta 'disposition `(,(car maybe-disp) + ,(string-join (cdr maybe-disp)) + ,note-id))]) + (cons-to-metas-list 'notes the-note) + (serialize-note the-note note-count) + ""))