Skip to content

Commit 943d995

Browse files
UziTechdavisjam
authored andcommitted
make header up to spec
1 parent 5736014 commit 943d995

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

lib/marked.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ var block = {
1717
fences: noop,
1818
hr: /^ {0,3}((?:- *){3,}|(?:_ *){3,}|(?:\* *){3,})(?:\n+|$)/,
1919
// cap[2] might be ' HEADING # ' and must be trimmed appropriately.
20-
heading: /^ *(#{1,6})(.*)(?:\n+|$)/,
20+
heading: /^ {0,3}(#{1,6})(?:[^\S\n](.*))?(?:\n+|$)/,
2121
nptable: noop,
2222
blockquote: /^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/,
2323
list: /^( *)(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/,
@@ -93,9 +93,7 @@ block.normal = merge({}, block);
9393

9494
block.gfm = merge({}, block.normal, {
9595
fences: /^ *(`{3,}|~{3,})[ \.]*(\S+)? *\n([\s\S]*?)\n? *\1 *(?:\n+|$)/,
96-
paragraph: /^/,
97-
// cap[2] might be ' HEADING # ' and must be trimmed appropriately.
98-
heading: /^ *(#{1,6}) (.+)(?:\n+|$)/
96+
paragraph: /^/
9997
});
10098

10199
block.gfm.paragraph = edit(block.paragraph)
@@ -118,6 +116,7 @@ block.tables = merge({}, block.gfm, {
118116
*/
119117

120118
block.pedantic = merge({}, block.normal, {
119+
heading: /^ *(#{1,6})(.*)(?:\n+|$)/,
121120
html: edit(
122121
'^ *(?:comment *(?:\\n|\\s*$)'
123122
+ '|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)' // closed tag
@@ -238,13 +237,18 @@ Lexer.prototype.token = function(src, top) {
238237
if (cap = this.rules.heading.exec(src)) {
239238
src = src.substring(cap[0].length);
240239
// cap[2] might be ' HEADING # '
241-
item = cap[2].trim();
240+
item = (cap[2] || '').trim();
242241
if (item.slice(-1) === '#') {
243242
// NB replace(/#+$/) is quadratic on mismatch because it's unanchored,
244243
// so we protect with if-check to ensure it won't mismatch.
245-
item = item.replace(/#+$/, '');
244+
if (this.options.pedantic) {
245+
item = item.replace(/#+$/, '');
246+
} else {
247+
// CM requires a space before additional #s
248+
item = item.replace(/(\s|^)#+$/, '');
249+
}
246250
}
247-
item = item.trim()
251+
item = item.trim();
248252
this.tokens.push({
249253
type: 'heading',
250254
depth: cap[1].length,

test/new/nogfm_hashtag.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
gfm: false
2+
pedantic: true
33
---
44
#header
55

test/specs/commonmark/commonmark-spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ describe('CommonMark 0.28 ATX headings', function() {
110110
var section = 'ATX headings';
111111

112112
// var shouldPassButFails = [];
113-
var shouldPassButFails = [40, 45, 46, 49];
113+
var shouldPassButFails = [40];
114114

115115
var willNotBeAttemptedByCoreTeam = [];
116116

0 commit comments

Comments
 (0)