5 Module Reference
5.1 Core
(require punct/core) | package: punct-lib |
parameter
(current-metas) → (or/c hash-eq? #f)
(current-metas metas) → void? metas : (or/c hash-eq? #f)
The only key automatically defined in every metadata table is 'here-path, which holds the absolute path to the source file.
If no Punct file is currently being compiled, this parameter will hold #f by default. In particular, this parameter is not automatically set to a Punct file’s metas during the rendering phase (e.g., doc->html).
procedure
key : symbol? val : (not/c procedure?)
syntax
(? key val-expr ...)
#lang punct •?[title "Example Title" author "Me"] ...
5.1.1 Elements
(require punct/element) | package: punct-lib |
The bindings provided by this module are also provided by punct/core.
procedure
(default-element-function tag default-attr-kw default-attr-val ...) → (->* () #:rest any/c xexpr?) tag : symbol? default-attr-kw : keyword? default-attr-val : string?
You can also give keyword/value arguments to default-element-function itself; these will be set as default attributes/values in the custom element returned by the resulting function.
> (define aside (default-element-function 'aside)) > (aside "Hello") '(aside "Hello")
> (define kbd (default-element-function 'kbd #:alt "foo")) > (kbd "CTRL") '(kbd ((alt "foo")) "CTRL")
> (kbd "CTRL" #:data-code "1") '(kbd ((alt "foo") (data-code "1")) "CTRL")
On Mac OS, type ALT+6 to produce § and ALT+7 to produce ¶.
If tag ends in either § or ¶, the resulting function will add a default block attribute of "root" or "single" respectively:
> (define info (default-element-function 'info§)) > (info "Note!") '(info ((block "root")) "Note!")
> (define mypar (default-element-function 'mypar¶)) > (mypar "Walnuts") '(mypar ((block "single")) "Walnuts")
If tag has a suffix of the form .foo, the resulting function will add a default 'class attribute whose value is set to "foo". Multiple such suffixes will add additional values to the 'class attribute.
> (define carton (default-element-function 'carton.xyz.abc)) > (carton "Cashews") '(carton ((class "xyz abc")) "Cashews")
> (define crate (default-element-function 'crate¶.foo)) > (crate "Pecans") '(crate ((block "single") (class "foo")) "Pecans")
Added in version 1.3 of package punct-lib.
syntax
(define-element id [default-attr-kw default-attr-val ...])
(define-element id tag [default-attr-kw default-attr-val ...])
default-attr-kw : keyword?
default-attr-val : string?
If tag is supplied, it is used as the tag for the X-expressions generated by the resulting function:
> (define-element bowl container.bowl) > (bowl "Corn nuts") '(container ((class "bowl")) "Corn nuts")
> (define-element jar vessel¶ #:type "Glass") > (jar "Chestnuts") '(vessel ((type "Glass") (block "single")) "Chestnuts")
If tag is not supplied, the first argument is used both as the identifier for the function and for the tag in generated X-expressions:
> (define-element bag.xyz.abc) > (bag "Sunflower seeds") '(ID "Sunflower seeds")
> (define-element packet¶.foo) > (packet "Raisins") '(ID "Raisins")
Added in version 1.3 of package punct-lib.
5.2 Fetch
(require punct/fetch) | package: punct-lib |
procedure
src : path-string?
procedure
doc : document? key : symbol?
default : failure-result/c = (lambda () (raise (make-exn:fail ....)))
Changed in version 1.1 of package punct-lib: Removed get-doc-ref and replaced with get-meta
5.3 Parse
(require punct/parse) | package: punct-lib |
procedure
(parse-markup-elements metas elements #:extract-inline? extract? #:parse-footnotes? parse-fn?) → (or/c document? (listof xexpr?)) metas : hash-eq? elements : list extract? : #t parse-fn? : #f
If #:extract-inline? is #true, and if the parsed document contains only a single paragraph element at the root level, then the elements inside the paragraph are returned as a list (the paragraph is “shucked”). Otherwise, the entire result is returned as a document.
The #:parse-footnotes? argument determines whether the commonmark parser will parse Markdown-style footnote references and definitions in elements.
> (define elems '("# Title\n\nA paragraph with *italic* text, and " 1 (custom "custom element"))) > (parse-markup-elements (hasheq) elems)
'#s(document
#hasheq()
((heading ((level "1")) "Title")
(paragraph
"A paragraph with "
(italic "italic")
" text, and 1"
(custom "custom element")))
())