Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make header up to spec #1

Merged
merged 1 commit into from
Apr 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions lib/marked.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var block = {
fences: noop,
hr: /^ {0,3}((?:- *){3,}|(?:_ *){3,}|(?:\* *){3,})(?:\n+|$)/,
// cap[2] might be ' HEADING # ' and must be trimmed appropriately.
heading: /^ *(#{1,6})(.*)(?:\n+|$)/,
heading: /^ {0,3}(#{1,6})(?:[^\S\n](.*))?(?:\n+|$)/,
nptable: noop,
blockquote: /^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/,
list: /^( *)(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/,
Expand Down Expand Up @@ -93,9 +93,7 @@ block.normal = merge({}, block);

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

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

block.pedantic = merge({}, block.normal, {
heading: /^ *(#{1,6})(.*)(?:\n+|$)/,
html: edit(
'^ *(?:comment *(?:\\n|\\s*$)'
+ '|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)' // closed tag
Expand Down Expand Up @@ -238,13 +237,18 @@ Lexer.prototype.token = function(src, top) {
if (cap = this.rules.heading.exec(src)) {
src = src.substring(cap[0].length);
// cap[2] might be ' HEADING # '
item = cap[2].trim();
item = (cap[2] || '').trim();
if (item.slice(-1) === '#') {
// NB replace(/#+$/) is quadratic on mismatch because it's unanchored,
// so we protect with if-check to ensure it won't mismatch.
item = item.replace(/#+$/, '');
if (this.options.pedantic) {
item = item.replace(/#+$/, '');
} else {
// CM requires a space before additional #s
item = item.replace(/(\s|^)#+$/, '');
}
}
item = item.trim()
item = item.trim();
this.tokens.push({
type: 'heading',
depth: cap[1].length,
Expand Down
2 changes: 1 addition & 1 deletion test/new/nogfm_hashtag.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
gfm: false
pedantic: true
---
#header

Expand Down
2 changes: 1 addition & 1 deletion test/specs/commonmark/commonmark-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ describe('CommonMark 0.28 ATX headings', function() {
var section = 'ATX headings';

// var shouldPassButFails = [];
var shouldPassButFails = [40, 45, 46, 49];
var shouldPassButFails = [40];

var willNotBeAttemptedByCoreTeam = [];

Expand Down