Skip to content

Commit

Permalink
fix(html): only parse inline html tags if the opening and closing tag…
Browse files Browse the repository at this point in the history
…s are on the same line

fixes: #133
  • Loading branch information
b-kelly committed Jun 16, 2022
1 parent 4dd7761 commit 383c6db
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/shared/markdown-it/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ function isParseableHtmlBlockToken(token: Token): parsedBlockTokenInfo {
const content = token.content;
// checks if a token matches `<open>content</close>` OR `<br />`
const matches =
/^(?:(<[a-z0-9]+.*?>)([^<>]+?)(<\/[a-z0-9]+>))$|^(<[a-z0-9]+(?:\s.+?)?\s?\/?>)$/i.exec(
/^(?:(<[a-z0-9]+.*?>)([^<>\n]+?)(<\/[a-z0-9]+>))$|^(<[a-z0-9]+(?:\s.+?)?\s?\/?>)$/i.exec(
content
);

Expand Down
7 changes: 7 additions & 0 deletions test/shared/markdown-it/html.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,13 @@ describe("html markdown-it plugin", () => {
expect(tokens[1].children[1].type).toBe("html_inline");
expect(tokens[1].children[1].content).toBe("</em>");
});

it("should only transform inline html all on the same line", () => {
const markdown = `<sub>\ntest\n</sub>`;
const tokens = instance.parse(markdown, {});
expect(tokens).toHaveLength(1);
expect(tokens[0].type).toBe("html_block");
});
});

describe("html_block", () => {
Expand Down

0 comments on commit 383c6db

Please sign in to comment.