Skip to content
This repository was archived by the owner on Feb 28, 2022. It is now read-only.

Commit 4a4546f

Browse files
committed
fix(markdown): #158 GFM Tables crash the pipeline
1 parent b418f73 commit 4a4546f

File tree

2 files changed

+43
-11
lines changed

2 files changed

+43
-11
lines changed

src/schemas/mdast.schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123
"description": "For tables, an align field can be present. If present, it must be a list of alignTypes. It represents how cells in columns are aligned.",
124124
"type": "array",
125125
"items": {
126-
"type":"string",
126+
"type": ["null", "string"],
127127
"enum": ["left", "right", "center", null]
128128
}
129129
},

test/testHTMLFromMarkdown.js

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
const winston = require('winston');
1414
const { JSDOM } = require('jsdom');
1515
const { assertEquivalentNode } = require('@adobe/helix-shared').dom;
16+
const { multiline } = require('@adobe/helix-shared').string;
1617
const { pipe } = require('../src/defaults/html.pipe.js');
1718

1819
const params = {
@@ -85,7 +86,7 @@ const assertMd = async (md, html) => {
8586

8687
const generated = await pipe(
8788
fromHTML,
88-
{ content: { body: md } },
89+
{ content: { body: multiline(md) } },
8990
{
9091
logger,
9192
request: { params },
@@ -132,10 +133,14 @@ describe('Testing Markdown conversion', () => {
132133
});
133134

134135
it('Code blocks without lang', async () => {
135-
await assertMd(
136-
' Hello World',
137-
'<pre><code>Hello World\n</code></pre>',
138-
);
136+
await assertMd(`
137+
# Hello
138+
139+
Hello World
140+
`, `
141+
<h1>Hello</h1>
142+
<pre><code>Hello World\n</code></pre>
143+
`);
139144
await assertMd(
140145
'```Hello World```',
141146
'<p><code>Hello World</code></p>',
@@ -147,10 +152,37 @@ describe('Testing Markdown conversion', () => {
147152
});
148153

149154
it('Link references', async () => {
150-
await assertMd(
151-
`Hello [World]
152-
[World]: http://example.com`,
153-
'<p>Hello <a href="http://example.com">World</a></p>',
154-
);
155+
await assertMd(`
156+
Hello [World]
157+
[World]: http://example.com
158+
`, `
159+
<p>Hello <a href="http://example.com">World</a></p>
160+
`);
161+
});
162+
163+
it('GFM', async () => {
164+
await assertMd(`
165+
Hello World.
166+
167+
| foo | bar |
168+
| --- | --- |
169+
| baz | bim |
170+
`, `
171+
<p>Hello World.</p>
172+
<table>
173+
<thead>
174+
<tr>
175+
<th>foo</th>
176+
<th>bar</th>
177+
</tr>
178+
</thead>
179+
<tbody>
180+
<tr>
181+
<td>baz</td>
182+
<td>bim</td>
183+
</tr>
184+
</tbody>
185+
</table>
186+
`);
155187
});
156188
});

0 commit comments

Comments
 (0)