@tinta-lang/syntax 0.0.0-stage → 0.1.16
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/LICENSE +21 -0
- package/README.md +16 -2
- package/THIRD_PARTY_NOTICES.txt +13651 -0
- package/dist/directive.d.ts +40 -0
- package/dist/editing.d.ts +46 -0
- package/dist/enrichment.d.ts +5 -0
- package/dist/expression.d.ts +26 -0
- package/dist/image-destinations.d.ts +3 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +10118 -0
- package/dist/parser.d.ts +40 -0
- package/dist/registry.d.ts +144 -0
- package/dist/source.d.ts +28 -0
- package/package.json +289 -3
- package/parser-provenance.json +1419 -0
- package/patches/README.md +5 -0
- package/patches/micromark.patch +84 -0
- package/vendor/@noble/hashes/LICENSE +21 -0
- package/vendor/@noble/hashes/_md.js +209 -0
- package/vendor/@noble/hashes/_u64.js +77 -0
- package/vendor/@noble/hashes/package.json +91 -0
- package/vendor/@noble/hashes/sha2.js +446 -0
- package/vendor/@noble/hashes/utils.js +687 -0
- package/vendor/character-entities/index.js +2132 -0
- package/vendor/character-entities/license +22 -0
- package/vendor/character-entities/package.json +78 -0
- package/vendor/decode-named-character-reference/index.js +19 -0
- package/vendor/decode-named-character-reference/license +22 -0
- package/vendor/decode-named-character-reference/package.json +90 -0
- package/vendor/devlop/lib/default.js +9 -0
- package/vendor/devlop/license +22 -0
- package/vendor/devlop/package.json +80 -0
- package/vendor/longest-streak/index.js +36 -0
- package/vendor/longest-streak/license +22 -0
- package/vendor/longest-streak/package.json +73 -0
- package/vendor/markdown-table/index.js +393 -0
- package/vendor/markdown-table/license +22 -0
- package/vendor/markdown-table/package.json +77 -0
- package/vendor/mdast-util-from-markdown/index.js +2 -0
- package/vendor/mdast-util-from-markdown/lib/index.js +1270 -0
- package/vendor/mdast-util-from-markdown/license +22 -0
- package/vendor/mdast-util-from-markdown/package.json +98 -0
- package/vendor/mdast-util-gfm-strikethrough/index.js +5 -0
- package/vendor/mdast-util-gfm-strikethrough/lib/index.js +133 -0
- package/vendor/mdast-util-gfm-strikethrough/license +22 -0
- package/vendor/mdast-util-gfm-strikethrough/package.json +84 -0
- package/vendor/mdast-util-gfm-table/index.js +2 -0
- package/vendor/mdast-util-gfm-table/lib/index.js +300 -0
- package/vendor/mdast-util-gfm-table/license +22 -0
- package/vendor/mdast-util-gfm-table/package.json +101 -0
- package/vendor/mdast-util-gfm-task-list-item/index.js +4 -0
- package/vendor/mdast-util-gfm-task-list-item/lib/index.js +141 -0
- package/vendor/mdast-util-gfm-task-list-item/license +22 -0
- package/vendor/mdast-util-gfm-task-list-item/package.json +90 -0
- package/vendor/mdast-util-phrasing/index.js +1 -0
- package/vendor/mdast-util-phrasing/lib/index.js +45 -0
- package/vendor/mdast-util-phrasing/license +23 -0
- package/vendor/mdast-util-phrasing/package.json +78 -0
- package/vendor/mdast-util-to-markdown/index.js +3 -0
- package/vendor/mdast-util-to-markdown/lib/configure.js +98 -0
- package/vendor/mdast-util-to-markdown/lib/handle/blockquote.js +40 -0
- package/vendor/mdast-util-to-markdown/lib/handle/break.js +41 -0
- package/vendor/mdast-util-to-markdown/lib/handle/code.js +86 -0
- package/vendor/mdast-util-to-markdown/lib/handle/definition.js +83 -0
- package/vendor/mdast-util-to-markdown/lib/handle/emphasis.js +67 -0
- package/vendor/mdast-util-to-markdown/lib/handle/heading.js +84 -0
- package/vendor/mdast-util-to-markdown/lib/handle/html.js +27 -0
- package/vendor/mdast-util-to-markdown/lib/handle/image-reference.js +78 -0
- package/vendor/mdast-util-to-markdown/lib/handle/image.js +92 -0
- package/vendor/mdast-util-to-markdown/lib/handle/index.js +45 -0
- package/vendor/mdast-util-to-markdown/lib/handle/inline-code.js +86 -0
- package/vendor/mdast-util-to-markdown/lib/handle/link-reference.js +78 -0
- package/vendor/mdast-util-to-markdown/lib/handle/link.js +129 -0
- package/vendor/mdast-util-to-markdown/lib/handle/list-item.js +73 -0
- package/vendor/mdast-util-to-markdown/lib/handle/list.js +107 -0
- package/vendor/mdast-util-to-markdown/lib/handle/paragraph.js +27 -0
- package/vendor/mdast-util-to-markdown/lib/handle/root.js +34 -0
- package/vendor/mdast-util-to-markdown/lib/handle/strong.js +67 -0
- package/vendor/mdast-util-to-markdown/lib/handle/text.js +30 -0
- package/vendor/mdast-util-to-markdown/lib/handle/thematic-break.js +27 -0
- package/vendor/mdast-util-to-markdown/lib/index.js +213 -0
- package/vendor/mdast-util-to-markdown/lib/join.js +56 -0
- package/vendor/mdast-util-to-markdown/lib/unsafe.js +160 -0
- package/vendor/mdast-util-to-markdown/lib/util/association.js +33 -0
- package/vendor/mdast-util-to-markdown/lib/util/character.js +32 -0
- package/vendor/mdast-util-to-markdown/lib/util/check-bullet-ordered.js +25 -0
- package/vendor/mdast-util-to-markdown/lib/util/check-bullet-other.js +42 -0
- package/vendor/mdast-util-to-markdown/lib/util/check-bullet.js +25 -0
- package/vendor/mdast-util-to-markdown/lib/util/check-emphasis.js +25 -0
- package/vendor/mdast-util-to-markdown/lib/util/check-fence.js +25 -0
- package/vendor/mdast-util-to-markdown/lib/util/check-list-item-indent.js +25 -0
- package/vendor/mdast-util-to-markdown/lib/util/check-quote.js +25 -0
- package/vendor/mdast-util-to-markdown/lib/util/check-rule-repetition.js +25 -0
- package/vendor/mdast-util-to-markdown/lib/util/check-rule.js +25 -0
- package/vendor/mdast-util-to-markdown/lib/util/check-strong.js +25 -0
- package/vendor/mdast-util-to-markdown/lib/util/compile-pattern.js +30 -0
- package/vendor/mdast-util-to-markdown/lib/util/container-flow.js +93 -0
- package/vendor/mdast-util-to-markdown/lib/util/container-phrasing.js +704 -0
- package/vendor/mdast-util-to-markdown/lib/util/encode-character-reference.js +11 -0
- package/vendor/mdast-util-to-markdown/lib/util/encode-info.js +82 -0
- package/vendor/mdast-util-to-markdown/lib/util/format-code-as-indented.js +27 -0
- package/vendor/mdast-util-to-markdown/lib/util/format-heading-as-setext.js +39 -0
- package/vendor/mdast-util-to-markdown/lib/util/format-link-as-autolink.js +39 -0
- package/vendor/mdast-util-to-markdown/lib/util/html-kind.js +63 -0
- package/vendor/mdast-util-to-markdown/lib/util/indent-lines.js +40 -0
- package/vendor/mdast-util-to-markdown/lib/util/pattern-in-scope.js +52 -0
- package/vendor/mdast-util-to-markdown/lib/util/safe.js +263 -0
- package/vendor/mdast-util-to-markdown/lib/util/track.js +55 -0
- package/vendor/mdast-util-to-markdown/license +22 -0
- package/vendor/mdast-util-to-markdown/package.json +88 -0
- package/vendor/mdast-util-to-string/index.js +5 -0
- package/vendor/mdast-util-to-string/lib/index.js +108 -0
- package/vendor/mdast-util-to-string/license +22 -0
- package/vendor/mdast-util-to-string/package.json +78 -0
- package/vendor/micromark/index.js +60 -0
- package/vendor/micromark/lib/compile.js +1068 -0
- package/vendor/micromark/lib/constructs.js +85 -0
- package/vendor/micromark/lib/create-tokenizer.js +615 -0
- package/vendor/micromark/lib/initialize/content.js +79 -0
- package/vendor/micromark/lib/initialize/document.js +370 -0
- package/vendor/micromark/lib/initialize/flow.js +58 -0
- package/vendor/micromark/lib/initialize/text.js +216 -0
- package/vendor/micromark/lib/parse.js +56 -0
- package/vendor/micromark/lib/postprocess.js +18 -0
- package/vendor/micromark/lib/preprocess.js +112 -0
- package/vendor/micromark/license +22 -0
- package/vendor/micromark/package.json +87 -0
- package/vendor/micromark-core-commonmark/index.js +22 -0
- package/vendor/micromark-core-commonmark/lib/attention.js +231 -0
- package/vendor/micromark-core-commonmark/lib/autolink.js +233 -0
- package/vendor/micromark-core-commonmark/lib/blank-line.js +61 -0
- package/vendor/micromark-core-commonmark/lib/block-quote.js +143 -0
- package/vendor/micromark-core-commonmark/lib/character-escape.js +64 -0
- package/vendor/micromark-core-commonmark/lib/character-reference.js +149 -0
- package/vendor/micromark-core-commonmark/lib/code-fenced.js +422 -0
- package/vendor/micromark-core-commonmark/lib/code-indented.js +159 -0
- package/vendor/micromark-core-commonmark/lib/code-text.js +225 -0
- package/vendor/micromark-core-commonmark/lib/content.js +163 -0
- package/vendor/micromark-core-commonmark/lib/definition.js +254 -0
- package/vendor/micromark-core-commonmark/lib/hard-break-escape.js +60 -0
- package/vendor/micromark-core-commonmark/lib/heading-atx.js +191 -0
- package/vendor/micromark-core-commonmark/lib/html-flow.js +827 -0
- package/vendor/micromark-core-commonmark/lib/html-text.js +678 -0
- package/vendor/micromark-core-commonmark/lib/label-end.js +561 -0
- package/vendor/micromark-core-commonmark/lib/label-start-image.js +110 -0
- package/vendor/micromark-core-commonmark/lib/label-start-link.js +63 -0
- package/vendor/micromark-core-commonmark/lib/line-ending.js +33 -0
- package/vendor/micromark-core-commonmark/lib/list.js +213 -0
- package/vendor/micromark-core-commonmark/lib/partial-non-lazy-continuation.js +61 -0
- package/vendor/micromark-core-commonmark/lib/setext-underline.js +187 -0
- package/vendor/micromark-core-commonmark/lib/thematic-break.js +102 -0
- package/vendor/micromark-core-commonmark/license +22 -0
- package/vendor/micromark-core-commonmark/package.json +62 -0
- package/vendor/micromark-extension-gfm-strikethrough/index.js +3 -0
- package/vendor/micromark-extension-gfm-strikethrough/lib/html.js +26 -0
- package/vendor/micromark-extension-gfm-strikethrough/lib/syntax.js +142 -0
- package/vendor/micromark-extension-gfm-strikethrough/license +22 -0
- package/vendor/micromark-extension-gfm-strikethrough/package.json +129 -0
- package/vendor/micromark-extension-gfm-table/index.js +2 -0
- package/vendor/micromark-extension-gfm-table/lib/edit-map.js +222 -0
- package/vendor/micromark-extension-gfm-table/lib/html.js +135 -0
- package/vendor/micromark-extension-gfm-table/lib/infer.js +52 -0
- package/vendor/micromark-extension-gfm-table/lib/syntax.js +846 -0
- package/vendor/micromark-extension-gfm-table/license +22 -0
- package/vendor/micromark-extension-gfm-table/package.json +86 -0
- package/vendor/micromark-extension-gfm-task-list-item/index.js +2 -0
- package/vendor/micromark-extension-gfm-task-list-item/lib/html.js +29 -0
- package/vendor/micromark-extension-gfm-task-list-item/lib/syntax.js +158 -0
- package/vendor/micromark-extension-gfm-task-list-item/license +22 -0
- package/vendor/micromark-extension-gfm-task-list-item/package.json +131 -0
- package/vendor/micromark-factory-destination/index.js +206 -0
- package/vendor/micromark-factory-destination/license +22 -0
- package/vendor/micromark-factory-destination/package.json +57 -0
- package/vendor/micromark-factory-label/index.js +148 -0
- package/vendor/micromark-factory-label/license +22 -0
- package/vendor/micromark-factory-label/package.json +60 -0
- package/vendor/micromark-factory-space/index.js +116 -0
- package/vendor/micromark-factory-space/license +22 -0
- package/vendor/micromark-factory-space/package.json +46 -0
- package/vendor/micromark-factory-title/index.js +158 -0
- package/vendor/micromark-factory-title/license +22 -0
- package/vendor/micromark-factory-title/package.json +58 -0
- package/vendor/micromark-factory-whitespace/index.js +44 -0
- package/vendor/micromark-factory-whitespace/license +22 -0
- package/vendor/micromark-factory-whitespace/package.json +57 -0
- package/vendor/micromark-util-character/index.js +246 -0
- package/vendor/micromark-util-character/license +22 -0
- package/vendor/micromark-util-character/package.json +57 -0
- package/vendor/micromark-util-chunked/index.js +81 -0
- package/vendor/micromark-util-chunked/license +22 -0
- package/vendor/micromark-util-chunked/package.json +57 -0
- package/vendor/micromark-util-classify-character/index.js +27 -0
- package/vendor/micromark-util-classify-character/license +22 -0
- package/vendor/micromark-util-classify-character/package.json +59 -0
- package/vendor/micromark-util-combine-extensions/index.js +143 -0
- package/vendor/micromark-util-combine-extensions/license +22 -0
- package/vendor/micromark-util-combine-extensions/package.json +52 -0
- package/vendor/micromark-util-decode-numeric-character-reference/index.js +32 -0
- package/vendor/micromark-util-decode-numeric-character-reference/license +22 -0
- package/vendor/micromark-util-decode-numeric-character-reference/package.json +59 -0
- package/vendor/micromark-util-decode-string/index.js +45 -0
- package/vendor/micromark-util-decode-string/license +22 -0
- package/vendor/micromark-util-decode-string/package.json +63 -0
- package/vendor/micromark-util-edit-map/index.js +225 -0
- package/vendor/micromark-util-edit-map/license +22 -0
- package/vendor/micromark-util-edit-map/package.json +48 -0
- package/vendor/micromark-util-encode/index.js +33 -0
- package/vendor/micromark-util-encode/license +22 -0
- package/vendor/micromark-util-encode/package.json +47 -0
- package/vendor/micromark-util-html-tag-name/index.js +93 -0
- package/vendor/micromark-util-html-tag-name/license +22 -0
- package/vendor/micromark-util-html-tag-name/package.json +47 -0
- package/vendor/micromark-util-normalize-identifier/index.js +33 -0
- package/vendor/micromark-util-normalize-identifier/license +22 -0
- package/vendor/micromark-util-normalize-identifier/package.json +58 -0
- package/vendor/micromark-util-resolve-all/index.js +32 -0
- package/vendor/micromark-util-resolve-all/license +22 -0
- package/vendor/micromark-util-resolve-all/package.json +48 -0
- package/vendor/micromark-util-sanitize-uri/index.js +107 -0
- package/vendor/micromark-util-sanitize-uri/license +22 -0
- package/vendor/micromark-util-sanitize-uri/package.json +59 -0
- package/vendor/micromark-util-subtokenize/index.js +228 -0
- package/vendor/micromark-util-subtokenize/lib/splice-buffer.js +251 -0
- package/vendor/micromark-util-subtokenize/license +22 -0
- package/vendor/micromark-util-subtokenize/package.json +60 -0
- package/vendor/unist-util-is/index.js +7 -0
- package/vendor/unist-util-is/lib/index.js +296 -0
- package/vendor/unist-util-is/license +22 -0
- package/vendor/unist-util-is/package.json +103 -0
- package/vendor/unist-util-stringify-position/index.js +1 -0
- package/vendor/unist-util-stringify-position/lib/index.js +84 -0
- package/vendor/unist-util-stringify-position/license +22 -0
- package/vendor/unist-util-stringify-position/package.json +80 -0
- package/vendor/unist-util-visit/index.js +2 -0
- package/vendor/unist-util-visit/lib/index.js +312 -0
- package/vendor/unist-util-visit/license +22 -0
- package/vendor/unist-util-visit/package.json +108 -0
- package/vendor/unist-util-visit-parents/index.js +2 -0
- package/vendor/unist-util-visit-parents/lib/color.js +7 -0
- package/vendor/unist-util-visit-parents/lib/index.js +399 -0
- package/vendor/unist-util-visit-parents/license +22 -0
- package/vendor/unist-util-visit-parents/package.json +106 -0
- package/vendor/zwitch/index.js +118 -0
- package/vendor/zwitch/license +22 -0
- package/vendor/zwitch/package.json +72 -0
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import {Info, Join, Options, SafeConfig, State} from 'mdast-util-to-markdown'
|
|
3
|
+
* @import {Nodes} from 'mdast'
|
|
4
|
+
* @import {Enter, FlowParents, PhrasingParents, TrackFields} from './types.js'
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import {phrasing} from 'mdast-util-phrasing'
|
|
8
|
+
import {zwitch} from 'zwitch'
|
|
9
|
+
import {configure} from './configure.js'
|
|
10
|
+
import {handle as handlers} from './handle/index.js'
|
|
11
|
+
import {join} from './join.js'
|
|
12
|
+
import {unsafe} from './unsafe.js'
|
|
13
|
+
import {association} from './util/association.js'
|
|
14
|
+
import {compilePattern} from './util/compile-pattern.js'
|
|
15
|
+
import {containerPhrasing} from './util/container-phrasing.js'
|
|
16
|
+
import {containerFlow} from './util/container-flow.js'
|
|
17
|
+
import {indentLines} from './util/indent-lines.js'
|
|
18
|
+
import {safe} from './util/safe.js'
|
|
19
|
+
import {track} from './util/track.js'
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Turn an mdast syntax tree into markdown.
|
|
23
|
+
*
|
|
24
|
+
* @param {Nodes} tree
|
|
25
|
+
* Tree to serialize.
|
|
26
|
+
* @param {Options | null | undefined} [options]
|
|
27
|
+
* Configuration (optional).
|
|
28
|
+
* @returns {string}
|
|
29
|
+
* Serialized markdown representing `tree`.
|
|
30
|
+
*/
|
|
31
|
+
export function toMarkdown(tree, options) {
|
|
32
|
+
const settings = options || {}
|
|
33
|
+
/** @type {State} */
|
|
34
|
+
const state = {
|
|
35
|
+
associationId: association,
|
|
36
|
+
bulletCurrent: undefined,
|
|
37
|
+
bulletLastUsed: undefined,
|
|
38
|
+
containerPhrasing: containerPhrasingBound,
|
|
39
|
+
containerFlow: containerFlowBound,
|
|
40
|
+
createTracker: track,
|
|
41
|
+
compilePattern,
|
|
42
|
+
enter,
|
|
43
|
+
// @ts-expect-error: GFM / frontmatter are typed in `mdast` but not defined
|
|
44
|
+
// here.
|
|
45
|
+
handlers: {...handlers},
|
|
46
|
+
// @ts-expect-error: add `handle` in a second.
|
|
47
|
+
handle: undefined,
|
|
48
|
+
indentLines,
|
|
49
|
+
indexStack: [],
|
|
50
|
+
join: [...join],
|
|
51
|
+
options: {},
|
|
52
|
+
safe: safeBound,
|
|
53
|
+
stack: [],
|
|
54
|
+
unsafe: [...unsafe]
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
configure(state, settings)
|
|
58
|
+
|
|
59
|
+
if (state.options.tightDefinitions) {
|
|
60
|
+
state.join.push(joinDefinition)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
state.handle = zwitch('type', {
|
|
64
|
+
invalid,
|
|
65
|
+
unknown,
|
|
66
|
+
handlers: state.handlers
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
let result = state.handle(
|
|
70
|
+
phrasing(tree) ? {type: 'root', children: [tree]} : tree,
|
|
71
|
+
undefined,
|
|
72
|
+
state,
|
|
73
|
+
{before: '\n', after: '\n', now: {line: 1, column: 1}, lineShift: 0}
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
if (
|
|
77
|
+
result &&
|
|
78
|
+
result.charCodeAt(result.length - 1) !== 10 &&
|
|
79
|
+
result.charCodeAt(result.length - 1) !== 13
|
|
80
|
+
) {
|
|
81
|
+
result += '\n'
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return result
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Enter a construct.
|
|
88
|
+
*
|
|
89
|
+
* @type {Enter}
|
|
90
|
+
*/
|
|
91
|
+
function enter(name) {
|
|
92
|
+
state.stack.push(name)
|
|
93
|
+
return exit
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Exit a construct.
|
|
97
|
+
*
|
|
98
|
+
* @returns {undefined}
|
|
99
|
+
* Nothing.
|
|
100
|
+
*/
|
|
101
|
+
function exit() {
|
|
102
|
+
state.stack.pop()
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Handle an invalid value that cannot be processed.
|
|
109
|
+
*
|
|
110
|
+
* @param {unknown} value
|
|
111
|
+
* Value.
|
|
112
|
+
* @returns {never}
|
|
113
|
+
* Never.
|
|
114
|
+
* @throws {Error}
|
|
115
|
+
* Always.
|
|
116
|
+
*/
|
|
117
|
+
function invalid(value) {
|
|
118
|
+
throw new Error('Cannot handle value `' + value + '`, expected node')
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Handle an unknown node.
|
|
123
|
+
*
|
|
124
|
+
* @param {unknown} value
|
|
125
|
+
* Value.
|
|
126
|
+
* @returns {never}
|
|
127
|
+
* Never.
|
|
128
|
+
* @throws {Error}
|
|
129
|
+
* Always.
|
|
130
|
+
*/
|
|
131
|
+
function unknown(value) {
|
|
132
|
+
// Always a node.
|
|
133
|
+
const node = /** @type {Nodes} */ (value)
|
|
134
|
+
throw new Error('Cannot handle unknown node `' + node.type + '`')
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Join function for `tightDefinitions` option.
|
|
139
|
+
*
|
|
140
|
+
* @type {Join}
|
|
141
|
+
*/
|
|
142
|
+
function joinDefinition(left, right) {
|
|
143
|
+
// No blank line between adjacent definitions.
|
|
144
|
+
if (left.type === 'definition' && left.type === right.type) {
|
|
145
|
+
return 0
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Serialize the children of a parent that contains phrasing children.
|
|
151
|
+
*
|
|
152
|
+
* These children will be joined flush together.
|
|
153
|
+
*
|
|
154
|
+
* @this {State}
|
|
155
|
+
* Info passed around about the current state.
|
|
156
|
+
* @param {PhrasingParents} parent
|
|
157
|
+
* Parent of flow nodes.
|
|
158
|
+
* @param {Info} info
|
|
159
|
+
* Info on where we are in the document we are generating.
|
|
160
|
+
* @returns {string}
|
|
161
|
+
* Serialized children, joined together.
|
|
162
|
+
*/
|
|
163
|
+
function containerPhrasingBound(parent, info) {
|
|
164
|
+
return containerPhrasing(parent, this, info)
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Serialize the children of a parent that contains flow children.
|
|
169
|
+
*
|
|
170
|
+
* These children will typically be joined by blank lines.
|
|
171
|
+
* What they are joined by exactly is defined by `Join` functions.
|
|
172
|
+
*
|
|
173
|
+
* @this {State}
|
|
174
|
+
* Info passed around about the current state.
|
|
175
|
+
* @param {FlowParents} parent
|
|
176
|
+
* Parent of flow nodes.
|
|
177
|
+
* @param {TrackFields} info
|
|
178
|
+
* Info on where we are in the document we are generating.
|
|
179
|
+
* @returns {string}
|
|
180
|
+
* Serialized children, joined by (blank) lines.
|
|
181
|
+
*/
|
|
182
|
+
function containerFlowBound(parent, info) {
|
|
183
|
+
return containerFlow(parent, this, info)
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Make a string safe for embedding in markdown constructs.
|
|
188
|
+
*
|
|
189
|
+
* In markdown, almost all punctuation characters can, in certain cases,
|
|
190
|
+
* result in something.
|
|
191
|
+
* Whether they do is highly subjective to where they happen and in what
|
|
192
|
+
* they happen.
|
|
193
|
+
*
|
|
194
|
+
* To solve this, `mdast-util-to-markdown` tracks:
|
|
195
|
+
*
|
|
196
|
+
* * Characters before and after something;
|
|
197
|
+
* * What “constructs” we are in.
|
|
198
|
+
*
|
|
199
|
+
* This information is then used by this function to escape or encode
|
|
200
|
+
* special characters.
|
|
201
|
+
*
|
|
202
|
+
* @this {State}
|
|
203
|
+
* Info passed around about the current state.
|
|
204
|
+
* @param {string | null | undefined} value
|
|
205
|
+
* Raw value to make safe.
|
|
206
|
+
* @param {SafeConfig} config
|
|
207
|
+
* Configuration.
|
|
208
|
+
* @returns {string}
|
|
209
|
+
* Serialized markdown safe for embedding.
|
|
210
|
+
*/
|
|
211
|
+
function safeBound(value, config) {
|
|
212
|
+
return safe(this, value, config)
|
|
213
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import {Join} from 'mdast-util-to-markdown'
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import {formatCodeAsIndented} from './util/format-code-as-indented.js'
|
|
6
|
+
import {formatHeadingAsSetext} from './util/format-heading-as-setext.js'
|
|
7
|
+
import {htmlKind} from './util/html-kind.js'
|
|
8
|
+
|
|
9
|
+
/** @type {Array<Join>} */
|
|
10
|
+
export const join = [joinDefaults]
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Default join function.
|
|
14
|
+
*
|
|
15
|
+
* @type {Join}
|
|
16
|
+
*/
|
|
17
|
+
function joinDefaults(left, right, parent, state) {
|
|
18
|
+
// Indented code after list or another indented code.
|
|
19
|
+
if (
|
|
20
|
+
right.type === 'code' &&
|
|
21
|
+
formatCodeAsIndented(right, state) &&
|
|
22
|
+
(left.type === 'list' ||
|
|
23
|
+
(left.type === right.type && formatCodeAsIndented(left, state)))
|
|
24
|
+
) {
|
|
25
|
+
return false
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Join children of a list or an item.
|
|
29
|
+
// In which case, `parent` has a `spread` field.
|
|
30
|
+
if ('spread' in parent && typeof parent.spread === 'boolean') {
|
|
31
|
+
if (
|
|
32
|
+
left.type === 'paragraph' &&
|
|
33
|
+
// Two paragraphs.
|
|
34
|
+
(left.type === right.type ||
|
|
35
|
+
right.type === 'definition' ||
|
|
36
|
+
// Paragraph followed by a setext heading.
|
|
37
|
+
(right.type === 'heading' && formatHeadingAsSetext(right, state)))
|
|
38
|
+
) {
|
|
39
|
+
return
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// HTML that only ends at a blank line followed by something.
|
|
43
|
+
if (left.type === 'html') {
|
|
44
|
+
const kind = htmlKind(left.value)
|
|
45
|
+
if (kind === undefined || kind === 6 || kind === 7) return 1
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// HTML that cannot interrupt a paragraph (kind 7) after one.
|
|
49
|
+
if (left.type === 'paragraph' && right.type === 'html') {
|
|
50
|
+
const kind = htmlKind(right.value)
|
|
51
|
+
if (kind === undefined || kind === 7) return 1
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return parent.spread ? 1 : 0
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import {ConstructName, Unsafe} from 'mdast-util-to-markdown'
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* List of constructs that occur in phrasing (paragraphs, headings), but cannot
|
|
7
|
+
* contain things like attention (emphasis, strong), images, or links.
|
|
8
|
+
* So they sort of cancel each other out.
|
|
9
|
+
* Note: could use a better name.
|
|
10
|
+
*
|
|
11
|
+
* @type {Array<ConstructName>}
|
|
12
|
+
*/
|
|
13
|
+
const fullPhrasingSpans = [
|
|
14
|
+
'autolink',
|
|
15
|
+
'destinationLiteral',
|
|
16
|
+
'destinationRaw',
|
|
17
|
+
'reference',
|
|
18
|
+
'titleQuote',
|
|
19
|
+
'titleApostrophe'
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
/** @type {Array<Unsafe>} */
|
|
23
|
+
export const unsafe = [
|
|
24
|
+
{character: '\t', after: '[\\r\\n]', inConstruct: 'phrasing'},
|
|
25
|
+
{character: '\t', before: '[\\r\\n]', inConstruct: 'phrasing'},
|
|
26
|
+
{
|
|
27
|
+
character: '\t',
|
|
28
|
+
inConstruct: ['codeFencedLangGraveAccent', 'codeFencedLangTilde']
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
character: '\r',
|
|
32
|
+
inConstruct: [
|
|
33
|
+
'codeFencedLangGraveAccent',
|
|
34
|
+
'codeFencedLangTilde',
|
|
35
|
+
'codeFencedMetaGraveAccent',
|
|
36
|
+
'codeFencedMetaTilde',
|
|
37
|
+
'destinationLiteral',
|
|
38
|
+
'headingAtx'
|
|
39
|
+
]
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
character: '\n',
|
|
43
|
+
inConstruct: [
|
|
44
|
+
'codeFencedLangGraveAccent',
|
|
45
|
+
'codeFencedLangTilde',
|
|
46
|
+
'codeFencedMetaGraveAccent',
|
|
47
|
+
'codeFencedMetaTilde',
|
|
48
|
+
'destinationLiteral',
|
|
49
|
+
'headingAtx'
|
|
50
|
+
]
|
|
51
|
+
},
|
|
52
|
+
{character: '\r', before: '[\\r\\n]', inConstruct: 'phrasing'},
|
|
53
|
+
{character: '\r', after: '\\r', inConstruct: 'phrasing'},
|
|
54
|
+
{character: '\n', before: '\\n', inConstruct: 'phrasing'},
|
|
55
|
+
{character: '\n', after: '[\\r\\n]', inConstruct: 'phrasing'},
|
|
56
|
+
{character: ' ', after: '[\\r\\n]', inConstruct: 'phrasing'},
|
|
57
|
+
{character: ' ', before: '[\\r\\n]', inConstruct: 'phrasing'},
|
|
58
|
+
{
|
|
59
|
+
character: ' ',
|
|
60
|
+
inConstruct: ['codeFencedLangGraveAccent', 'codeFencedLangTilde']
|
|
61
|
+
},
|
|
62
|
+
// An exclamation mark can start an image, if it is followed by a link or
|
|
63
|
+
// a link reference.
|
|
64
|
+
{
|
|
65
|
+
character: '!',
|
|
66
|
+
after: '\\[',
|
|
67
|
+
inConstruct: 'phrasing',
|
|
68
|
+
notInConstruct: fullPhrasingSpans
|
|
69
|
+
},
|
|
70
|
+
// A quote can break out of a title.
|
|
71
|
+
{character: '"', inConstruct: 'titleQuote'},
|
|
72
|
+
// A number sign could start an ATX heading if it starts a line.
|
|
73
|
+
{atBreak: true, character: '#'},
|
|
74
|
+
{character: '#', inConstruct: 'headingAtx', after: '(?:[\r\n]|$)'},
|
|
75
|
+
// Dollar sign and percentage are not used in markdown.
|
|
76
|
+
// An ampersand could start a character reference.
|
|
77
|
+
{character: '&', after: '[#A-Za-z]', inConstruct: 'phrasing'},
|
|
78
|
+
// An apostrophe can break out of a title.
|
|
79
|
+
{character: "'", inConstruct: 'titleApostrophe'},
|
|
80
|
+
// A left paren could break out of a destination raw.
|
|
81
|
+
{character: '(', inConstruct: 'destinationRaw'},
|
|
82
|
+
// A left paren followed by `]` could make something into a link or image.
|
|
83
|
+
{
|
|
84
|
+
before: '\\]',
|
|
85
|
+
character: '(',
|
|
86
|
+
inConstruct: 'phrasing',
|
|
87
|
+
notInConstruct: fullPhrasingSpans
|
|
88
|
+
},
|
|
89
|
+
// A right paren could start a list item or break out of a destination
|
|
90
|
+
// raw.
|
|
91
|
+
{atBreak: true, before: '\\d+', character: ')'},
|
|
92
|
+
{character: ')', inConstruct: 'destinationRaw'},
|
|
93
|
+
// An asterisk can start thematic breaks, list items, emphasis, strong.
|
|
94
|
+
{atBreak: true, character: '*', after: '(?:[ \t\r\n*])'},
|
|
95
|
+
{character: '*', inConstruct: 'phrasing', notInConstruct: fullPhrasingSpans},
|
|
96
|
+
// A plus sign could start a list item.
|
|
97
|
+
{atBreak: true, character: '+', after: '(?:[ \t\r\n])'},
|
|
98
|
+
// A dash can start thematic breaks, list items, and setext heading
|
|
99
|
+
// underlines.
|
|
100
|
+
{atBreak: true, character: '-', after: '(?:[ \t\r\n-])'},
|
|
101
|
+
// A dot could start a list item.
|
|
102
|
+
{atBreak: true, before: '\\d+', character: '.', after: '(?:[ \t\r\n]|$)'},
|
|
103
|
+
// Slash, colon, and semicolon are not used in markdown for constructs.
|
|
104
|
+
// A less than can start html (flow or text) or an autolink.
|
|
105
|
+
// HTML could start with an exclamation mark (declaration, cdata, comment),
|
|
106
|
+
// slash (closing tag), question mark (instruction), or a letter (tag).
|
|
107
|
+
// An autolink also starts with a letter.
|
|
108
|
+
// Finally, it could break out of a destination literal.
|
|
109
|
+
{atBreak: true, character: '<', after: '[!/?A-Za-z]'},
|
|
110
|
+
{
|
|
111
|
+
character: '<',
|
|
112
|
+
after: '[!/?A-Za-z]',
|
|
113
|
+
inConstruct: 'phrasing',
|
|
114
|
+
notInConstruct: fullPhrasingSpans
|
|
115
|
+
},
|
|
116
|
+
{character: '<', inConstruct: 'destinationLiteral'},
|
|
117
|
+
// An equals to can start setext heading underlines.
|
|
118
|
+
{atBreak: true, character: '='},
|
|
119
|
+
// A greater than can start block quotes and it can break out of a
|
|
120
|
+
// destination literal.
|
|
121
|
+
{atBreak: true, character: '>'},
|
|
122
|
+
{character: '>', inConstruct: 'destinationLiteral'},
|
|
123
|
+
// Question mark and at sign are not used in markdown for constructs.
|
|
124
|
+
// A left bracket can start definitions, references, labels,
|
|
125
|
+
{atBreak: true, character: '['},
|
|
126
|
+
{character: '[', inConstruct: 'phrasing', notInConstruct: fullPhrasingSpans},
|
|
127
|
+
{character: '[', inConstruct: ['label', 'reference']},
|
|
128
|
+
// A backslash can start an escape (when followed by punctuation) or a
|
|
129
|
+
// hard break (when followed by an eol).
|
|
130
|
+
// Note: typical escapes are handled in `safe`!
|
|
131
|
+
{character: '\\', after: '[\\r\\n]', inConstruct: 'phrasing'},
|
|
132
|
+
// A right bracket can exit labels.
|
|
133
|
+
{character: ']', inConstruct: ['label', 'reference']},
|
|
134
|
+
// Caret is not used in markdown for constructs.
|
|
135
|
+
// An underscore can start emphasis, strong, or a thematic break.
|
|
136
|
+
{atBreak: true, character: '_'},
|
|
137
|
+
{character: '_', inConstruct: 'phrasing', notInConstruct: fullPhrasingSpans},
|
|
138
|
+
// A grave accent can start code (fenced or text), or it can break out of
|
|
139
|
+
// a grave accent code fence.
|
|
140
|
+
{atBreak: true, character: '`'},
|
|
141
|
+
{
|
|
142
|
+
character: '`',
|
|
143
|
+
inConstruct: ['codeFencedLangGraveAccent', 'codeFencedMetaGraveAccent']
|
|
144
|
+
},
|
|
145
|
+
{character: '`', inConstruct: 'phrasing', notInConstruct: fullPhrasingSpans},
|
|
146
|
+
// Left brace, vertical bar, right brace are not used in markdown for
|
|
147
|
+
// constructs.
|
|
148
|
+
// A tilde can start code (fenced).
|
|
149
|
+
{atBreak: true, character: '~'},
|
|
150
|
+
{character: '<', inConstruct: 'autolink'},
|
|
151
|
+
{character: '>', inConstruct: 'autolink'},
|
|
152
|
+
{character: '\u007F', inConstruct: 'autolink'}
|
|
153
|
+
]
|
|
154
|
+
|
|
155
|
+
// Also the low ASCII control characters including space.
|
|
156
|
+
let code = -1
|
|
157
|
+
|
|
158
|
+
while (++code < 33) {
|
|
159
|
+
unsafe.push({character: String.fromCharCode(code), inConstruct: 'autolink'})
|
|
160
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import {AssociationId} from '../types.js'
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import {decodeString} from 'micromark-util-decode-string'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Get an identifier from an association to match it to others.
|
|
9
|
+
*
|
|
10
|
+
* Associations are nodes that match to something else through an ID:
|
|
11
|
+
* <https://github.com/syntax-tree/mdast#association>.
|
|
12
|
+
*
|
|
13
|
+
* The `label` of an association is the string value: character escapes and
|
|
14
|
+
* references work, and casing is intact.
|
|
15
|
+
* The `identifier` is used to match one association to another:
|
|
16
|
+
* controversially, character escapes and references don’t work in this
|
|
17
|
+
* matching: `©` does not match `©`, and `\+` does not match `+`.
|
|
18
|
+
*
|
|
19
|
+
* But casing is ignored (and whitespace) is trimmed and collapsed: ` A\nb`
|
|
20
|
+
* matches `a b`.
|
|
21
|
+
* So, we do prefer the label when figuring out how we’re going to serialize:
|
|
22
|
+
* it has whitespace, casing, and we can ignore most useless character
|
|
23
|
+
* escapes and all character references.
|
|
24
|
+
*
|
|
25
|
+
* @type {AssociationId}
|
|
26
|
+
*/
|
|
27
|
+
export function association(node) {
|
|
28
|
+
if (node.label || !node.identifier) {
|
|
29
|
+
return node.label || ''
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return decodeString(node.identifier)
|
|
33
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get the first character of a value.
|
|
3
|
+
*
|
|
4
|
+
* Is aware of astral characters (such as emoji).
|
|
5
|
+
*
|
|
6
|
+
* @param {string} value
|
|
7
|
+
* Value.
|
|
8
|
+
* @returns {string}
|
|
9
|
+
* First character; empty if `value` is empty.
|
|
10
|
+
*/
|
|
11
|
+
export function firstCharacter(value) {
|
|
12
|
+
const code = value.codePointAt(0)
|
|
13
|
+
return code === undefined ? '' : String.fromCodePoint(code)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Get the last character of a value.
|
|
18
|
+
*
|
|
19
|
+
* Is aware of astral characters (such as emoji).
|
|
20
|
+
*
|
|
21
|
+
* @param {string} value
|
|
22
|
+
* Value.
|
|
23
|
+
* @returns {string}
|
|
24
|
+
* Last character; empty if `value` is empty.
|
|
25
|
+
*/
|
|
26
|
+
export function lastCharacter(value) {
|
|
27
|
+
// Only a surrogate pair gives a code point above the BMP.
|
|
28
|
+
const code = value.codePointAt(value.length - 2)
|
|
29
|
+
return code !== undefined && code > 0xff_ff
|
|
30
|
+
? value.slice(-2)
|
|
31
|
+
: value.slice(-1)
|
|
32
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import {Options, State} from 'mdast-util-to-markdown'
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Checks the preferred ordered list bullet option.
|
|
7
|
+
*
|
|
8
|
+
* @param {State} state
|
|
9
|
+
* Info passed around.
|
|
10
|
+
* @returns {Exclude<Options['bulletOrdered'], null | undefined>}
|
|
11
|
+
* Preferred ordered list bullet.
|
|
12
|
+
*/
|
|
13
|
+
export function checkBulletOrdered(state) {
|
|
14
|
+
const marker = state.options.bulletOrdered || '.'
|
|
15
|
+
|
|
16
|
+
if (marker !== '.' && marker !== ')') {
|
|
17
|
+
throw new Error(
|
|
18
|
+
'Cannot serialize items with `' +
|
|
19
|
+
marker +
|
|
20
|
+
'` for `options.bulletOrdered`, expected `.` or `)`'
|
|
21
|
+
)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return marker
|
|
25
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import {Options, State} from 'mdast-util-to-markdown'
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import {checkBullet} from './check-bullet.js'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Checks the preferred alternate list bullet option.
|
|
9
|
+
*
|
|
10
|
+
* @param {State} state
|
|
11
|
+
* Info passed around.
|
|
12
|
+
* @returns {Exclude<Options['bullet'], null | undefined>}
|
|
13
|
+
* Preferred alternate list bullet.
|
|
14
|
+
*/
|
|
15
|
+
export function checkBulletOther(state) {
|
|
16
|
+
const bullet = checkBullet(state)
|
|
17
|
+
const bulletOther = state.options.bulletOther
|
|
18
|
+
|
|
19
|
+
if (!bulletOther) {
|
|
20
|
+
return bullet === '*' ? '-' : '*'
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (bulletOther !== '*' && bulletOther !== '+' && bulletOther !== '-') {
|
|
24
|
+
throw new Error(
|
|
25
|
+
'Cannot serialize items with `' +
|
|
26
|
+
bulletOther +
|
|
27
|
+
'` for `options.bulletOther`, expected `*`, `+`, or `-`'
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (bulletOther === bullet) {
|
|
32
|
+
throw new Error(
|
|
33
|
+
'Expected `bullet` (`' +
|
|
34
|
+
bullet +
|
|
35
|
+
'`) and `bulletOther` (`' +
|
|
36
|
+
bulletOther +
|
|
37
|
+
'`) to be different'
|
|
38
|
+
)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return bulletOther
|
|
42
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import {Options, State} from 'mdast-util-to-markdown'
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Checks the preferred list bullet option.
|
|
7
|
+
*
|
|
8
|
+
* @param {State} state
|
|
9
|
+
* Info passed around.
|
|
10
|
+
* @returns {Exclude<Options['bullet'], null | undefined>}
|
|
11
|
+
* Preferred list bullet.
|
|
12
|
+
*/
|
|
13
|
+
export function checkBullet(state) {
|
|
14
|
+
const marker = state.options.bullet || '*'
|
|
15
|
+
|
|
16
|
+
if (marker !== '*' && marker !== '+' && marker !== '-') {
|
|
17
|
+
throw new Error(
|
|
18
|
+
'Cannot serialize items with `' +
|
|
19
|
+
marker +
|
|
20
|
+
'` for `options.bullet`, expected `*`, `+`, or `-`'
|
|
21
|
+
)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return marker
|
|
25
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import {Options, State} from 'mdast-util-to-markdown'
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Checks the preferred emphasis option.
|
|
7
|
+
*
|
|
8
|
+
* @param {State} state
|
|
9
|
+
* Info passed around.
|
|
10
|
+
* @returns {Exclude<Options['emphasis'], null | undefined>}
|
|
11
|
+
* Preferred emphasis marker.
|
|
12
|
+
*/
|
|
13
|
+
export function checkEmphasis(state) {
|
|
14
|
+
const marker = state.options.emphasis || '*'
|
|
15
|
+
|
|
16
|
+
if (marker !== '*' && marker !== '_') {
|
|
17
|
+
throw new Error(
|
|
18
|
+
'Cannot serialize emphasis with `' +
|
|
19
|
+
marker +
|
|
20
|
+
'` for `options.emphasis`, expected `*`, or `_`'
|
|
21
|
+
)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return marker
|
|
25
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import {Options, State} from 'mdast-util-to-markdown'
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Checks the preferred fence option.
|
|
7
|
+
*
|
|
8
|
+
* @param {State} state
|
|
9
|
+
* Info passed around.
|
|
10
|
+
* @returns {Exclude<Options['fence'], null | undefined>}
|
|
11
|
+
* Preferred fence marker.
|
|
12
|
+
*/
|
|
13
|
+
export function checkFence(state) {
|
|
14
|
+
const marker = state.options.fence || '`'
|
|
15
|
+
|
|
16
|
+
if (marker !== '`' && marker !== '~') {
|
|
17
|
+
throw new Error(
|
|
18
|
+
'Cannot serialize code with `' +
|
|
19
|
+
marker +
|
|
20
|
+
'` for `options.fence`, expected `` ` `` or `~`'
|
|
21
|
+
)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return marker
|
|
25
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import {Options, State} from 'mdast-util-to-markdown'
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Checks the preferred list item indent option.
|
|
7
|
+
*
|
|
8
|
+
* @param {State} state
|
|
9
|
+
* Info passed around.
|
|
10
|
+
* @returns {Exclude<Options['listItemIndent'], null | undefined>}
|
|
11
|
+
* Preferred list item indent.
|
|
12
|
+
*/
|
|
13
|
+
export function checkListItemIndent(state) {
|
|
14
|
+
const style = state.options.listItemIndent || 'one'
|
|
15
|
+
|
|
16
|
+
if (style !== 'tab' && style !== 'one' && style !== 'mixed') {
|
|
17
|
+
throw new Error(
|
|
18
|
+
'Cannot serialize items with `' +
|
|
19
|
+
style +
|
|
20
|
+
'` for `options.listItemIndent`, expected `tab`, `one`, or `mixed`'
|
|
21
|
+
)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return style
|
|
25
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import {Options, State} from 'mdast-util-to-markdown'
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Checks the preferred quote option.
|
|
7
|
+
*
|
|
8
|
+
* @param {State} state
|
|
9
|
+
* Info passed around.
|
|
10
|
+
* @returns {Exclude<Options['quote'], null | undefined>}
|
|
11
|
+
* Preferred quote.
|
|
12
|
+
*/
|
|
13
|
+
export function checkQuote(state) {
|
|
14
|
+
const marker = state.options.quote || '"'
|
|
15
|
+
|
|
16
|
+
if (marker !== '"' && marker !== "'") {
|
|
17
|
+
throw new Error(
|
|
18
|
+
'Cannot serialize title with `' +
|
|
19
|
+
marker +
|
|
20
|
+
'` for `options.quote`, expected `"`, or `\'`'
|
|
21
|
+
)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return marker
|
|
25
|
+
}
|