Browse Source

Treat newline as a whitespace in em and del

pull/14/head
Alex Kocharin 10 years ago
parent
commit
7abfb2718c
  1. 11
      lib/rules_inline/emphasis.js
  2. 10
      lib/rules_inline/strikethrough.js
  3. 43
      test/fixtures/remarkable/regression.txt

11
lib/rules_inline/emphasis.js

@ -15,11 +15,11 @@ function isAlphaNum(code) {
// note: in case if 4+ markers it is still not a valid emphasis,
// should be treated as a special case
function parseStart(state, start) {
var pos = start, lastChar, count,
var pos = start, lastChar, nextChar, count,
max = state.posMax,
marker = state.src.charCodeAt(start);
lastChar = state.pending.length !== 0 ? state.pending.charCodeAt(state.pending.length - 1) : -1;
lastChar = start > 0 ? state.src.charCodeAt(start - 1) : -1;
while (pos < max && state.src.charCodeAt(pos) === marker) { pos++; }
if (pos >= max) { return -1; }
@ -40,7 +40,8 @@ function parseStart(state, start) {
}
// check condition 2, marker followed by whitespace
if (state.src.charCodeAt(pos) === 0x20) { return -1; }
nextChar = state.src.charCodeAt(pos);
if (nextChar === 0x20 || nextChar === 0x0A) { return -1; }
if (marker === 0x5F /* _ */) {
// check condition 3, if it's the beginning of the word
@ -61,7 +62,7 @@ function parseEnd(state, start) {
max = state.posMax,
marker = state.src.charCodeAt(start);
lastChar = state.pending.length !== 0 ? state.pending.charCodeAt(state.pending.length - 1) : -1;
lastChar = start > 0 ? state.src.charCodeAt(start - 1) : -1;
while (pos < max && state.src.charCodeAt(pos) === marker) { pos++; }
count = pos - start;
@ -80,7 +81,7 @@ function parseEnd(state, start) {
}
// check condition 2, marker preceded by whitespace
if (lastChar === 0x20) { return -1; }
if (lastChar === 0x20 || lastChar === 0x0A) { return -1; }
if (marker === 0x5F) {
// check condition 3, if it's the end of the word

10
lib/rules_inline/strikethrough.js

@ -25,12 +25,12 @@ module.exports = function strikethrough(state) {
if (state.level >= state.options.level) { return false; }
lastChar = state.pending.length !== 0 ? state.pending.charCodeAt(state.pending.length - 1) : -1;
lastChar = start > 0 ? state.src.charCodeAt(start - 1) : -1;
nextChar = state.src.charCodeAt(start + 2);
if (lastChar === 0x7E/* ~ */) { return false; }
if (nextChar === 0x7E/* */) { return false; }
if (nextChar === 0x20/* */) { return false; }
if (nextChar === 0x20 || nextChar === 0x0A) { return false; }
pos = start + 2;
while (pos < max && state.src.charCodeAt(pos) === 0x7E/* ~ */) { pos++; }
@ -52,13 +52,13 @@ module.exports = function strikethrough(state) {
while (state.pos + 1 < max) {
if (state.src.charCodeAt(state.pos) === 0x7E/* ~ */) {
if (state.src.charCodeAt(state.pos + 1) === 0x7E/* ~ */) {
lastChar = state.pending.length !== 0 ? state.pending.charCodeAt(state.pending.length - 1) : -1;
lastChar = state.src.charCodeAt(state.pos - 1);
nextChar = state.pos + 2 < max ? state.src.charCodeAt(state.pos + 2) : -1;
if (nextChar !== 0x7E/* ~ */ && lastChar !== 0x7E/* ~ */) {
if (lastChar !== 0x20) {
if (lastChar !== 0x20 && lastChar !== 0x0A) {
// closing '~~'
stack--;
} else if (nextChar !== 0x20) {
} else if (nextChar !== 0x20 && nextChar !== 0x0A) {
// opening '~~'
stack++;
} // else {

43
test/fixtures/remarkable/regression.txt

@ -17,3 +17,46 @@ Regression tests for link backtracking optimizations:
<p>[[some unrelated text <a href="foo">[link]</a></p>
.
This is not a valid emphasis, because \n considered a whitespace:
.
**test
**
**
test**
**
test
**
.
<p>**test
**</p>
<p>**
test**</p>
<p>**
test
**</p>
.
Same for strikethrough:
.
~~test
~~
~~
test~~
~~
test
~~
.
<p>~~test
~~</p>
<p>~~
test~~</p>
<p>~~
test
~~</p>
.

Loading…
Cancel
Save