|
532 | 532 | var cap = this.rules.block.heading.exec(src); |
533 | 533 |
|
534 | 534 | if (cap) { |
| 535 | + var text = cap[2].trim(); // remove trailing #s |
| 536 | + |
| 537 | + if (text.endsWith('#')) { |
| 538 | + var trimmed = rtrim$1(text, '#'); |
| 539 | + |
| 540 | + if (this.options.pedantic) { |
| 541 | + text = trimmed.trim(); |
| 542 | + } else if (!trimmed || trimmed.endsWith(' ')) { |
| 543 | + // CommonMark requires space before trailing #s |
| 544 | + text = trimmed.trim(); |
| 545 | + } |
| 546 | + } |
| 547 | + |
535 | 548 | return { |
536 | 549 | type: 'heading', |
537 | 550 | raw: cap[0], |
538 | 551 | depth: cap[1].length, |
539 | | - text: cap[2] |
| 552 | + text: text |
540 | 553 | }; |
541 | 554 | } |
542 | 555 | }; |
|
1122 | 1135 | code: /^( {4}[^\n]+\n*)+/, |
1123 | 1136 | fences: /^ {0,3}(`{3,}(?=[^`\n]*\n)|~{3,})([^\n]*)\n(?:|([\s\S]*?)\n)(?: {0,3}\1[~`]* *(?:\n+|$)|$)/, |
1124 | 1137 | hr: /^ {0,3}((?:- *){3,}|(?:_ *){3,}|(?:\* *){3,})(?:\n+|$)/, |
1125 | | - heading: /^ {0,3}(#{1,6}) +([^\n]*?)(?: +#+)? *(?:\n+|$)/, |
| 1138 | + heading: /^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/, |
1126 | 1139 | blockquote: /^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/, |
1127 | 1140 | list: /^( {0,3})(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?! {0,3}bull )\n*|\s*$)/, |
1128 | 1141 | html: '^ {0,3}(?:' // optional indentation |
|
1193 | 1206 | html: edit$1('^ *(?:comment *(?:\\n|\\s*$)' + '|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)' // closed tag |
1194 | 1207 | + '|<tag(?:"[^"]*"|\'[^\']*\'|\\s[^\'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))').replace('comment', block._comment).replace(/tag/g, '(?!(?:' + 'a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub' + '|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)' + '\\b)\\w+(?!:|[^\\w\\s@]*@)\\b').getRegex(), |
1195 | 1208 | def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/, |
1196 | | - heading: /^ *(#{1,6}) *([^\n]+?) *(?:#+ *)?(?:\n+|$)/, |
| 1209 | + heading: /^(#{1,6})(.*)(?:\n+|$)/, |
1197 | 1210 | fences: noopTest$1, |
1198 | 1211 | // fences not supported |
1199 | 1212 | paragraph: edit$1(block.normal._paragraph).replace('hr', block.hr).replace('heading', ' *#{1,6} *[^\n]').replace('lheading', block.lheading).replace('blockquote', ' {0,3}>').replace('|fences', '').replace('|list', '').replace('|html', '').getRegex() |
|
0 commit comments