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

Commit

Permalink
fix(markdown): #158 GFM Tables crash the pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
koraa committed Apr 1, 2019
1 parent b418f73 commit 4a4546f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/schemas/mdast.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
"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.",
"type": "array",
"items": {
"type":"string",
"type": ["null", "string"],
"enum": ["left", "right", "center", null]
}
},
Expand Down
52 changes: 42 additions & 10 deletions test/testHTMLFromMarkdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
const winston = require('winston');
const { JSDOM } = require('jsdom');
const { assertEquivalentNode } = require('@adobe/helix-shared').dom;
const { multiline } = require('@adobe/helix-shared').string;
const { pipe } = require('../src/defaults/html.pipe.js');

const params = {
Expand Down Expand Up @@ -85,7 +86,7 @@ const assertMd = async (md, html) => {

const generated = await pipe(
fromHTML,
{ content: { body: md } },
{ content: { body: multiline(md) } },
{
logger,
request: { params },
Expand Down Expand Up @@ -132,10 +133,14 @@ describe('Testing Markdown conversion', () => {
});

it('Code blocks without lang', async () => {
await assertMd(
' Hello World',
'<pre><code>Hello World\n</code></pre>',
);
await assertMd(`
# Hello
Hello World
`, `
<h1>Hello</h1>
<pre><code>Hello World\n</code></pre>
`);
await assertMd(
'```Hello World```',
'<p><code>Hello World</code></p>',
Expand All @@ -147,10 +152,37 @@ describe('Testing Markdown conversion', () => {
});

it('Link references', async () => {
await assertMd(
`Hello [World]
[World]: http://example.com`,
'<p>Hello <a href="http://example.com">World</a></p>',
);
await assertMd(`
Hello [World]
[World]: http://example.com
`, `
<p>Hello <a href="http://example.com">World</a></p>
`);
});

it('GFM', async () => {
await assertMd(`
Hello World.
| foo | bar |
| --- | --- |
| baz | bim |
`, `
<p>Hello World.</p>
<table>
<thead>
<tr>
<th>foo</th>
<th>bar</th>
</tr>
</thead>
<tbody>
<tr>
<td>baz</td>
<td>bim</td>
</tr>
</tbody>
</table>
`);
});
});

0 comments on commit 4a4546f

Please sign in to comment.