@adobe/helix-markdown-support 5.0.10 → 6.0.1

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.
@@ -1,11 +1,11 @@
1
1
  version: 2.1
2
2
  executors:
3
- node16:
3
+ node18:
4
4
  docker:
5
- - image: cimg/node:16.16
5
+ - image: cimg/node:18.2
6
6
 
7
7
  orbs:
8
- codecov: codecov/codecov@3.2.3
8
+ codecov: codecov/codecov@3.2.4
9
9
 
10
10
  commands:
11
11
  setup:
@@ -20,7 +20,7 @@ commands:
20
20
 
21
21
  jobs:
22
22
  build:
23
- executor: node16
23
+ executor: node18
24
24
 
25
25
  steps:
26
26
  - setup
@@ -10,10 +10,10 @@ jobs:
10
10
  if: "!contains(github.event.head_commit.message, '[skip ci]')"
11
11
  steps:
12
12
  - uses: actions/checkout@v3
13
- - name: Use Node.js 14.x
13
+ - name: Use Node.js 18.x
14
14
  uses: actions/setup-node@v3
15
15
  with:
16
- node-version: '14.x'
16
+ node-version: '18.x'
17
17
  - run: npm install
18
18
  - run: npm test
19
19
  - run: npm run semantic-release
package/CHANGELOG.md CHANGED
@@ -1,3 +1,22 @@
1
+ ## [6.0.1](https://github.com/adobe/helix-markdown-support/compare/v6.0.0...v6.0.1) (2023-01-18)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **deps:** update dependency @adobe/remark-gridtables to v1.0.1 ([#165](https://github.com/adobe/helix-markdown-support/issues/165)) ([9f49d14](https://github.com/adobe/helix-markdown-support/commit/9f49d14a38b16a801d07b7be55aa75f7ed69fd14))
7
+
8
+ # [6.0.0](https://github.com/adobe/helix-markdown-support/compare/v5.0.10...v6.0.0) (2022-11-03)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * remove gridtables export ([#153](https://github.com/adobe/helix-markdown-support/issues/153)) ([90d610b](https://github.com/adobe/helix-markdown-support/commit/90d610b06c92a61279f9641fcda321553e24cfc3))
14
+
15
+
16
+ ### BREAKING CHANGES
17
+
18
+ * gridtables export (re)moved. use @adobe/remark-gridtables and @adobe/mdast-util-gridtables instead.
19
+
1
20
  ## [5.0.10](https://github.com/adobe/helix-markdown-support/compare/v5.0.9...v5.0.10) (2022-10-05)
2
21
 
3
22
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/helix-markdown-support",
3
- "version": "5.0.10",
3
+ "version": "6.0.1",
4
4
  "description": "Helix Markdown Support",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -22,15 +22,12 @@
22
22
  "main": "src/index.js",
23
23
  "exports": {
24
24
  ".": "./src/index.js",
25
- "./gridtable": "./src/gridtable/index.js",
26
25
  "./matter": "./src/matter/index.js"
27
26
  },
28
27
  "dependencies": {
29
- "hast-util-to-html": "8.0.3",
28
+ "hast-util-to-html": "8.0.4",
30
29
  "js-yaml": "4.1.0",
31
- "mdast-util-from-markdown": "1.2.0",
32
- "mdast-util-to-hast": "12.2.4",
33
- "mdast-util-to-markdown": "1.3.0",
30
+ "mdast-util-to-hast": "12.2.5",
34
31
  "micromark-util-character": "1.1.0",
35
32
  "micromark-util-symbol": "1.0.1",
36
33
  "unist-util-find": "1.0.2",
@@ -51,17 +48,18 @@
51
48
  },
