size: 4 KiB
| 1 | .\" Automatically generated by Pandoc 2.19.2 |
| 2 | .\" |
| 3 | .\" Define V font for inline verbatim, using C font in formats |
| 4 | .\" that render this, and otherwise B font. |
| 5 | .ie "\f[CB]x\f[]"x" \{\ |
| 6 | . ftr V B |
| 7 | . ftr VI BI |
| 8 | . ftr VB B |
| 9 | . ftr VBI BI |
| 10 | .\} |
| 11 | .el \{\ |
| 12 | . ftr V CR |
| 13 | . ftr VI CI |
| 14 | . ftr VB CB |
| 15 | . ftr VBI CBI |
| 16 | .\} |
| 17 | .TH "DJOT" "1" "" "djot 0.2.1" "" |
| 18 | .hy |
| 19 | .SH NAME |
| 20 | .PP |
| 21 | djot \[en] converts djot markup. |
| 22 | .SH SYNOPSIS |
| 23 | .PP |
| 24 | djot options [file..] |
| 25 | .SH DESCRIPTION |
| 26 | .PP |
| 27 | djot is a command-line parser for djot markup (https://djot.net). |
| 28 | It can produce |
| 29 | .IP \[bu] 2 |
| 30 | an HMTL document (default behavior) |
| 31 | .IP \[bu] 2 |
| 32 | a stream of annotated tokens with byte offsets (\f[V]--matches\f[R]) |
| 33 | .IP \[bu] 2 |
| 34 | an AST in either human-readable or JSON form (\f[V]--ast\f[R]). |
| 35 | .SH OPTIONS |
| 36 | .TP |
| 37 | \f[V]--matches, -m\f[R] |
| 38 | Show matches (annotated tokens with source positions). |
| 39 | .TP |
| 40 | \f[V]--ast\f[R], \f[V]-a\f[R] |
| 41 | Produce and render an abstract syntax tree. |
| 42 | .TP |
| 43 | \f[V]--json\f[R], \f[V]-j\f[R] |
| 44 | Use machine-readable JSON format when used with \f[V]--matches\f[R] or |
| 45 | \f[V]--ast\f[R]. |
| 46 | .TP |
| 47 | \f[V]--sourcepos\f[R], \f[V]-p\f[R] |
| 48 | Include source positions in the AST or HTML document. |
| 49 | .TP |
| 50 | \f[V]--filter\f[R] \f[I]FILE\f[R], \f[V]-f\f[R] \f[I]FILE\f[R] |
| 51 | Run the filter defined in \f[I]FILE\f[R] on the AST between parsing and |
| 52 | rendering. |
| 53 | The \f[V]--filter\f[R] option may be used multiple times; filters will |
| 54 | be applied in the order specified on the command line. |
| 55 | See FILTERS below for a description of filters. |
| 56 | .TP |
| 57 | \f[V]--verbose\f[R], \f[V]-v\f[R] |
| 58 | Verbose output, including warnings. |
| 59 | .TP |
| 60 | \f[V]--version\f[R] |
| 61 | Print the djot version. |
| 62 | .TP |
| 63 | \f[V]--help\f[R], \f[V]-h\f[R] |
| 64 | Print usage information. |
| 65 | .SH FILTERS |
| 66 | .PP |
| 67 | Filters are small Lua programs that modify the parsed document prior to |
| 68 | rendering. |
| 69 | Here is an example of a filter that capitalizes all the content text in |
| 70 | a document: |
| 71 | .IP |
| 72 | .nf |
| 73 | \f[C] |
| 74 | return { |
| 75 | str = function(e) |
| 76 | e.text = e.text:upper() |
| 77 | end |
| 78 | } |
| 79 | \f[R] |
| 80 | .fi |
| 81 | .PP |
| 82 | Save this as \f[V]caps.lua\f[R] use tell djot to use it using |
| 83 | .IP |
| 84 | .nf |
| 85 | \f[C] |
| 86 | djot --filter caps input.djot |
| 87 | \f[R] |
| 88 | .fi |
| 89 | .PP |
| 90 | Note that djot will search your LUA_PATH for the filter if it is not |
| 91 | found in the working directory, so you can in principle install filters |
| 92 | using luarocks. |
| 93 | .PP |
| 94 | Here\[cq]s a filter that prints a list of all the URLs you link to in a |
| 95 | document. |
| 96 | This filter doesn\[cq]t alter the document at all; it just prints the |
| 97 | list to stderr. |
| 98 | .IP |
| 99 | .nf |
| 100 | \f[C] |
| 101 | return { |
| 102 | link = function(el) |
| 103 | io.stderr:write(el.destination .. \[dq]\[rs]n\[dq]) |
| 104 | end |
| 105 | } |
| 106 | \f[R] |
| 107 | .fi |
| 108 | .PP |
| 109 | A filter walks the document\[cq]s abstract syntax tree, applying |
| 110 | functions to like-tagged nodes, so you will want to get familiar with |
| 111 | how djot\[cq]s AST is designed. |
| 112 | The easiest way to do this is to use \f[V]djot --ast\f[R]. |
| 113 | .PP |
| 114 | By default filters do a bottom-up traversal; that is, the filter for a |
| 115 | node is run after its children have been processed. |
| 116 | It is possible to do a top-down travel, though, and even to run separate |
| 117 | actions on entering a node (before processing the children) and on |
| 118 | exiting (after processing the children). |
| 119 | To do this, associate the node\[cq]s tag with a table containing |
| 120 | \f[V]enter\f[R] and/or \f[V]exit\f[R] functions. |
| 121 | The following filter will capitalize text that is nested inside |
| 122 | emphasis, but not other text: |
| 123 | .IP |
| 124 | .nf |
| 125 | \f[C] |
| 126 | local capitalize = 0 |
| 127 | return { |
| 128 | emph = { |
| 129 | enter = function(e) |
| 130 | capitalize = capitalize + 1 |
| 131 | end, |
| 132 | exit = function(e) |
| 133 | capitalize = capitalize - 1 |
| 134 | end, |
| 135 | }, |
| 136 | str = function(e) |
| 137 | if capitalize > 0 then |
| 138 | e.text = e.text:upper() |
| 139 | end |
| 140 | end |
| 141 | } |
| 142 | \f[R] |
| 143 | .fi |
| 144 | .PP |
| 145 | For a top-down traversal, you\[cq]d just use the \f[V]enter\f[R] |
| 146 | functions. |
| 147 | If the tag is associated directly with a function, as in the first |
| 148 | example above, it is treated as an \[ga]exit\[cq] function. |
| 149 | .PP |
| 150 | It is possible to inhibit traversal into the children of a node, by |
| 151 | having the \f[V]enter\f[R] function return the value true (or any truish |
| 152 | value, say \f[V]\[dq]stop\[dq]\f[R]). |
| 153 | This can be used, for example, to prevent the contents of a footnote |
| 154 | from being processed: |
| 155 | .IP |
| 156 | .nf |
| 157 | \f[C] |
| 158 | return { |
| 159 | footnote = { |
| 160 | enter = function(e) |
| 161 | return true |
| 162 | end |
| 163 | } |
| 164 | } |
| 165 | \f[R] |
| 166 | .fi |
| 167 | .PP |
| 168 | A single filter may return a table with multiple tables, which will be |
| 169 | applied sequentially. |
| 170 | .SH AUTHORS |
| 171 | .PP |
| 172 | John MacFarlane (<jgm@berkeley.edu>). |