Skip to content

Commit

Permalink
feat(core): escape corner brackets during serialization (#17)
Browse files Browse the repository at this point in the history
During sterilization, we need to escape the corner brackets, because later they can be parsed as HTML
  • Loading branch information
d3m1d0v authored Oct 5, 2022
1 parent 4596c70 commit 01ad8a8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/core/markdown/Markdown.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const serializer = new MarkdownSerializer(
const {doc, p, h1, h2, li, ul, ol, br, pre} = builder;
const {em, strong, code} = builder;

const {same, serialize} = createMarkupChecker({parser, serializer});
const {same, parse, serialize} = createMarkupChecker({parser, serializer});

describe('markdown', () => {
it('parses a paragraph', () => same('hello!', doc(p('hello!')))); // TODO: move test to extensions?
Expand Down Expand Up @@ -151,7 +151,7 @@ describe('markdown', () => {
it('parses a line break', () =>
same('line one\\\nline two', doc(p('line one', br(), 'line two'))));

it('ignores HTML tags', () => same('Foo < img> bar', doc(p('Foo < img> bar'))));
it('ignores HTML tags', () => parse('Foo < img> bar', doc(p('Foo < img> bar'))));

it("doesn't accidentally generate list markup", () => same('1\\. foo', doc(p('1. foo'))));

Expand Down
2 changes: 1 addition & 1 deletion src/core/markdown/MarkdownSerializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ export class MarkdownSerializerState {
// have special meaning only at the start of the line.
esc(str, startOfLine) {
// TODO: add a setting which characters need to be escaped
str = str.replace(/[`\^+*\\~\[\]\{\}\$]/g, '\\$&');
str = str.replace(/[`\^+*\\~\[\]\{\}<>\$]/g, '\\$&');
if (startOfLine) str = str.replace(/^[:#\-*+>]/, '\\$&').replace(/^(\s*\d+)\./, '$1\\.');
return str;
}
Expand Down

0 comments on commit 01ad8a8

Please sign in to comment.