52
49
  "devDependencies": {
53
50
  "@adobe/eslint-config-helix": "1.3.2",
54
- "@semantic-release/changelog": "6.0.1",
51
+ "@adobe/remark-gridtables": "1.0.1",
52
+ "@semantic-release/changelog": "6.0.2",
55
53
  "@semantic-release/git": "10.0.1",
56
54
  "c8": "7.12.0",
57
- "eslint": "8.24.0",
55
+ "eslint": "8.31.0",
58
56
  "eslint-plugin-header": "3.1.1",
59
- "eslint-plugin-import": "2.26.0",
60
- "husky": "8.0.1",
57
+ "eslint-plugin-import": "2.27.4",
58
+ "husky": "8.0.3",
61
59
  "junit-report-builder": "3.0.1",
62
- "lint-staged": "13.0.3",
60
+ "lint-staged": "13.1.0",
63
61
  "mdast-builder": "1.1.1",
64
- "mocha": "10.0.0",
62
+ "mocha": "10.2.0",
65
63
  "mocha-multi-reporters": "1.5.1",
66
64
  "rehype-format": "4.0.1",
67
65
  "remark-gfm": "3.0.1",
@@ -1,207 +0,0 @@
1
- # Grid Tables
2
-
3
- ## Overview
4
-
5
- GridTables look like this:
6
-
7
- ```
8
- +-------------------+------+
9
- | Table Headings | Here |
10
- +--------+----------+------+
11
- | Sub | Headings | Too |
12
- +========+=================+
13
- | cell | column spanning |
14
- | spans +---------:+------+
15
- | rows | normal | cell |
16
- +---v----+:---------------:+
17
- | | cells can be |
18
- | | *formatted* |
19
- | | **paragraphs** |
20
- | | ``` |
21
- | multi | and contain |
22
- | line | blocks |
23
- | cells | ``` |
24
- +========+=========<+======+
25
- | footer | cells | |
26
- +--------+----------+------+
27
- ```
28
-
29
- - the top of a cell must be indicated by `+-` followed by some `-` or `+` and finished by `-+`.
30
- - if the table contains a footer but no header, the top row should use `=` as grid line.
31
- - col spans are indicated by missing column (`|`) delimiters
32
- - row spans are indicated by missing row (`-`) delimiters
33
- - cells can be left, center, right, or justify aligned; indicated by the placement of `:` or `><`
34
- - cells can be top, middle, or bottom v-aligned; indicated by the placement of arrows (`v` `^` `x`)
35
- - the header and footer sections are delimited by section delimiters (`=`).
36
- - if no section delimiters are present, all cells are placed in the table body.
37
- - if only 1 section delimiter is present, it delimits header from body.
38
- - the content in cells can be a full Markdown document again. note, that the cell boundaries (`|`)
39
- need to exactly match with the column markers (`+`) in the row delimiters, if the cell content
40
- contains `|`, otherwise the correct layout of the table can't be guaranteed.
41
-
42
- Layout
43
- ======
44
-
45
- The table layout tries to keep the table within a certain width (default 120). For example,
46
- if the table has 3 columns, each column will be max 40 characters wide. If all text in a column
47
- is smaller, it will shrink the columns. However, cells have a minimum width (default 10) when
48
- text needs to be broken. If the cell contents need more space, e.g. with a nested table or
49
- code block, it will grow accordingly.
50
-
51
- Align
52
- =====
53
-
54
- Horizontal align is indicated by placing markers at the grid line above the cell:
55
-
56
- ```
57
- Justify Center Left Right
58
- +>-----<+ +:-----:+ +:------+ +------:+
59
- | A b C | | ABC | | ABC | | ABC |
60
- +-------+ +-------+ +-------+ +-------+
61
- ```
62
-
63
- Vertical align is indicated by placing markers at the center of the grid line above the cell:
64
-
65
- ```
66
- Top Middle Bottom
67
- +---^---+ +---x---+ +---v---+
68
- | Larum | | | | |
69
- | Ipsum | | Larum | | |
70
- | | | Ipsum | | Larum |
71
- | | | | | Ipsum |
72
- +-------+ +-------+ +-------+
73
- ```
74
-
75
- ## Syntax
76
-
77
- ```ebfn
78
-
79
- gridTable := gridLine cellLine+ gridLine;
80
- gridLine := gridCell+ "+";
81
- cellLine := ( gridCell | cellContent )+ ( "+" | "|" );
82
- gridCell := "+" alignMarkerStart? ("-" | "=")+ vAlignMarker? ("-" | "=")* alignMarkerEnd?;
83
- cellContent := ( "+" | "|" ) " " content " " ;
84
- alignMarkerStart := ":" | ">";
85
- alignMarkerEnd := ":" | "<";
86
- vAlignMarker := "^" | "v" | "x"
87
- ```
88
-
89
- ## MDAST Syntax tree
90
-
91
- The following interfaces are added to **[mdast][]** by this utility.
92
-
93
- ### Nodes
94
-
95
- #### `GridTable`
96
-
97
- ```idl
98
- interface GridTable <: Parent {
99
- type: "gridTable"
100
- children: [GridTableHeader|GridTableBody|GridTableFooter]
101
- }
102
- ```
103
-
104
- #### `GridTableHeader`
105
-
106
- ```idl
107
- interface GridTableHeader <: Parent {
108
- type: "gtHead"
109
- children: [GridTableRow]
110
- }
111
- ```
112
-
113
- #### `GridTableBody`
114
-
115
- ```idl
116
- interface GridTableBody <: Parent {
117
- type: "gtBody"
118
- children: [GridTableRow]
119
- }
120
- ```
121
-
122
- #### `GridTableFoot`
123
-
124
- ```idl
125
- interface GridTableFooter <: Parent {
126
- type: "gtFoot"
127
- children: [GridTableRow]
128
- }
129
- ```
130
-
131
- #### `GridTableRow`
132
-
133
- ```idl
134
- interface GridTableRow <: Parent {
135
- type: "gtRow"
136
- children: [GridTableCell]
137
- }
138
- ```
139
-
140
- #### `GridTableCell`
141
-
142
- ```idl
143
- interface GridTableCell <: Parent {
144
- type: "gtCell"
145
- colSpan: number >= 1
146
- rowSpan: number >= 1
147
- align: alignType
148
- valign: valignType
149
- children: [MdastContent]
150
- }
151
- ```
152
-
153
- **GridTableCell** ([**Parent**][dfn-parent]) represents a header cell in a
154
- [**GridTable**][dfn-table], if its parent is a [*gridTableHead*][term-head], or a data
155
- cell otherwise.
156
-
157
- **GridTableCell** can be used where [**gridTableRow**][dfn-row-content] content is expected.
158
- Its content model is [**mdast**][dfn-phrasing-content] content, allowing full mdast documents.
159
-
160
- ### Enumeration
161
-
162
- #### `alignType`
163
-
164
- ```idl
165
- enum alignType {
166
- "left" | "right" | "center" | "justify" | null
167
- }
168
- ```
169
-
170
- #### `valignType`
171
-
172
- ```idl
173
- enum alignType {
174
- "top" | "bottom" | "middle" | null
175
- }
176
- ```
177
-
178
- ## Usage
179
-
180
- ### Parsing with unified
181
-
182
- ```js
183
- import { unified } from 'unified';
184
- import remarkParse from 'remark-parse';
185
- import { remarkGridTable } from '@adobe/helix-markdown-support/gridtable';
186
-
187
- const mdast = unified()
188
- .use(remarkParse)
189
- .use(remarkGridTable)
190
- .parse(markdown);
191
- ```
192
-
193
- ### Generating HAST
194
-
195
- ```js
196
- import { toHast, defaultHandlers } from 'mdast-util-to-hast';
197
- import { mdast2hastGridTableHandler, TYPE_TABLE } from '@adobe/helix-markdown-support/gridtable';
198
-
199
- const hast = toHast(mdast, {
200
- handlers: {
201
- ...defaultHandlers,
202
- [TYPE_TABLE]: mdast2hastGridTableHandler(),
203
- },
204
- allowDangerousHtml: true,
205
- });
206
- ```
207
-
@@ -1,273 +0,0 @@
1
- /*
2
- * Copyright 2022 Adobe. All rights reserved.
3
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License. You may obtain a copy
5
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
- *
7
- * Unless required by applicable law or agreed to in writing, software distributed under
8
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- * OF ANY KIND, either express or implied. See the License for the specific language
10
- * governing permissions and limitations under the License.
11
- */
12
- /* eslint-disable no-underscore-dangle */
13
- import { fromMarkdown } from 'mdast-util-from-markdown';
14
- import { CONTINUE, visit } from 'unist-util-visit';
15
- import {
16
- TYPE_BODY, TYPE_CELL, TYPE_HEADER, TYPE_FOOTER, TYPE_ROW, TYPE_TABLE,
17
- } from './types.js';
18
-
19
- function unescapeDelimsInCode(tree) {
20
- visit(tree, (node) => {
21
- if (node.type === 'inlineCode' || node.type === 'code') {
22
- // eslint-disable-next-line no-param-reassign
23
- node.value = node.value.replace(/\\([+|])/gm, '$1');
24
- }
25
- return CONTINUE;
26
- });
27
- }
28
-
29
- function multiline(lines) {
30
- // remove empty trailing lines
31
- while (lines.length > 0 && lines[lines.length - 1].match(/^\s*$/)) {
32
- lines.pop();
33
- }
34
-
35
- // calculate common indent
36
- const prefixLen = lines
37
- .filter((line) => !line.match(/^\s*$/))
38
- .map((line) => line.match(/^ */)[0].length)
39
- .reduce((min, len) => Math.min(len, min), Infinity);
40
-
41
- // remove prefix
42
- return lines
43
- .map((line) => line.substring(prefixLen).trimEnd());
44
- }
45
-
46
- function getColSpan(info, token) {
47
- const i0 = info.cols.indexOf(token._colStart);
48
- const i1 = info.cols.indexOf(token._colEnd);
49
- return i1 - i0;
50
- }
51
-
52
- function enterTable(token) {
53
- this.enter({ type: TYPE_TABLE, children: [] }, token);
54
- this.setData('tableInfo', {
55
- // the column positions of the table
56
- cols: token._cols,
57
- // the current column
58
- colPos: 0,
59
- // list of all cells
60
- allCells: [],
61
- // cells that are still open via rowSpan
62
- pendingCells: [],
63
- // the current cells of a row
64
- cells: [],
65
- // the grid dividers use for align the cells
66
- dividers: [],
67
- // the link/image reference definitions
68
- definitions: token._definitions,
69
- });
70
- }
71
-
72
- function createExitTable(options) {
73
- const { processor } = options;
74
-
75
- return function exitTable(token) {
76
- // render cells
77
- const info = this.getData('tableInfo');
78
- for (const cell of info.allCells) {
79
- const {
80
- node, lines, colSpan, rowSpan,
81
- align, valign,
82
- } = cell;
83
-
84
- // add fake definitions...
85
- const sanitizedLines = multiline(lines);
86
- for (const def of info.definitions) {
87
- sanitizedLines.push('');
88
- sanitizedLines.push(`[${def}]: dummy`);
89
- }
90
- const cellContent = sanitizedLines.join('\n');
91
-
92
- const tree = fromMarkdown(cellContent, {
93
- extensions: processor.data('micromarkExtensions'),
94
- mdastExtensions: processor.data('fromMarkdownExtensions'),
95
- });
96
-
97
- // remove previously added definitions
98
- for (let i = 0; i < tree.children.length; i += 1) {
99
- const child = tree.children[i];
100
- if (child.type === 'definition' && info.definitions.includes(child.label)) {
101
- tree.children.splice(i, 1);
102
- i -= 1;
103
- }
104
- }
105
-
106
- // remove escaped pipes and plusses in code
107
- unescapeDelimsInCode(tree);
108
-
109
- node.children = tree.children;
110
- if (colSpan > 1) {
111
- node.colSpan = colSpan;
112
- }
113
- if (rowSpan > 1) {
114
- node.rowSpan = rowSpan;
115
- }
116
- if (align) {
117
- node.align = align;
118
- }
119
- if (valign) {
120
- node.valign = valign;
121
- }
122
- }
123
- this.exit(token);
124
- };
125
- }
126
-
127
- function enter(token) {
128
- this.enter({ type: token.type, children: [] }, token);
129
- }
130
-
131
- function enterCell() {
132
- this.buffer();
133
- }
134
-
135
- function exitCell(token) {
136
- this.config.enter.data.call(this, token);
137
- this.config.exit.data.call(this, token);
138
- const data = this.resume();
139
- const info = this.getData('tableInfo');
140
- const colSpan = getColSpan(info, token);
141
-
142
- let cell = info.pendingCells[info.colPos];
143
-
144
- // open rowspan if we are on a divider line
145
- if (info.isDivider) {
146
- if (!cell) {
147
- cell = info.cells[info.colPos];
148
- info.pendingCells[info.colPos] = cell;
149
- }
150
- if (!cell) {
151
- // throw Error('no matching rowspan');
152
- } else {
153
- cell.rowSpan += 1;
154
- }
155
- }
156
-
157
- // if a rowspan is open, append to its cell
158
- if (cell) {
159
- cell.lines.push(data);
160
- info.colPos += colSpan;
161
- return;
162
- }
163
-
164
- // otherwise append to regular cell
165
- cell = info.cells[info.colPos];
166
- if (!cell) {
167
- const div = info.dividers[info.colPos];
168
- cell = {
169
- rowSpan: 1,
170
- colSpan,
171
- align: div?._align,
172
- valign: div?._valign,
173
- node: {
174
- type: TYPE_CELL,
175
- },
176
- lines: [],
177
- };
178
- info.cells[info.colPos] = cell;
179
- info.allCells.push(cell);
180
- }
181
- cell.lines.push(data);
182
- info.colPos += colSpan;
183
- }
184
-
185
- function enterGridDivider(token) {
186
- const info = this.getData('tableInfo');
187
- // clear pending rowspans and set divider info
188
- let colSpan = getColSpan(info, token);
189
- while (colSpan > 0) {
190
- colSpan -= 1;
191
- info.pendingCells[info.colPos] = null;
192
- info.dividers[info.colPos] = token;
193
- info.colPos += 1;
194
- }
195
- }
196
-
197
- function enterRowLine(token) {
198
- const info = this.getData('tableInfo');
199
- info.isDivider = token._type;
200
- info.colPos = 0;
201
- if (info.isDivider) {
202
- info.dividers = [];
203
- }
204
- }
205
-
206
- function commitRow(info) {
207
- // create fake token for 'gtRow'
208
- const rowToken = {
209
- type: TYPE_ROW,
210
- start: { line: 0, column: 0, offset: 0 },
211
- end: { line: 0, column: 0, offset: 0 },
212
- };
213
- this.enter({ type: TYPE_ROW, children: [] }, rowToken);
214
-
215
- // emit cells
216
- for (const cell of info.cells) {
217
- if (cell) {
218
- const cellToken = {
219
- type: TYPE_CELL,
220
- start: { line: 0, column: 0, offset: 0 },
221
- end: { line: 0, column: 0, offset: 0 },
222
- };
223
- this.enter(cell.node, cellToken);
224
- this.exit(cellToken);
225
- }
226
- }
227
-
228
- this.exit(rowToken);
229
- // eslint-disable-next-line no-param-reassign
230
- info.cells = [];
231
- }
232
-
233
- function exitHeader(token) {
234
- const info = this.getData('tableInfo');
235
- // commit row has some cells
236
- if (info.cells.length) {
237
- commitRow.call(this, info);
238
- // also close all rowspans.
239
- info.pendingCells = [];
240
- }
241
- this.exit(token);
242
- }
243
-
244
- function exitRowLine() {
245
- const info = this.getData('tableInfo');
246
- // commit row if on a divider and has some cells
247
- if (info.isDivider && info.cells.length) {
248
- commitRow.call(this, info);
249
- }
250
- }
251
-
252
- // eslint-disable-next-line no-unused-vars
253
- export default function handler(options = {}) {
254
- return {
255
- enter: {
256
- [TYPE_TABLE]: enterTable,
257
- [TYPE_HEADER]: enter,
258
- [TYPE_BODY]: enter,
259
- [TYPE_FOOTER]: enter,
260
- [TYPE_CELL]: enterCell,
261
- gridDivider: enterGridDivider,
262
- rowLine: enterRowLine,
263
- },
264
- exit: {
265
- [TYPE_TABLE]: createExitTable(options),
266
- [TYPE_HEADER]: exitHeader,
267
- [TYPE_BODY]: exitHeader,
268
- [TYPE_FOOTER]: exitHeader,
269
- [TYPE_CELL]: exitCell,
270
- rowLine: exitRowLine,
271
- },
272
- };
273
- }
@@ -1,91 +0,0 @@
1
- /*
2
- * Copyright 2022 Adobe. All rights reserved.
3
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License. You may obtain a copy
5
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
- *
7
- * Unless required by applicable law or agreed to in writing, software distributed under
8
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- * OF ANY KIND, either express or implied. See the License for the specific language
10
- * governing permissions and limitations under the License.
11
- */
12
-
13
- /**
14
- * GridTables remark plugin and micromark extension.
15
- *
16
- * GridTables look like this:
17
- *
18
- * ```
19
- * +-------------------+------+
20
- * | Table Headings | Here |
21
- * +--------+----------+------+
22
- * | Sub | Headings | Too |
23
- * +========+=================+
24
- * | cell | column spanning |
25
- * | spans +---------:+------+
26
- * | rows | normal | cell |
27
- * +---v----+:---------------:+
28
- * | | cells can be |
29
- * | | *formatted* |
30
- * | | **paragraphs** |
31
- * | | ``` |
32
- * | multi | and contain |
33
- * | line | blocks |
34
- * | cells | ``` |
35
- * +========+=========<+======+
36
- * | footer | cells | |
37
- * +--------+----------+------+
38
- * ```
39
- *
40
- * - the top of a cell must be indicated by `+-` followed by some `-` or `+` and finished by `-+`.
41
- * - if the table contains a footer but no header, the top row should use `=` as grid line.
42
- * - col spans are indicated by missing column (`|`) delimiters
43
- * - row spans are indicated by missing row (`-`) delimiters
44
- * - cells can be left, center, right, or justify aligned; indicated by the placement of `:` or `><`
45
- * - cells can be top, middle, or bottom v-aligned;
46
- * indicated by the placement of arrows (`v` `^` `x`)
47
- * - the header and footer sections are delimited by section delimiters (`=`).
48
- * - if no section delimiters are present, all cells are placed in the table body.
49
- * - if only 1 section delimiter is present, it delimits header from body.
50
- * - the content in cells can be a full Markdown document again.
51
- * note, that the cell boundaries (`|`)
52
- * need to exactly match with the column markers (`+`) in the row delimiters, if the cell content
53
- * contains `|`, otherwise the correct layout of the table can't be guaranteed.
54
- *
55
- * Layout
56
- * ======
57
- *
58
- * The table layout tries to keep the table within a certain width (default 120). For example,
59
- * if the table has 3 columns, each column will be max 40 characters wide. If all text in a column
60
- * is smaller, it will shrink the columns. However, cells have a minimum width (default 10) when
61
- * text needs to be broken. If the cell contents need more space, e.g. with a nested table or
62
- * code block, it will grow accordingly.
63
- *
64
- * Align
65
- * =====
66
- *
67
- * Horizontal align is indicated by placing markers at the grid line above the cell:
68
- *
69
- * ```
70
- * Justify Center Left Right
71
- * +>-----<+ +:-----:+ +:------+ +------:+
72
- * | A b C | | ABC | | ABC | | ABC |
73
- * +-------+ +-------+ +-------+ +-------+
74
- * ```
75
- *
76
- * Vertical align is indicated by placing markers at the center of the grid line above the cell:
77
- *
78
- * ```
79
- * Top Middle Bottom
80
- * +---^---+ +---x---+ +---v---+
81
- * | Larum | | | | |
82
- * | Ipsum | | Larum | | |
83
- * | | | Ipsum | | Larum |
84
- * | | | | | Ipsum |
85
- * +-------+ +-------+ +-------+
86
- * ```
87
- *
88
- */
89
- export * from './types.js';
90
- export { default as remarkGridTable } from './remark-plugin.js';
91
- export { default as mdast2hastGridTableHandler } from './mdast2hast-handler.js';