@tinta-lang/syntax 0.0.0-stage → 0.1.0-dev.0
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/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 +280 -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
- package/README.md +0 -3
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
// To do: next major: remove.
|
|
2
|
+
/**
|
|
3
|
+
* @typedef {Options} MarkdownTableOptions
|
|
4
|
+
* Configuration.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @typedef Options
|
|
9
|
+
* Configuration.
|
|
10
|
+
* @property {boolean | null | undefined} [alignDelimiters=true]
|
|
11
|
+
* Whether to align the delimiters (default: `true`);
|
|
12
|
+
* they are aligned by default:
|
|
13
|
+
*
|
|
14
|
+
* ```markdown
|
|
15
|
+
* | Alpha | B |
|
|
16
|
+
* | ----- | ----- |
|
|
17
|
+
* | C | Delta |
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* Pass `false` to make them staggered:
|
|
21
|
+
*
|
|
22
|
+
* ```markdown
|
|
23
|
+
* | Alpha | B |
|
|
24
|
+
* | - | - |
|
|
25
|
+
* | C | Delta |
|
|
26
|
+
* ```
|
|
27
|
+
* @property {ReadonlyArray<string | null | undefined> | string | null | undefined} [align]
|
|
28
|
+
* How to align columns (default: `''`);
|
|
29
|
+
* one style for all columns or styles for their respective columns;
|
|
30
|
+
* each style is either `'l'` (left), `'r'` (right), or `'c'` (center);
|
|
31
|
+
* other values are treated as `''`, which doesn’t place the colon in the
|
|
32
|
+
* alignment row but does align left;
|
|
33
|
+
* *only the lowercased first character is used, so `Right` is fine.*
|
|
34
|
+
* @property {boolean | null | undefined} [delimiterEnd=true]
|
|
35
|
+
* Whether to end each row with the delimiter (default: `true`).
|
|
36
|
+
*
|
|
37
|
+
* > 👉 **Note**: please don’t use this: it could create fragile structures
|
|
38
|
+
* > that aren’t understandable to some markdown parsers.
|
|
39
|
+
*
|
|
40
|
+
* When `true`, there are ending delimiters:
|
|
41
|
+
*
|
|
42
|
+
* ```markdown
|
|
43
|
+
* | Alpha | B |
|
|
44
|
+
* | ----- | ----- |
|
|
45
|
+
* | C | Delta |
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* When `false`, there are no ending delimiters:
|
|
49
|
+
*
|
|
50
|
+
* ```markdown
|
|
51
|
+
* | Alpha | B
|
|
52
|
+
* | ----- | -----
|
|
53
|
+
* | C | Delta
|
|
54
|
+
* ```
|
|
55
|
+
* @property {boolean | null | undefined} [delimiterStart=true]
|
|
56
|
+
* Whether to begin each row with the delimiter (default: `true`).
|
|
57
|
+
*
|
|
58
|
+
* > 👉 **Note**: please don’t use this: it could create fragile structures
|
|
59
|
+
* > that aren’t understandable to some markdown parsers.
|
|
60
|
+
*
|
|
61
|
+
* When `true`, there are starting delimiters:
|
|
62
|
+
*
|
|
63
|
+
* ```markdown
|
|
64
|
+
* | Alpha | B |
|
|
65
|
+
* | ----- | ----- |
|
|
66
|
+
* | C | Delta |
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
69
|
+
* When `false`, there are no starting delimiters:
|
|
70
|
+
*
|
|
71
|
+
* ```markdown
|
|
72
|
+
* Alpha | B |
|
|
73
|
+
* ----- | ----- |
|
|
74
|
+
* C | Delta |
|
|
75
|
+
* ```
|
|
76
|
+
* @property {boolean | null | undefined} [padding=true]
|
|
77
|
+
* Whether to add a space of padding between delimiters and cells
|
|
78
|
+
* (default: `true`).
|
|
79
|
+
*
|
|
80
|
+
* When `true`, there is padding:
|
|
81
|
+
*
|
|
82
|
+
* ```markdown
|
|
83
|
+
* | Alpha | B |
|
|
84
|
+
* | ----- | ----- |
|
|
85
|
+
* | C | Delta |
|
|
86
|
+
* ```
|
|
87
|
+
*
|
|
88
|
+
* When `false`, there is no padding:
|
|
89
|
+
*
|
|
90
|
+
* ```markdown
|
|
91
|
+
* |Alpha|B |
|
|
92
|
+
* |-----|-----|
|
|
93
|
+
* |C |Delta|
|
|
94
|
+
* ```
|
|
95
|
+
* @property {((value: string) => number) | null | undefined} [stringLength]
|
|
96
|
+
* Function to detect the length of table cell content (optional);
|
|
97
|
+
* this is used when aligning the delimiters (`|`) between table cells;
|
|
98
|
+
* full-width characters and emoji mess up delimiter alignment when viewing
|
|
99
|
+
* the markdown source;
|
|
100
|
+
* to fix this, you can pass this function,
|
|
101
|
+
* which receives the cell content and returns its “visible” size;
|
|
102
|
+
* note that what is and isn’t visible depends on where the text is displayed.
|
|
103
|
+
*
|
|
104
|
+
* Without such a function, the following:
|
|
105
|
+
*
|
|
106
|
+
* ```js
|
|
107
|
+
* markdownTable([
|
|
108
|
+
* ['Alpha', 'Bravo'],
|
|
109
|
+
* ['中文', 'Charlie'],
|
|
110
|
+
* ['👩❤️👩', 'Delta']
|
|
111
|
+
* ])
|
|
112
|
+
* ```
|
|
113
|
+
*
|
|
114
|
+
* Yields:
|
|
115
|
+
*
|
|
116
|
+
* ```markdown
|
|
117
|
+
* | Alpha | Bravo |
|
|
118
|
+
* | - | - |
|
|
119
|
+
* | 中文 | Charlie |
|
|
120
|
+
* | 👩❤️👩 | Delta |
|
|
121
|
+
* ```
|
|
122
|
+
*
|
|
123
|
+
* With [`string-width`](https://github.com/sindresorhus/string-width):
|
|
124
|
+
*
|
|
125
|
+
* ```js
|
|
126
|
+
* import stringWidth from 'string-width'
|
|
127
|
+
*
|
|
128
|
+
* markdownTable(
|
|
129
|
+
* [
|
|
130
|
+
* ['Alpha', 'Bravo'],
|
|
131
|
+
* ['中文', 'Charlie'],
|
|
132
|
+
* ['👩❤️👩', 'Delta']
|
|
133
|
+
* ],
|
|
134
|
+
* {stringLength: stringWidth}
|
|
135
|
+
* )
|
|
136
|
+
* ```
|
|
137
|
+
*
|
|
138
|
+
* Yields:
|
|
139
|
+
*
|
|
140
|
+
* ```markdown
|
|
141
|
+
* | Alpha | Bravo |
|
|
142
|
+
* | ----- | ------- |
|
|
143
|
+
* | 中文 | Charlie |
|
|
144
|
+
* | 👩❤️👩 | Delta |
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* @param {string} value
|
|
150
|
+
* Cell value.
|
|
151
|
+
* @returns {number}
|
|
152
|
+
* Cell size.
|
|
153
|
+
*/
|
|
154
|
+
function defaultStringLength(value) {
|
|
155
|
+
return value.length
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Generate a markdown
|
|
160
|
+
* ([GFM](https://docs.github.com/en/github/writing-on-github/working-with-advanced-formatting/organizing-information-with-tables))
|
|
161
|
+
* table.
|
|
162
|
+
*
|
|
163
|
+
* @param {ReadonlyArray<ReadonlyArray<string | null | undefined>>} table
|
|
164
|
+
* Table data (matrix of strings).
|
|
165
|
+
* @param {Readonly<Options> | null | undefined} [options]
|
|
166
|
+
* Configuration (optional).
|
|
167
|
+
* @returns {string}
|
|
168
|
+
* Result.
|
|
169
|
+
*/
|
|
170
|
+
export function markdownTable(table, options) {
|
|
171
|
+
const settings = options || {}
|
|
172
|
+
// To do: next major: change to spread.
|
|
173
|
+
const align = (settings.align || []).concat()
|
|
174
|
+
const stringLength = settings.stringLength || defaultStringLength
|
|
175
|
+
/** @type {Array<number>} Character codes as symbols for alignment per column. */
|
|
176
|
+
const alignments = []
|
|
177
|
+
/** @type {Array<Array<string>>} Cells per row. */
|
|
178
|
+
const cellMatrix = []
|
|
179
|
+
/** @type {Array<Array<number>>} Sizes of each cell per row. */
|
|
180
|
+
const sizeMatrix = []
|
|
181
|
+
/** @type {Array<number>} */
|
|
182
|
+
const longestCellByColumn = []
|
|
183
|
+
let mostCellsPerRow = 0
|
|
184
|
+
let rowIndex = -1
|
|
185
|
+
|
|
186
|
+
// This is a superfluous loop if we don’t align delimiters, but otherwise we’d
|
|
187
|
+
// do superfluous work when aligning, so optimize for aligning.
|
|
188
|
+
while (++rowIndex < table.length) {
|
|
189
|
+
/** @type {Array<string>} */
|
|
190
|
+
const row = []
|
|
191
|
+
/** @type {Array<number>} */
|
|
192
|
+
const sizes = []
|
|
193
|
+
let columnIndex = -1
|
|
194
|
+
|
|
195
|
+
if (table[rowIndex].length > mostCellsPerRow) {
|
|
196
|
+
mostCellsPerRow = table[rowIndex].length
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
while (++columnIndex < table[rowIndex].length) {
|
|
200
|
+
const cell = serialize(table[rowIndex][columnIndex])
|
|
201
|
+
|
|
202
|
+
if (settings.alignDelimiters !== false) {
|
|
203
|
+
const size = stringLength(cell)
|
|
204
|
+
sizes[columnIndex] = size
|
|
205
|
+
|
|
206
|
+
if (
|
|
207
|
+
longestCellByColumn[columnIndex] === undefined ||
|
|
208
|
+
size > longestCellByColumn[columnIndex]
|
|
209
|
+
) {
|
|
210
|
+
longestCellByColumn[columnIndex] = size
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
row.push(cell)
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
cellMatrix[rowIndex] = row
|
|
218
|
+
sizeMatrix[rowIndex] = sizes
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// Figure out which alignments to use.
|
|
222
|
+
let columnIndex = -1
|
|
223
|
+
|
|
224
|
+
if (typeof align === 'object' && 'length' in align) {
|
|
225
|
+
while (++columnIndex < mostCellsPerRow) {
|
|
226
|
+
alignments[columnIndex] = toAlignment(align[columnIndex])
|
|
227
|
+
}
|
|
228
|
+
} else {
|
|
229
|
+
const code = toAlignment(align)
|
|
230
|
+
|
|
231
|
+
while (++columnIndex < mostCellsPerRow) {
|
|
232
|
+
alignments[columnIndex] = code
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// Inject the alignment row.
|
|
237
|
+
columnIndex = -1
|
|
238
|
+
/** @type {Array<string>} */
|
|
239
|
+
const row = []
|
|
240
|
+
/** @type {Array<number>} */
|
|
241
|
+
const sizes = []
|
|
242
|
+
|
|
243
|
+
while (++columnIndex < mostCellsPerRow) {
|
|
244
|
+
const code = alignments[columnIndex]
|
|
245
|
+
let before = ''
|
|
246
|
+
let after = ''
|
|
247
|
+
|
|
248
|
+
if (code === 99 /* `c` */) {
|
|
249
|
+
before = ':'
|
|
250
|
+
after = ':'
|
|
251
|
+
} else if (code === 108 /* `l` */) {
|
|
252
|
+
before = ':'
|
|
253
|
+
} else if (code === 114 /* `r` */) {
|
|
254
|
+
after = ':'
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// There *must* be at least one hyphen-minus in each alignment cell.
|
|
258
|
+
let size =
|
|
259
|
+
settings.alignDelimiters === false
|
|
260
|
+
? 1
|
|
261
|
+
: Math.max(
|
|
262
|
+
1,
|
|
263
|
+
longestCellByColumn[columnIndex] - before.length - after.length
|
|
264
|
+
)
|
|
265
|
+
|
|
266
|
+
const cell = before + '-'.repeat(size) + after
|
|
267
|
+
|
|
268
|
+
if (settings.alignDelimiters !== false) {
|
|
269
|
+
size = before.length + size + after.length
|
|
270
|
+
|
|
271
|
+
if (size > longestCellByColumn[columnIndex]) {
|
|
272
|
+
longestCellByColumn[columnIndex] = size
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
sizes[columnIndex] = size
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
row[columnIndex] = cell
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// Inject the alignment row.
|
|
282
|
+
cellMatrix.splice(1, 0, row)
|
|
283
|
+
sizeMatrix.splice(1, 0, sizes)
|
|
284
|
+
|
|
285
|
+
rowIndex = -1
|
|
286
|
+
/** @type {Array<string>} */
|
|
287
|
+
const lines = []
|
|
288
|
+
|
|
289
|
+
while (++rowIndex < cellMatrix.length) {
|
|
290
|
+
const row = cellMatrix[rowIndex]
|
|
291
|
+
const sizes = sizeMatrix[rowIndex]
|
|
292
|
+
columnIndex = -1
|
|
293
|
+
/** @type {Array<string>} */
|
|
294
|
+
const line = []
|
|
295
|
+
|
|
296
|
+
while (++columnIndex < mostCellsPerRow) {
|
|
297
|
+
const cell = row[columnIndex] || ''
|
|
298
|
+
let before = ''
|
|
299
|
+
let after = ''
|
|
300
|
+
|
|
301
|
+
if (settings.alignDelimiters !== false) {
|
|
302
|
+
const size =
|
|
303
|
+
longestCellByColumn[columnIndex] - (sizes[columnIndex] || 0)
|
|
304
|
+
const code = alignments[columnIndex]
|
|
305
|
+
|
|
306
|
+
if (code === 114 /* `r` */) {
|
|
307
|
+
before = ' '.repeat(size)
|
|
308
|
+
} else if (code === 99 /* `c` */) {
|
|
309
|
+
if (size % 2) {
|
|
310
|
+
before = ' '.repeat(size / 2 + 0.5)
|
|
311
|
+
after = ' '.repeat(size / 2 - 0.5)
|
|
312
|
+
} else {
|
|
313
|
+
before = ' '.repeat(size / 2)
|
|
314
|
+
after = before
|
|
315
|
+
}
|
|
316
|
+
} else {
|
|
317
|
+
after = ' '.repeat(size)
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
if (settings.delimiterStart !== false && !columnIndex) {
|
|
322
|
+
line.push('|')
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
if (
|
|
326
|
+
settings.padding !== false &&
|
|
327
|
+
// Don’t add the opening space if we’re not aligning and the cell is
|
|
328
|
+
// empty: there will be a closing space.
|
|
329
|
+
!(settings.alignDelimiters === false && cell === '') &&
|
|
330
|
+
(settings.delimiterStart !== false || columnIndex)
|
|
331
|
+
) {
|
|
332
|
+
line.push(' ')
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
if (settings.alignDelimiters !== false) {
|
|
336
|
+
line.push(before)
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
line.push(cell)
|
|
340
|
+
|
|
341
|
+
if (settings.alignDelimiters !== false) {
|
|
342
|
+
line.push(after)
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
if (settings.padding !== false) {
|
|
346
|
+
line.push(' ')
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
if (
|
|
350
|
+
settings.delimiterEnd !== false ||
|
|
351
|
+
columnIndex !== mostCellsPerRow - 1
|
|
352
|
+
) {
|
|
353
|
+
line.push('|')
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
lines.push(
|
|
358
|
+
settings.delimiterEnd === false
|
|
359
|
+
? line.join('').replace(/ +$/, '')
|
|
360
|
+
: line.join('')
|
|
361
|
+
)
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
return lines.join('\n')
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* @param {string | null | undefined} [value]
|
|
369
|
+
* Value to serialize.
|
|
370
|
+
* @returns {string}
|
|
371
|
+
* Result.
|
|
372
|
+
*/
|
|
373
|
+
function serialize(value) {
|
|
374
|
+
return value === null || value === undefined ? '' : String(value)
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* @param {string | null | undefined} value
|
|
379
|
+
* Value.
|
|
380
|
+
* @returns {number}
|
|
381
|
+
* Alignment.
|
|
382
|
+
*/
|
|
383
|
+
function toAlignment(value) {
|
|
384
|
+
const code = typeof value === 'string' ? value.codePointAt(0) : 0
|
|
385
|
+
|
|
386
|
+
return code === 67 /* `C` */ || code === 99 /* `c` */
|
|
387
|
+
? 99 /* `c` */
|
|
388
|
+
: code === 76 /* `L` */ || code === 108 /* `l` */
|
|
389
|
+
? 108 /* `l` */
|
|
390
|
+
: code === 82 /* `R` */ || code === 114 /* `r` */
|
|
391
|
+
? 114 /* `r` */
|
|
392
|
+
: 0
|
|
393
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
(The MIT License)
|
|
2
|
+
|
|
3
|
+
Copyright (c) Titus Wormer <tituswormer@gmail.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
'Software'), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
20
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
22
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
{
|
|
2
|
+
"author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
|
|
3
|
+
"bugs": "https://github.com/wooorm/markdown-table/issues",
|
|
4
|
+
"contributors": [
|
|
5
|
+
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
|
|
6
|
+
],
|
|
7
|
+
"description": "Generate a markdown (GFM) table",
|
|
8
|
+
"devDependencies": {
|
|
9
|
+
"@types/node": "^22.0.0",
|
|
10
|
+
"c8": "^10.0.0",
|
|
11
|
+
"chalk": "^5.0.0",
|
|
12
|
+
"prettier": "^3.0.0",
|
|
13
|
+
"remark-cli": "^12.0.0",
|
|
14
|
+
"remark-preset-wooorm": "^10.0.0",
|
|
15
|
+
"strip-ansi": "^7.0.0",
|
|
16
|
+
"type-coverage": "^2.0.0",
|
|
17
|
+
"typescript": "^5.0.0",
|
|
18
|
+
"xo": "^0.59.0"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"index.d.ts.map",
|
|
22
|
+
"index.d.ts",
|
|
23
|
+
"index.js"
|
|
24
|
+
],
|
|
25
|
+
"funding": {
|
|
26
|
+
"type": "github",
|
|
27
|
+
"url": "https://github.com/sponsors/wooorm"
|
|
28
|
+
},
|
|
29
|
+
"keywords": [
|
|
30
|
+
"align",
|
|
31
|
+
"markdown",
|
|
32
|
+
"rows",
|
|
33
|
+
"table",
|
|
34
|
+
"tabular",
|
|
35
|
+
"text"
|
|
36
|
+
],
|
|
37
|
+
"license": "MIT",
|
|
38
|
+
"main": "index.js",
|
|
39
|
+
"name": "markdown-table",
|
|
40
|
+
"prettier": {
|
|
41
|
+
"bracketSpacing": false,
|
|
42
|
+
"semi": false,
|
|
43
|
+
"singleQuote": true,
|
|
44
|
+
"tabWidth": 2,
|
|
45
|
+
"trailingComma": "none",
|
|
46
|
+
"useTabs": false
|
|
47
|
+
},
|
|
48
|
+
"remarkConfig": {
|
|
49
|
+
"plugins": [
|
|
50
|
+
"remark-preset-wooorm"
|
|
51
|
+
]
|
|
52
|
+
},
|
|
53
|
+
"repository": "wooorm/markdown-table",
|
|
54
|
+
"scripts": {
|
|
55
|
+
"build": "tsc --build --clean && tsc --build && type-coverage",
|
|
56
|
+
"format": "remark --frail --output --quiet -- . && prettier --log-level warn --write -- . && xo --fix",
|
|
57
|
+
"test-api": "node --conditions development test.js",
|
|
58
|
+
"test-coverage": "c8 --100 --check-coverage --reporter lcov -- npm run test-api",
|
|
59
|
+
"test": "npm run build && npm run format && npm run test-coverage"
|
|
60
|
+
},
|
|
61
|
+
"sideEffects": false,
|
|
62
|
+
"typeCoverage": {
|
|
63
|
+
"atLeast": 100,
|
|
64
|
+
"detail": true,
|
|
65
|
+
"strict": true
|
|
66
|
+
},
|
|
67
|
+
"types": "index.d.ts",
|
|
68
|
+
"type": "module",
|
|
69
|
+
"version": "3.0.4",
|
|
70
|
+
"xo": {
|
|
71
|
+
"prettier": true,
|
|
72
|
+
"rules": {
|
|
73
|
+
"complexity": "off",
|
|
74
|
+
"unicorn/prefer-switch": "off"
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|