Browse Source

Updated heading for new spec

pull/14/head
Vitaly Puzrin 10 years ago
parent
commit
f54ea502ee
  1. 21
      lib/rules_block/heading.js
  2. 34
      test/fixtures/commonmark/bad.txt
  3. 22
      test/fixtures/commonmark/good.txt

21
lib/rules_block/heading.js

@ -4,7 +4,7 @@
module.exports = function heading(state, startLine, endLine, silent) { module.exports = function heading(state, startLine, endLine, silent) {
var ch, level, var ch, level, tmp,
pos = state.bMarks[startLine] + state.tShift[startLine], pos = state.bMarks[startLine] + state.tShift[startLine],
max = state.eMarks[startLine]; max = state.eMarks[startLine];
@ -24,27 +24,16 @@ module.exports = function heading(state, startLine, endLine, silent) {
if (level > 6 || (pos < max && ch !== 0x20/* space */)) { return false; } if (level > 6 || (pos < max && ch !== 0x20/* space */)) { return false; }
// skip spaces before heading text if (silent) { return true; }
pos = state.skipSpaces(pos);
// Now pos contains offset of first heared char
// Let's cut tails like ' ### ' from the end of string // Let's cut tails like ' ### ' from the end of string
max = state.skipCharsBack(max, 0x20/* space */, pos); max = state.skipCharsBack(max, 0x20/* space */, pos);
max = state.skipCharsBack(max, 0x23/* # */, pos); tmp = state.skipCharsBack(max, 0x23/* # */, pos);
if (tmp > pos && state.src.charCodeAt(tmp - 1) === 0x20/* space */) {
if (max < state.eMarks[startLine] && max = tmp;
state.src.charCodeAt(max) === 0x23/* # */ &&
state.src.charCodeAt(max - 1) === 0x5C/* \ */) {
max++;
} }
// ## Foo ####
// ^^^
max = state.skipCharsBack(max, 0x20/* space */, pos);
if (silent) { return true; }
state.line = startLine + 1; state.line = startLine + 1;
state.tokens.push({ type: 'heading_open', state.tokens.push({ type: 'heading_open',

34
test/fixtures/commonmark/bad.txt

@ -1,37 +1,3 @@
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 619
.
# foo#
.
<h1>foo#</h1>
.
error:
<h1>foo</h1>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 628
.
### foo \###
## foo #\##
# foo \#
.
<h3>foo ###</h3>
<h2>foo ###</h2>
<h1>foo #</h1>
.
error:
<h3>foo #</h3>
<h2>foo ##</h2>
<h1>foo #</h1>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 3124 src line: 3124

22
test/fixtures/commonmark/good.txt

@ -390,6 +390,28 @@ src line: 611
<h3>foo ### b</h3> <h3>foo ### b</h3>
. .
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 619
.
# foo#
.
<h1>foo#</h1>
.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 628
.
### foo \###
## foo #\##
# foo \#
.
<h3>foo ###</h3>
<h2>foo ###</h2>
<h1>foo #</h1>
.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 641 src line: 641

Loading…
Cancel
Save