Browse Source

Change priority for all pairs

`**foo __bar** baz__` is now parsed as `<strong>foo __bar</strong> baz__`
pull/14/head
Alex Kocharin 10 years ago
parent
commit
666e94a47a
  1. 5
      lib/parser_inline.js
  2. 15
      lib/rules_inline/del.js
  3. 9
      lib/rules_inline/emphasis.js
  4. 15
      lib/rules_inline/ins.js
  5. 21
      lib/rules_inline/mark.js
  6. 4
      test/fixtures/remarkable/del.txt
  7. 4
      test/fixtures/remarkable/ins.txt
  8. 4
      test/fixtures/remarkable/mark.txt

5
lib/parser_inline.js

@ -81,6 +81,11 @@ ParserInline.prototype.skipToken = function (state) {
}
for (i = 0; i < len; i++) {
// TODO: change it to rule chains somehow
if ([ 'autolink', 'backticks', 'escape', 'htmltag', 'links', 'text' ].indexOf(this._rules[i].name) === -1) {
continue;
}
if (this._rules[i](state, true)) {
state.cacheSet(pos, state.pos);
return;

15
lib/rules_inline/del.js

@ -5,6 +5,7 @@
module.exports = function del(state, silent) {
var found,
pos,
stack,
max = state.posMax,
start = state.pos,
lastChar,
@ -13,11 +14,6 @@ module.exports = function del(state, silent) {
if (state.src.charCodeAt(start) !== 0x7E/* ~ */) { return false; }
if (start + 4 >= max) { return false; }
if (state.src.charCodeAt(start + 1) !== 0x7E/* ~ */) { return false; }
// make del lower a priority tag with respect to links, same as <em>;
// this code also prevents recursion
if (silent && state.isInLabel) { return false; }
if (state.level >= state.options.maxNesting) { return false; }
lastChar = start > 0 ? state.src.charCodeAt(start - 1) : -1;
@ -37,6 +33,7 @@ module.exports = function del(state, silent) {
}
state.pos = start + 2;
stack = 1;
while (state.pos + 1 < max) {
if (state.src.charCodeAt(state.pos) === 0x7E/* ~ */) {
@ -46,6 +43,14 @@ module.exports = function del(state, silent) {
if (nextChar !== 0x7E/* ~ */ && lastChar !== 0x7E/* ~ */) {
if (lastChar !== 0x20 && lastChar !== 0x0A) {
// closing '~~'
stack--;
} else if (nextChar !== 0x20 && nextChar !== 0x0A) {
// opening '~~'
stack++;
} // else {
// // standalone ' ~~ ' indented with spaces
//}
if (stack <= 0) {
found = true;
break;
}

9
lib/rules_inline/emphasis.js

@ -62,11 +62,6 @@ module.exports = function emphasis(state, silent) {
if (marker !== 0x5F/* _ */ && marker !== 0x2A /* * */) { return false; }
// skip emphasis in links because it has lower priority, compare:
// [foo *bar]()*
// [foo `bar]()`
if (silent && state.isInLabel) { return false; }
res = scanDelims(state, start);
startCount = res.delims;
if (!res.can_open) {
@ -110,6 +105,10 @@ module.exports = function emphasis(state, silent) {
state.pos += count;
continue;
}
if (res.can_open) { stack.push(count); }
state.pos += count;
continue;
}
state.parser.skipToken(state);

15
lib/rules_inline/ins.js

@ -5,6 +5,7 @@
module.exports = function ins(state, silent) {
var found,
pos,
stack,
max = state.posMax,
start = state.pos,
lastChar,
@ -13,11 +14,6 @@ module.exports = function ins(state, silent) {
if (state.src.charCodeAt(start) !== 0x2B/* + */) { return false; }
if (start + 4 >= max) { return false; }
if (state.src.charCodeAt(start + 1) !== 0x2B/* + */) { return false; }
// make ins lower a priority tag with respect to links, same as <em>;
// this code also prevents recursion
if (silent && state.isInLabel) { return false; }
if (state.level >= state.options.maxNesting) { return false; }
lastChar = start > 0 ? state.src.charCodeAt(start - 1) : -1;
@ -37,6 +33,7 @@ module.exports = function ins(state, silent) {
}
state.pos = start + 2;
stack = 1;
while (state.pos + 1 < max) {
if (state.src.charCodeAt(state.pos) === 0x2B/* + */) {
@ -46,6 +43,14 @@ module.exports = function ins(state, silent) {
if (nextChar !== 0x2B/* + */ && lastChar !== 0x2B/* + */) {
if (lastChar !== 0x20 && lastChar !== 0x0A) {
// closing '++'
stack--;
} else if (nextChar !== 0x20 && nextChar !== 0x0A) {
// opening '++'
stack++;
} // else {
// // standalone ' ++ ' indented with spaces
//}
if (stack <= 0) {
found = true;
break;
}

21
lib/rules_inline/mark.js

@ -1,10 +1,11 @@
// Process ++inserted text++
// Process ==highlighted text==
'use strict';
module.exports = function mark(state, silent) {
module.exports = function del(state, silent) {
var found,
pos,
stack,
max = state.posMax,
start = state.pos,
lastChar,
@ -13,11 +14,6 @@ module.exports = function mark(state, silent) {
if (state.src.charCodeAt(start) !== 0x3D/* = */) { return false; }
if (start + 4 >= max) { return false; }
if (state.src.charCodeAt(start + 1) !== 0x3D/* = */) { return false; }
// make ins lower a priority tag with respect to links, same as <em>;
// this code also prevents recursion
if (silent && state.isInLabel) { return false; }
if (state.level >= state.options.maxNesting) { return false; }
lastChar = start > 0 ? state.src.charCodeAt(start - 1) : -1;
@ -37,6 +33,7 @@ module.exports = function mark(state, silent) {
}
state.pos = start + 2;
stack = 1;
while (state.pos + 1 < max) {
if (state.src.charCodeAt(state.pos) === 0x3D/* = */) {
@ -45,7 +42,15 @@ module.exports = function mark(state, silent) {
nextChar = state.pos + 2 < max ? state.src.charCodeAt(state.pos + 2) : -1;
if (nextChar !== 0x3D/* = */ && lastChar !== 0x3D/* = */) {
if (lastChar !== 0x20 && lastChar !== 0x0A) {
// closing '++'
// closing '=='
stack--;
} else if (nextChar !== 0x20 && nextChar !== 0x0A) {
// opening '=='
stack++;
} // else {
// // standalone ' == ' indented with spaces
//}
if (stack <= 0) {
found = true;
break;
}

4
test/fixtures/remarkable/del.txt

@ -25,8 +25,8 @@ Strikeouts have the same priority as emphases:
~~**test~~**
.
<p>**<del>test**</del></p>
<p>~~<strong>test~~</strong></p>
<p><strong>~~test</strong>~~</p>
<p><del>**test</del>**</p>
.
Strikeouts have the same priority as emphases with respect to links:

4
test/fixtures/remarkable/ins.txt

@ -25,8 +25,8 @@ Inserts have the same priority as emphases:
++**test++**
.
<p>**<ins>test**</ins></p>
<p>++<strong>test++</strong></p>
<p><strong>++test</strong>++</p>
<p><ins>**test</ins>**</p>
.
Inserts have the same priority as emphases with respect to links:

4
test/fixtures/remarkable/mark.txt

@ -25,8 +25,8 @@ Marks have the same priority as emphases:
==**test==**
.
<p>**<mark>test**</mark></p>
<p>==<strong>test==</strong></p>
<p><strong>==test</strong>==</p>
<p><mark>**test</mark>**</p>
.
Marks have the same priority as emphases with respect to links:

Loading…
Cancel
Save