@markup-carve/pandoc-carve 0.1.4 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +71 -325
- package/dist/ast-json.js +37 -0
- package/dist/cli.js +125 -12
- package/dist/convert.d.ts +6 -1
- package/dist/convert.js +135 -34
- package/dist/diagnostics.d.ts +13 -1
- package/dist/diagnostics.js +71 -46
- package/dist/includes.d.ts +14 -0
- package/dist/includes.js +35 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +158 -4
- package/dist/pandoc.d.ts +1 -1
- package/dist/pandoc.js +3 -3
- package/dist/reverse.js +148 -62
- package/dist/row-groups.d.ts +2 -0
- package/dist/row-groups.js +25 -1
- package/package.json +9 -3
package/README.md
CHANGED
|
@@ -1,23 +1,17 @@
|
|
|
1
1
|
# pandoc-carve
|
|
2
2
|
|
|
3
|
-
Bidirectional [Carve](https://github.com/markup-carve/carve)
|
|
3
|
+
Bidirectional [Carve](https://github.com/markup-carve/carve) and Pandoc bridge.
|
|
4
|
+
It exports Carve through Pandoc's writers and imports any format handled by a
|
|
5
|
+
Pandoc reader.
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
Org, MediaWiki, HTML, Markdown, ...) into Carve source.
|
|
9
|
-
|
|
10
|
-
```
|
|
11
|
-
.crv ──parse──▶ Carve AST ──carveToPandoc()──▶ Pandoc JSON ──pandoc -f json -t X──▶ .tex / .typ / .docx / …
|
|
12
|
-
.docx / .tex / … ──pandoc -t json──▶ Pandoc JSON ──pandocToCarve()──▶ Carve AST ──renderCarve──▶ .crv
|
|
7
|
+
```text
|
|
8
|
+
.crv -> Carve AST -> Pandoc JSON -> LaTeX, Typst, DOCX, PDF, EPUB, ...
|
|
9
|
+
DOCX, LaTeX, RST, ... -> Pandoc JSON -> Carve AST -> .crv
|
|
13
10
|
```
|
|
14
11
|
|
|
15
|
-
The bridge maps
|
|
16
|
-
tables with spans, footnotes, math,
|
|
17
|
-
|
|
18
|
-
`` `\alpha`{=latex} `` becomes a Pandoc `RawInline` that the LaTeX writer emits
|
|
19
|
-
and every other writer drops - exactly the pandoc-Markdown semantics the syntax
|
|
20
|
-
was born from.
|
|
12
|
+
The bridge maps parsed nodes instead of converting through HTML. It preserves
|
|
13
|
+
structure such as tables with spans, footnotes, math, admonitions, attributes,
|
|
14
|
+
and target-routed raw content when Pandoc can represent it.
|
|
21
15
|
|
|
22
16
|
## Install
|
|
23
17
|
|
|
@@ -25,347 +19,99 @@ was born from.
|
|
|
25
19
|
npm install @markup-carve/pandoc-carve
|
|
26
20
|
```
|
|
27
21
|
|
|
28
|
-
The CLI
|
|
29
|
-
3.
|
|
30
|
-
or your package manager. Emitting plain JSON (`-t json`) needs no pandoc at all.
|
|
22
|
+
The CLI requires Pandoc 3.x on `PATH` for formats other than JSON. CI currently
|
|
23
|
+
tests Pandoc 3.11. Pandoc is not bundled.
|
|
31
24
|
|
|
32
25
|
## CLI
|
|
33
26
|
|
|
34
27
|
```bash
|
|
35
|
-
#
|
|
28
|
+
# Export
|
|
36
29
|
pandoc-carve doc.crv -t latex -o doc.tex
|
|
37
|
-
|
|
38
|
-
# Carve -> Typst, PDF, DOCX ... any pandoc writer
|
|
39
30
|
pandoc-carve doc.crv -t typst -o doc.typ
|
|
40
|
-
pandoc-carve doc.crv -t pdf -o doc.pdf
|
|
41
31
|
pandoc-carve doc.crv -t docx -o doc.docx
|
|
32
|
+
pandoc-carve doc.crv -t pdf -o doc.pdf
|
|
42
33
|
|
|
43
|
-
#
|
|
44
|
-
pandoc-carve doc.crv -t latex -s -o doc.tex
|
|
45
|
-
|
|
46
|
-
# Just the Pandoc JSON AST (no pandoc needed)
|
|
47
|
-
pandoc-carve doc.crv -t json
|
|
48
|
-
|
|
49
|
-
# Read from stdin, pass extra args through to pandoc after --
|
|
50
|
-
cat doc.crv | pandoc-carve - -t latex -- --toc
|
|
51
|
-
|
|
52
|
-
# IMPORT: anything pandoc reads -> Carve
|
|
34
|
+
# Import
|
|
53
35
|
pandoc-carve report.docx -f docx -o report.crv
|
|
54
36
|
pandoc-carve paper.tex -f latex -o paper.crv
|
|
55
|
-
pandoc-carve README.md -f markdown -o README.crv
|
|
56
37
|
|
|
57
|
-
#
|
|
38
|
+
# Emit or consume Pandoc JSON without invoking pandoc
|
|
39
|
+
pandoc-carve doc.crv -t json
|
|
58
40
|
pandoc -f rst -t json doc.rst | pandoc-carve - -f json
|
|
59
|
-
|
|
60
|
-
# From a SERIALIZED Carve AST (spec PART 12) - from any engine, not just carve-js
|
|
61
|
-
carve doc.crv --to-json | pandoc-carve - -f carve-json -t latex
|
|
62
41
|
```
|
|
63
42
|
|
|
64
|
-
Anything
|
|
65
|
-
`
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
do not fail CI. Use `--diagnostics -` for JSON on stderr.
|
|
43
|
+
Anything that cannot be mapped faithfully produces a diagnostic. Use
|
|
44
|
+
`--diagnostics report.json` for the versioned JSON report and `--fail-on-loss`
|
|
45
|
+
to return exit code 3 when a conversion degrades or drops content. Imports
|
|
46
|
+
through a Pandoc reader other than `-f json` also return 3 because fidelity
|
|
47
|
+
before the Pandoc JSON boundary cannot be verified.
|
|
70
48
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
import { carveToPandoc, carveToPandocJson } from '@markup-carve/pandoc-carve';
|
|
75
|
-
|
|
76
|
-
const { doc, warnings, diagnostics } = carveToPandoc('Hello /world/!');
|
|
77
|
-
// doc = { 'pandoc-api-version': [1, 23, 1], meta: {...}, blocks: [...] }
|
|
78
|
-
// warnings = ['degraded: ...'] for lossy constructs
|
|
79
|
-
// diagnostics = [{ code, direction, severity, message, details?, path?, sourceLocation? }]
|
|
80
|
-
|
|
81
|
-
const json = carveToPandocJson('Hello /world/!'); // stringified doc
|
|
82
|
-
```
|
|
49
|
+
Named input files expand contained includes by default, rooted at their own
|
|
50
|
+
directory. Use `--no-includes` to keep directives literal. Standard input
|
|
51
|
+
expands includes only when `--include-root` is supplied.
|
|
83
52
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
whether it arrives as an object or as JSON text:
|
|
88
|
-
|
|
89
|
-
```js
|
|
90
|
-
import { carveAstToPandoc, carveToCarveAst } from '@markup-carve/pandoc-carve';
|
|
91
|
-
|
|
92
|
-
// A tree from carve-rs, carve-php, carve-go ... or `carve doc.crv --to-json`
|
|
93
|
-
const { doc, warnings, diagnostics } = carveAstToPandoc(serializedAstJson);
|
|
94
|
-
|
|
95
|
-
// The same exchange format, produced from source here
|
|
96
|
-
const ast = carveToCarveAst('Hello /world/!');
|
|
97
|
-
```
|
|
53
|
+
The [CLI reference](docs/reference.md#cli) covers standalone documents,
|
|
54
|
+
additional Pandoc arguments, includes, serialized Carve AST input, and every
|
|
55
|
+
diagnostic option.
|
|
98
56
|
|
|
99
|
-
|
|
100
|
-
returns Carve source, serialized by carve's own `renderCarve` (the `carve fmt`
|
|
101
|
-
serializer), so output formatting carries fmt's guarantees:
|
|
57
|
+
## API
|
|
102
58
|
|
|
103
59
|
```js
|
|
104
|
-
import {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
const
|
|
60
|
+
import {
|
|
61
|
+
carveToPandoc,
|
|
62
|
+
carveToPandocJson,
|
|
63
|
+
pandocToCarve,
|
|
64
|
+
} from '@markup-carve/pandoc-carve'
|
|
65
|
+
|
|
66
|
+
const exported = carveToPandoc('Hello /world/!')
|
|
67
|
+
const json = carveToPandocJson('Hello /world/!')
|
|
68
|
+
const imported = pandocToCarve(json)
|
|
111
69
|
```
|
|
112
70
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
list), export with `carveToPandoc(src, { roundtrip: true })` or the CLI's
|
|
117
|
-
`--roundtrip` flag. In addition to the existing `carve-block` attribute marker,
|
|
118
|
-
this preserves comments, typed citation fields, and unknown future Carve nodes
|
|
119
|
-
with a versioned private Span/Div envelope. The native citation and readable
|
|
120
|
-
unknown-node fallback remain usable by Pandoc. The marker may be visible in
|
|
121
|
-
writer output and exact preservation is guaranteed only through Pandoc JSON.
|
|
122
|
-
The complete format, safety checks, available source information, and filter
|
|
123
|
-
semantics are documented in [the provenance envelope](docs/roundtrip-provenance.md).
|
|
124
|
-
|
|
125
|
-
Pipe the JSON to pandoc yourself:
|
|
126
|
-
|
|
127
|
-
```bash
|
|
128
|
-
node -e "import('@markup-carve/pandoc-carve').then(m => process.stdout.write(m.carveToPandocJson(require('fs').readFileSync('doc.crv','utf8'))))" \
|
|
129
|
-
| pandoc -f json -t latex
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
## What maps to what
|
|
133
|
-
|
|
134
|
-
| Carve | Pandoc |
|
|
135
|
-
|-------|--------|
|
|
136
|
-
| `/italic/`, `*bold*`, `/*both*/` | Emph, Strong, Strong+Emph |
|
|
137
|
-
| `_underline_`, `~strike~`, `=highlight=` | Underline, Strikeout, Span `.mark` |
|
|
138
|
-
| `{^sup^}`, `{,sub,}` | Superscript, Subscript |
|
|
139
|
-
| Headings + `{#id .class}` attributes | Header with Attr |
|
|
140
|
-
| Tables incl. rowspan/colspan and captions | Table (spans inverted to pandoc's origin-cell model) |
|
|
141
|
-
| `table.rowGroups` counts (PART 12 section 15) | TableHead, one TableBody per group with its RowHeadColumns and intermediate header rows, TableFoot |
|
|
142
|
-
| Cell attributes `\|{#id .cls k=v} text`, row attributes `\| a \|{.cls}` | the `Attr` pandoc's Cell and Row already carry |
|
|
143
|
-
| Footnotes (reference and inline `^[..]`) | Note |
|
|
144
|
-
| Math `` $`..` `` / `` $$`..` `` | Math Inline / Display |
|
|
145
|
-
| Images/quotes with `^ caption` lines | Figure |
|
|
146
|
-
| A bare `::: figure` composite (PART 9 section 4c) | Figure of nested Figures - pandoc's subfigure model - with the group caption on the outer one. An opener carrying a title or a `[label]` is not this production and stays a Div |
|
|
147
|
-
| `::: note` admonitions | Div `.admonition .note` (+ title paragraph) |
|
|
148
|
-
| Tabs / code-group panels, grouping `[label]` | Div; each `[label]` becomes a bold caption so panels stay distinguishable (graceful degradation) |
|
|
149
|
-
| `` `x`{=latex} `` / ```` ```=latex ```` | RawInline / RawBlock (target-routed by pandoc) |
|
|
150
|
-
| Citations `[@key]`, `[+@key]`, `[-@key, p. 33]` | Cite with one Citation per key (AuthorInText / SuppressAuthor / NormalCitation), the locator in the citation suffix, the verbatim source as the Cite content |
|
|
151
|
-
| `@mention`, `#tag`, `:ext[..]`, critic markup | classed Spans (documented degradation) |
|
|
152
|
-
| `[text]{.smallcaps}` | SmallCaps (pandoc's own class convention, both directions) |
|
|
153
|
-
| Frontmatter, nested: maps, block and flow sequences, sequences of maps | Meta, to the depth pandoc's own reader gives it |
|
|
154
|
-
| `::: \|` line blocks (verse) | LineBlock, one entry per line, an empty entry per stanza break |
|
|
155
|
-
| Ordered markers `1.` / `1)` / `a.` / `iv.` | OrderedList with the matching style and delimiter. Pandoc's example list `(@)` and its `(1)` marker have no Carve form and are reported |
|
|
156
|
-
| A no-break space the parser resolved (`\ `) | U+00A0 (the engines publish a private-use sentinel for it) |
|
|
157
|
-
| A reference link, image or footnote nothing defines (`[r][]`, `[^f]`) | the literal source as text, which is what Carve renders, plus a warning naming the label |
|
|
158
|
-
|
|
159
|
-
The complete node-by-node contract lives in the test goldens. Worked
|
|
160
|
-
input/output pairs in both directions - including how interactive constructs
|
|
161
|
-
degrade for print formats - are in [`examples/`](examples/README.md).
|
|
162
|
-
|
|
163
|
-
## Dangerous URL schemes are blanked
|
|
71
|
+
Each direction returns structured diagnostics alongside its output. Node.js
|
|
72
|
+
hosts can use `carveToPandocWithIncludes` from the `/node` entry point for
|
|
73
|
+
contained file expansion and dependency tracking.
|
|
164
74
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
naming the scheme and the destination that was refused.
|
|
75
|
+
Use `carveToCarveAst` to serialize source, `carveAstToPandoc` to convert a
|
|
76
|
+
serialized Carve tree, and `pandocToCarveAst` for the reverse direction. These
|
|
77
|
+
functions consume the versioned AST defined by the Carve specification, not an
|
|
78
|
+
implementation-specific runtime tree.
|
|
170
79
|
|
|
171
|
-
|
|
172
|
-
every target that emits a resolvable URL. Pandoc's targets are not HTML, but
|
|
173
|
-
`pandoc -f json -t html` is one command away - passing the scheme through here
|
|
174
|
-
would not be a narrower policy, it would be the same sink one step removed.
|
|
80
|
+
## Round trips
|
|
175
81
|
|
|
176
|
-
|
|
177
|
-
`
|
|
178
|
-
|
|
179
|
-
over both to keep the mirror honest - the probe strips control characters and
|
|
180
|
-
Unicode whitespace before it reads a scheme, so `<U+202F>javascript:` and
|
|
181
|
-
`java<DEL>script:` are caught along with the plain spelling.
|
|
182
|
-
|
|
183
|
-
Nothing else is touched. An `https:`, `mailto:`, `tel:`, `ftp:`, relative or
|
|
184
|
-
fragment destination reaches pandoc exactly as written, and emits no
|
|
185
|
-
diagnostic.
|
|
186
|
-
|
|
187
|
-
> [!NOTE]
|
|
188
|
-
> This covers link and image **destinations**. An `{onclick=…}`, `{style=…}` or
|
|
189
|
-
> `{srcdoc=…}` attribute, which Carve's HTML writer also refuses, still reaches
|
|
190
|
-
> pandoc - see [#163](https://github.com/markup-carve/pandoc-carve/issues/163).
|
|
191
|
-
|
|
192
|
-
## Why a bridge, not a pandoc reader?
|
|
193
|
-
|
|
194
|
-
A native `Text.Pandoc.Readers.Carve` upstream would be a fourth full Carve
|
|
195
|
-
parser, written in Haskell, outside the conformance loop that keeps the three
|
|
196
|
-
official implementations byte-identical against the shared corpus. While the
|
|
197
|
-
spec is on its 0.x line and still moving, that reader would drift on pandoc's
|
|
198
|
-
release cadence and ship stale behavior. The bridge reuses the canonical,
|
|
199
|
-
conformance-tested `@markup-carve/carve` parser instead - correct by
|
|
200
|
-
construction, and it iterates in lockstep with the spec.
|
|
201
|
-
|
|
202
|
-
A pandoc custom Lua reader has the same drift problem (it would reimplement
|
|
203
|
-
the parser in Lua). Once the spec reaches 1.0 and stabilizes, contributing an
|
|
204
|
-
upstream reader becomes attractive - with this bridge's node map and the
|
|
205
|
-
conformance corpus as the oracle any port has to pass.
|
|
206
|
-
|
|
207
|
-
## Options
|
|
82
|
+
With round-trip metadata enabled, the test suite requires
|
|
83
|
+
`carve -> Pandoc AST -> carve` to render equivalent normalized HTML across the
|
|
84
|
+
corpus apart from an explicit known-lossy list:
|
|
208
85
|
|
|
209
86
|
```js
|
|
210
|
-
carveToPandoc(
|
|
211
|
-
roundtrip: true, // stamp attr wrappers for exact re-import
|
|
212
|
-
symbols: { heart: '♥' }, // resolve :name: symbols like the renderer would
|
|
213
|
-
listTable: false, // opt OUT: keep ::: list-table as a degraded div
|
|
214
|
-
citations: false, // opt OUT: read [@key] as an @mention
|
|
215
|
-
extensions: [], // extra Carve extensions for the parse
|
|
216
|
-
});
|
|
87
|
+
const result = carveToPandoc(source, { roundtrip: true })
|
|
217
88
|
```
|
|
218
89
|
|
|
219
|
-
CLI
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
one it recognizes on the way back. With `citations` off the parser reaches the
|
|
225
|
-
`@` first and `[@doe1990]` is a `.mention` span, so an imported bibliography
|
|
226
|
-
becomes mentions; with `listTable` off a table this bridge itself wrote as
|
|
227
|
-
`::: list-table` returns as a `Div` of nested lists. Turn them off to get what
|
|
228
|
-
a processor with neither extension enabled would render.
|
|
90
|
+
The CLI equivalent is `--roundtrip`. Private Span and Div metadata preserves
|
|
91
|
+
comments, attribute placement, typed citations, and future Carve nodes through
|
|
92
|
+
Pandoc JSON. Other writers may expose or discard that metadata. See the
|
|
93
|
+
[provenance envelope](docs/roundtrip-provenance.md) for its format and safety
|
|
94
|
+
rules.
|
|
229
95
|
|
|
230
|
-
##
|
|
96
|
+
## Fidelity and limitations
|
|
231
97
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
JSON Schema cannot express a cross-field sum, so a document that validates
|
|
236
|
-
against `resources/ast-schema.json` can still be incoherent - the bridge
|
|
237
|
-
checks it itself rather than trusting a green validator.
|
|
238
|
-
- A pandoc table with block content in a cell (a list, two paragraphs, a code
|
|
239
|
-
block) is imported as `::: list-table` rather than a pipe table, and that is
|
|
240
|
-
now the ONLY reason a table leaves the pipe form. PART 9 §16's pipe-table cell
|
|
241
|
-
holds inlines, so there is no pipe form for it, and the extension's cells are
|
|
242
|
-
list items that hold full blocks. Structure is preserved; what the extension
|
|
243
|
-
cannot spell is reported instead - a body group's attributes, a body boundary
|
|
244
|
-
no header row marks, and body groups that disagree on their row-head column
|
|
245
|
-
count. It converts back to the pandoc table by default; `listTable: false`
|
|
246
|
-
returns the degraded div instead.
|
|
247
|
-
- A pandoc table with ROW-HEAD COLUMNS stays a pipe table. `RowHeadColumns` says
|
|
248
|
-
the leading N cells of every body row are row headers, and a pipe table says
|
|
249
|
-
that per cell: `|= Mercury | 4,879.4 |` is a `<th scope="row">`. Marking the
|
|
250
|
-
cells needs no extension and round-trips, because the export direction derives
|
|
251
|
-
the count back from the leading run.
|
|
252
|
-
- On the way out, one TableBody per RUN of body rows that agree on that leading
|
|
253
|
-
run. Pandoc's `RowHeadColumns` is a count on a body and a `Table` holds a list
|
|
254
|
-
of bodies, so rows that disagree are simply different bodies. A table whose
|
|
255
|
-
body rows all agree emits exactly one body, as before.
|
|
256
|
-
- Pandoc `SmallCaps` has no Carve node and is not getting one: it imports as a
|
|
257
|
-
`[text]{.smallcaps}` span, with a warning saying so. The span is not a dead
|
|
258
|
-
end, though - the export direction reads that class back as `SmallCaps`, the
|
|
259
|
-
same convention pandoc's own markdown reader uses, so small caps survive
|
|
260
|
-
Pandoc -> Carve -> Pandoc and still reach the LaTeX, Typst and DOCX writers.
|
|
261
|
-
Other attributes on the span are preserved around it, exactly as pandoc does.
|
|
262
|
-
- Pandoc `Quoted` imports as literal curly quote characters (`“…”` / `‘…’`).
|
|
263
|
-
Carve has no quote node, and the characters are what an author would have
|
|
264
|
-
typed. This one is genuinely one-way: the text re-exports as `Str`, so the
|
|
265
|
-
quote kind and pandoc's locale-aware quoting are gone. Reported once per
|
|
266
|
-
document.
|
|
267
|
-
- A `ColSpec`'s `ColWidth` is dropped. Carve's table model has no width slot at
|
|
268
|
-
any level and pipe-table source cannot spell one, so there is nowhere to put
|
|
269
|
-
the number and no syntax that would reproduce it - a wontfix rather than a
|
|
270
|
-
gap. The drop is silent on purpose: pandoc derives a `ColWidth` for every
|
|
271
|
-
grid and multiline table from the ASCII column widths, so a diagnostic would
|
|
272
|
-
fire on the ordinary case and report a value the author never chose. Column
|
|
273
|
-
ALIGNMENT is carried in both directions; tables leaving the bridge always
|
|
274
|
-
carry `ColWidthDefault`, which pandoc's writers size themselves.
|
|
275
|
-
- A rowspan that starts in a header row and continues into the body is clipped
|
|
276
|
-
to an empty body cell, with a warning. Carve is the richer model here: its
|
|
277
|
-
rows are one flat list, while pandoc's `TableHead` and `TableBody` hold
|
|
278
|
-
separate row lists and confine a cell's `rowSpan` to its own section. Moving
|
|
279
|
-
the head/body boundary to make the span fit would silently reclassify a row,
|
|
280
|
-
and duplicating the origin's content would invent a cell the author never
|
|
281
|
-
wrote, so the grid keeps its shape and the diagnostic reports the loss.
|
|
282
|
-
- Reverse conversion keeps flattening for display targets: `pandocToCarve`
|
|
283
|
-
serializes through Carve 0.1 source, which has no spelling for row groups or
|
|
284
|
-
a short caption, so those fields survive only on the `pandocToCarveAst` path.
|
|
285
|
-
- Citations cross as pandoc's own citeproc convention, which is lossy in one
|
|
286
|
-
respect: pandoc's `Citation` has no locator field, so Carve's typed
|
|
287
|
-
`locatorLabel`/`locatorValue` pair is serialized into `citationSuffix` behind
|
|
288
|
-
a `, ` and citeproc re-derives it from there. The bridge does not rebuild
|
|
289
|
-
those two fields on the way back - the label table is section 4.2's, it lives
|
|
290
|
-
in the engine, and a second copy here would drift. The locator TEXT round-
|
|
291
|
-
trips byte for byte, so re-parsing the emitted source with the citations
|
|
292
|
-
extension restores the typed pair. With `roundtrip: true`, the private
|
|
293
|
-
provenance wrapper retains the original typed fields directly while its
|
|
294
|
-
enclosed native `Cite` remains available to citeproc. A group whose items mix `AuthorInText` and
|
|
295
|
-
`NormalCitation` cannot be spelled in Carve (the integral `+` is a property of
|
|
296
|
-
the whole cluster) and is imported as integral with a warning.
|
|
297
|
-
- Pandoc keeps its bibliography in document metadata, not in the AST, so
|
|
298
|
-
importing a `Cite` emits no `[@key]:` definition lines. The citation itself
|
|
299
|
-
round-trips: `citationNoteNum` is reproduced the way pandoc's own markdown
|
|
300
|
-
reader computes it (notes closed so far, plus one), so a `Cite` returns
|
|
301
|
-
unchanged rather than unchanged-except-one-integer.
|
|
302
|
-
- Block content inside metadata (pandoc's `MetaBlocks`, e.g. `abstract: |`)
|
|
303
|
-
round-trips as a YAML literal block scalar, the same spelling pandoc's own
|
|
304
|
-
markdown writer emits and its reader turns back into `MetaBlocks` - by the
|
|
305
|
-
FORM, so any key can carry it, not just `abstract`. The scalar keeps every
|
|
306
|
-
line and every blank line between them, so the paragraph structure survives
|
|
307
|
-
rather than flattening into one string. Every other `Meta` shape - maps,
|
|
308
|
-
lists, lists of maps, scalars, booleans - round-trips too.
|
|
309
|
-
- A `rowGroups` partition (a foot, several body groups, a body's own header
|
|
310
|
-
rows or row-head columns) survives into the exchange AST, so
|
|
311
|
-
`pandocToCarveAst` hands it on whole. `pandocToCarve` spells most of it too: a
|
|
312
|
-
pipe table states its head and foot row counts on its attribute line
|
|
313
|
-
(`{header-rows=2 footer-rows=1}`) and marks its row headers on the cells, so
|
|
314
|
-
what flattens into body rows is a second body group and a body's own
|
|
315
|
-
intermediate header rows and attributes - reported, not dropped quietly. Use
|
|
316
|
-
the AST entry point when a second body group has to survive.
|
|
317
|
-
- Stating the foot states the whole partition, and a stated partition is ONE
|
|
318
|
-
body. A body carries one `RowHeadColumns`, so when the body rows disagree on
|
|
319
|
-
how many leading cells are row headers, a table with a foot cannot keep them:
|
|
320
|
-
the reader takes a count every row agrees on, and the disagreement is reported
|
|
321
|
-
from both directions. Without a foot the reader splits a body at every change
|
|
322
|
-
and every run survives.
|
|
323
|
-
- A marker on a HEAD cell (`|=> Name |`) is the column's alignment and becomes
|
|
324
|
-
pandoc's `ColSpec`; a marker on a BODY cell (`|> 12 |`) aligns that cell alone
|
|
325
|
-
and becomes the cell's own `Alignment`. The two are not interchangeable: a
|
|
326
|
-
pandoc cell with `AlignDefault` inherits its ColSpec, so promoting a body
|
|
327
|
-
cell's marker to the column would align cells the author did not.
|
|
328
|
-
- Column alignment needs a header row to live on (`|=> Name |`). A headerless
|
|
329
|
-
pandoc table's column alignment is written onto each cell instead, which
|
|
330
|
-
renders the same; the move is reported.
|
|
331
|
-
- The frontmatter reader covers the YAML subset frontmatter uses, not YAML.
|
|
332
|
-
Anchors, tags, multi-document streams, block scalars and flow maps are out; a
|
|
333
|
-
line that fits no shape is reported and skipped rather than guessed at.
|
|
334
|
-
- Scalars are typed the way pandoc's own frontmatter reader types them: an
|
|
335
|
-
unquoted `true`, `yes`, `on` or `y` (and their negatives) is a `MetaBool`, a
|
|
336
|
-
quoted `"true"` stays text, a null scalar keeps its key as an empty
|
|
337
|
-
`MetaString`, and a number stays text because `Meta` has no number type. This
|
|
338
|
-
matters beyond tidiness - a boolean read as text is not a near miss but an
|
|
339
|
-
inversion, since a pandoc template testing `draft` sees any non-empty string
|
|
340
|
-
as true.
|
|
341
|
-
- Attribute order inside `{...}` is normalized to `#id .class key=val` on
|
|
342
|
-
round-trip - pandoc's Attr has fixed slots, so the author's original order
|
|
343
|
-
is not representable. Semantics are unchanged.
|
|
344
|
-
- Import fidelity is bounded by `renderCarve` (carve fmt): the bridge hands it
|
|
345
|
-
a byte-exact AST, but known fmt issues (e.g. trailing whitespace inside code
|
|
346
|
-
blocks, carve-js issue 340) surface in the serialized output.
|
|
347
|
-
- The pinned engine bounds what the source path can produce. The current git
|
|
348
|
-
pin exports `toAstJson`, so the engine's own exchange serializer is used;
|
|
349
|
-
with an older engine (any published release up to `0.1.3`),
|
|
350
|
-
`src/ast-json.ts` performs the PART 12 section 7 mapping instead, and a pin
|
|
351
|
-
that exports `toAstJson` takes over automatically.
|
|
352
|
-
- Tier-3 visual extensions (mermaid, chart, code-group) arrive as their
|
|
353
|
-
degraded block forms (code blocks / divs), same as Carve's static mode.
|
|
354
|
-
`list-table` is the exception: it converts to a real Pandoc table with full
|
|
355
|
-
block content per cell, unless `listTable: false` / `--no-list-table`.
|
|
98
|
+
Pandoc's AST does not represent every Carve construct, and output formats have
|
|
99
|
+
their own limits. The bridge reports those cases rather than silently dropping
|
|
100
|
+
them. Highlights include:
|
|
356
101
|
|
|
357
|
-
|
|
102
|
+
- underline, highlight, and custom attributes depend on target-format support;
|
|
103
|
+
- complex Carve table structure may be normalized by a writer;
|
|
104
|
+
- grouped UI constructs such as tabs degrade to labeled blocks;
|
|
105
|
+
- raw target content only survives in matching writers;
|
|
106
|
+
- comments and attribute placement require round-trip metadata.
|
|
358
107
|
|
|
359
|
-
|
|
360
|
-
|
|
108
|
+
Dangerous URL schemes such as `javascript:` are blanked and reported. The
|
|
109
|
+
[URL policy](docs/reference.md#dangerous-url-schemes-are-blanked) documents the
|
|
110
|
+
exact behavior. The [mapping and limitations reference](docs/reference.md#what-maps-to-what)
|
|
111
|
+
contains the node table and per-format limits; the [options section](docs/reference.md#options)
|
|
112
|
+
covers API configuration.
|
|
361
113
|
|
|
362
|
-
|
|
363
|
-
git clone --recurse-submodules https://github.com/markup-carve/pandoc-carve
|
|
364
|
-
# or, in an existing clone:
|
|
365
|
-
git submodule update --init
|
|
366
|
-
npm ci && npm test
|
|
367
|
-
```
|
|
114
|
+
## Development
|
|
368
115
|
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
two-word document stayed live on the published package.
|
|
116
|
+
Contributor setup, tests, and maintenance commands are in the
|
|
117
|
+
[development guide](docs/development.md).
|
package/dist/ast-json.js
CHANGED
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
*/
|
|
39
39
|
const CHILD_FIELDS = [
|
|
40
40
|
'children',
|
|
41
|
+
'blocks',
|
|
41
42
|
'items',
|
|
42
43
|
'rows',
|
|
43
44
|
'cells',
|
|
@@ -47,6 +48,8 @@ const CHILD_FIELDS = [
|
|
|
47
48
|
'shortCaption',
|
|
48
49
|
'title',
|
|
49
50
|
'target',
|
|
51
|
+
'old',
|
|
52
|
+
'new',
|
|
50
53
|
];
|
|
51
54
|
function isObject(value) {
|
|
52
55
|
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
@@ -58,6 +61,13 @@ function isObject(value) {
|
|
|
58
61
|
* object, so the runtime tree the caller still holds is never copied and never
|
|
59
62
|
* mutated.
|
|
60
63
|
*/
|
|
64
|
+
/**
|
|
65
|
+
* The six kinds a `:::` container places rather than presents. They are
|
|
66
|
+
* `directive` nodes, not admonitions (carve#2195, carve#2225): a table of
|
|
67
|
+
* contents is not a callout. Releases up to 0.1.7 spell them `admonition`,
|
|
68
|
+
* and the schema refuses that `kind` there.
|
|
69
|
+
*/
|
|
70
|
+
const DIRECTIVE_KINDS = new Set(['bibliography', 'footnotes', 'glossary', 'index', 'references', 'toc']);
|
|
61
71
|
function normalize(node) {
|
|
62
72
|
if (Array.isArray(node)) {
|
|
63
73
|
let changed = false;
|
|
@@ -107,6 +117,19 @@ function normalize(node) {
|
|
|
107
117
|
// reads the wire has no reason to know the other spelling existed.
|
|
108
118
|
set('type', 'critic_comment');
|
|
109
119
|
break;
|
|
120
|
+
case 'substitution': {
|
|
121
|
+
if (!Array.isArray(current['old']) && typeof current['oldText'] === 'string') {
|
|
122
|
+
set('old', [{ type: 'text', value: current['oldText'] }]);
|
|
123
|
+
}
|
|
124
|
+
if (!Array.isArray(current['new']) && typeof current['newText'] === 'string') {
|
|
125
|
+
set('new', [{ type: 'text', value: current['newText'] }]);
|
|
126
|
+
}
|
|
127
|
+
if (current['oldText'] !== undefined || current['newText'] !== undefined) {
|
|
128
|
+
const { oldText: _oldText, newText: _newText, ...rest } = out ?? { ...node };
|
|
129
|
+
out = rest;
|
|
130
|
+
}
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
110
133
|
case 'footnote': {
|
|
111
134
|
// The pre-split inline node (carve#405), whose name COLLIDES with
|
|
112
135
|
// the wire `footnote` - which is the DEFINITION block, carrying
|
|
@@ -137,6 +160,20 @@ function normalize(node) {
|
|
|
137
160
|
default:
|
|
138
161
|
break;
|
|
139
162
|
}
|
|
163
|
+
// A reference's label is spelled `label` on the wire, like the `footnote`
|
|
164
|
+
// definition it matches (carve#2213). Releases up to 0.1.7 serialize `id`,
|
|
165
|
+
// which the schema refuses - it sanctions decoding the old property onto
|
|
166
|
+
// the field (PART 12 section 11), which is what this does. Remove it once
|
|
167
|
+
// no supported release emits `id`. After the switch, because the pre-split
|
|
168
|
+
// fold above reaches `footnote_ref` by changing `type` rather than matching it.
|
|
169
|
+
const settled = out ?? node;
|
|
170
|
+
if (settled['type'] === 'admonition' && DIRECTIVE_KINDS.has(String(settled['kind']))) {
|
|
171
|
+
out = { ...settled, type: 'directive' };
|
|
172
|
+
}
|
|
173
|
+
if (settled['type'] === 'footnote_ref' && typeof settled['id'] === 'string') {
|
|
174
|
+
const { id, ...rest } = settled;
|
|
175
|
+
out = { ...rest, label: id };
|
|
176
|
+
}
|
|
140
177
|
return (out ?? node);
|
|
141
178
|
}
|
|
142
179
|
/**
|