Skip to content

Commit 1983e59

Browse files
committed
Document the raw block input hack
1 parent 6029fe7 commit 1983e59

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

docs/index.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,67 @@ or pass `-MrangeDelim=' - '` to pandoc on command line.
7878

7979
You can use other html entites of course, like ` ` etc.
8080

81+
## Using raw blocks to define elements
82+
83+
It may be useful/convenient to define some elements as raw blocks, as Pandoc
84+
Markdown, while very powerful, doesn't support everything Pandoc can support
85+
internally (e.g. colspan/rowspan in tables).
86+
87+
Pandoc-crossref relies on Pandoc's AST representation, thus simply using [raw
88+
blocks](https://pandoc.org/MANUAL.html#extension-raw_attribute) won't work.
89+
90+
However, it's feasible if Pandoc can actually parse the contents of the raw
91+
block with a little helper Lua filter. For example, something like this:
92+
93+
```lua
94+
function Div(div)
95+
local id = div.attr.identifier
96+
if (id:match "^tbl:" or id:match "^fig:") and div.content[2].t == "RawBlock"
97+
then
98+
local raw = div.content[2]
99+
local elem = pandoc.read(raw.text, raw.format).blocks
100+
elem[1].caption = pandoc.Caption(div.content[1])
101+
elem[1].attr = div.attr
102+
return elem
103+
end
104+
end
105+
```
106+
107+
applied before pandoc-crossref, will reparse table definitions like this:
108+
109+
``````markdown
110+
:::{#tbl:foo}
111+
Caption
112+
113+
```{=html}
114+
<table>
115+
<tr><th>Foo</th><th>Bar</th></tr>
116+
<tr><td rowspan=2>1</td><td>Quux</td></tr>
117+
<tr><td>Baz</td></tr>
118+
</table>
119+
```
120+
:::
121+
``````
122+
123+
This also will work for figures, e.g.:
124+
125+
126+
``````markdown
127+
:::{#fig:foo}
128+
Caption
129+
130+
```{=html}
131+
<figure>
132+
<p>This is just a paragraph instead of an image in a figure, nothing to see
133+
here</p>
134+
</figure>
135+
```
136+
:::
137+
``````
138+
139+
Bear in mind that if Pandoc fails to parse the raw block, pandoc-crossref will
140+
fail to interpret it.
141+
81142
# Syntax
82143

83144
Syntax is loosely based on discussion in

0 commit comments

Comments
 (0)