Skip to content

Commit

Permalink
fix: fixed a crash when specifying the HTML pre tag
Browse files Browse the repository at this point in the history
  • Loading branch information
akabekobeko committed Apr 8, 2021
1 parent 30b23bc commit 3fbbb82
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/plugins/figure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ export const hast = () => (tree: Node) => {
visit<HastNode>(tree, 'element', (node, index, parent) => {
// handle captioned code block
const maybeCode = node.children?.[0] as HastNode | undefined;
if (is(node, 'pre') && maybeCode?.properties.title) {
const maybeTitle = maybeCode?.properties?.title;
if (is(node, 'pre') && maybeCode?.properties?.title) {
const maybeTitle = maybeCode.properties.title;
delete maybeCode.properties.title;
(parent as Parent).children[index] = h(
'figure',
Expand Down
13 changes: 13 additions & 0 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,16 @@ it('empty replace', () => {
).toBe(`<p>[icon1][Notice]</p>
<p>[person][Nod nod]</p>`);
});

it('<pre>', () => {
const actual = lib.stringify(`<pre>\n* * *\n * * *\n</pre>`, {
partial: true,
disableFormatHtml: true,
});
// In CommonMark parsing, a line break is inserted immediately after `<pre>`
// In this test, line breaks are intentionally removed according to the behavior of VFM.
const expected = `<pre>* * *
* * *
</pre>`;
expect(actual).toBe(expected);
});

0 comments on commit 3fbbb82

Please sign in to comment.