Skip to content

Commit 01ad8a8

Browse files
authored
feat(core): escape corner brackets during serialization (#17)
During sterilization, we need to escape the corner brackets, because later they can be parsed as HTML
1 parent 4596c70 commit 01ad8a8

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/core/markdown/Markdown.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ const serializer = new MarkdownSerializer(
8282
const {doc, p, h1, h2, li, ul, ol, br, pre} = builder;
8383
const {em, strong, code} = builder;
8484

85-
const {same, serialize} = createMarkupChecker({parser, serializer});
85+
const {same, parse, serialize} = createMarkupChecker({parser, serializer});
8686

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

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

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

src/core/markdown/MarkdownSerializer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ export class MarkdownSerializerState {
294294
// have special meaning only at the start of the line.
295295
esc(str, startOfLine) {
296296
// TODO: add a setting which characters need to be escaped
297-
str = str.replace(/[`\^+*\\~\[\]\{\}\$]/g, '\\$&');
297+
str = str.replace(/[`\^+*\\~\[\]\{\}<>\$]/g, '\\$&');
298298
if (startOfLine) str = str.replace(/^[:#\-*+>]/, '\\$&').replace(/^(\s*\d+)\./, '$1\\.');
299299
return str;
300300
}

0 commit comments

Comments
 (0)