Skip to content

Commit 91cd66d

Browse files
authored
Fix parsing multiple blockquotes and inlineCode syntax error (brussell98#10)
* Fix syntax error * Fix blockquote rule to handle multiple blockquotes and sanitize text in inline code
1 parent 35f7cff commit 91cd66d

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

index.js

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,8 @@ const rules = {
3939
const removeSyntaxRegex = isBlock ? /^ *>>> ?/ : /^ *> ?/gm;
4040
const content = all.replace(removeSyntaxRegex, '');
4141

42-
state.inQuote = true
43-
if (!isBlock)
44-
state.inline = true;
45-
46-
const parsed = parse(content, state);
47-
48-
state.inQuote = state.inQuote || false;
49-
state.inline = state.inline || false;
50-
5142
return {
52-
content: parsed,
43+
content: parse(content, Object.assign({}, state, {inQuote: true})),
5344
type: 'blockQuote'
5445
}
5546
}
@@ -113,8 +104,11 @@ const rules = {
113104
strike: Object.assign({ }, markdown.defaultRules.del, {
114105
match: markdown.inlineRegex(/^~~([\s\S]+?)~~(?!_)/),
115106
}),
116-
inlineCode: Object.assign({ }, markdown.defaultRules.inlineCode {
117-
match: source => source = source.trimEnd(), markdown.defaultRules.inlineCode.match.regex.exec(source)
107+
inlineCode: Object.assign({ }, markdown.defaultRules.inlineCode, {
108+
match: source => markdown.defaultRules.inlineCode.match.regex.exec(source),
109+
html: function(node, output, state) {
110+
return htmlTag('code', markdown.sanitizeText(node.content.trim()), null, state);
111+
}
118112
}),
119113
text: Object.assign({ }, markdown.defaultRules.text, {
120114
match: source => /^[\s\S]+?(?=[^0-9A-Za-z\s\u00c0-\uffff-]|\n\n|\n|\w+:\S|$)/.exec(source),

test/single.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ test('Block quotes', () => {
8888
.toBe('<blockquote>test<br><pre><code class="hljs js">code</code></pre></blockquote>');
8989
expect(markdown.toHTML('> text\n> \n> here'))
9090
.toBe('<blockquote>text<br><br>here</blockquote>');
91+
expect(markdown.toHTML('text\n\n> Lorem ipsum\n>> Lorem ipsum\n> Lorem ipsum\n> > Lorem ipsum\n> Lorem ipsum\n\nLorem ipsum\n\n> Lorem ipsum\n\nLorem ipsum\n\n>>> text\ntext\ntext\n'))
92+
.toBe('text<br><br><blockquote>Lorem ipsum<br></blockquote>&gt;&gt; Lorem ipsum<br><blockquote>Lorem ipsum<br>&gt; Lorem ipsum<br>Lorem ipsum<br></blockquote><br>Lorem ipsum<br><br><blockquote>Lorem ipsum<br></blockquote><br>Lorem ipsum<br><br><blockquote>text<br>text<br>text<br></blockquote>');
9193
});
9294

9395
test('don\'t drop arms', () => {

0 commit comments

Comments
 (0)