From 2c433e10a083af67f57c0e80fa9c8edbb5014948 Mon Sep 17 00:00:00 2001 From: Vitaly Puzrin Date: Thu, 1 Jan 2015 04:54:47 +0300 Subject: [PATCH] Moved ins/mark/sub/sup to plugins --- lib/parser_inline.js | 4 -- lib/rules_inline/ins.js | 101 ---------------------------- lib/rules_inline/mark.js | 101 ---------------------------- lib/rules_inline/sub.js | 59 ---------------- lib/rules_inline/sup.js | 59 ---------------- test/fixtures/markdown-it/del.txt | 11 +-- test/fixtures/markdown-it/ins.txt | 104 ----------------------------- test/fixtures/markdown-it/mark.txt | 102 ---------------------------- test/fixtures/markdown-it/sub.txt | 36 ---------- test/fixtures/markdown-it/sup.txt | 42 ------------ 10 files changed, 6 insertions(+), 613 deletions(-) delete mode 100644 lib/rules_inline/ins.js delete mode 100644 lib/rules_inline/mark.js delete mode 100644 lib/rules_inline/sub.js delete mode 100644 lib/rules_inline/sup.js delete mode 100644 test/fixtures/markdown-it/ins.txt delete mode 100644 test/fixtures/markdown-it/mark.txt delete mode 100644 test/fixtures/markdown-it/sub.txt delete mode 100644 test/fixtures/markdown-it/sup.txt diff --git a/lib/parser_inline.js b/lib/parser_inline.js index 2dfd0d9..a3408ba 100644 --- a/lib/parser_inline.js +++ b/lib/parser_inline.js @@ -18,11 +18,7 @@ var _rules = [ [ 'escape', require('./rules_inline/escape') ], [ 'backticks', require('./rules_inline/backticks') ], [ 'del', require('./rules_inline/del') ], - [ 'ins', require('./rules_inline/ins') ], - [ 'mark', require('./rules_inline/mark') ], [ 'emphasis', require('./rules_inline/emphasis') ], - [ 'sub', require('./rules_inline/sub') ], - [ 'sup', require('./rules_inline/sup') ], [ 'links', require('./rules_inline/links') ], [ 'footnote_inline', require('./rules_inline/footnote_inline') ], [ 'footnote_ref', require('./rules_inline/footnote_ref') ], diff --git a/lib/rules_inline/ins.js b/lib/rules_inline/ins.js deleted file mode 100644 index 1645822..0000000 --- a/lib/rules_inline/ins.js +++ /dev/null @@ -1,101 +0,0 @@ -'use strict'; - - -// parse sequence of markers, -// "start" should point at a valid marker -function scanDelims(state, start) { - var pos = start, lastChar, nextChar, count, - can_open = true, - can_close = true, - max = state.posMax, - marker = state.src.charCodeAt(start); - - lastChar = start > 0 ? state.src.charCodeAt(start - 1) : -1; - - while (pos < max && state.src.charCodeAt(pos) === marker) { pos++; } - if (pos >= max) { can_open = false; } - count = pos - start; - - nextChar = pos < max ? state.src.charCodeAt(pos) : -1; - - // check whitespace conditions - if (nextChar === 0x20 || nextChar === 0x0A) { can_open = false; } - if (lastChar === 0x20 || lastChar === 0x0A) { can_close = false; } - - return { - can_open: can_open, - can_close: can_close, - delims: count - }; -} - -module.exports = function(state, silent) { - var startCount, - count, - tagCount, - found, - stack, - res, - max = state.posMax, - start = state.pos, - marker = state.src.charCodeAt(start); - - if (marker !== 0x2B/* + */) { return false; } - if (silent) { return false; } // don't run any pairs in validation mode - - res = scanDelims(state, start); - startCount = res.delims; - if (!res.can_open) { - state.pos += startCount; - if (!silent) { state.pending += state.src.slice(start, state.pos); } - return true; - } - - stack = Math.floor(startCount / 2); - if (stack <= 0) { return false; } - state.pos = start + startCount; - - while (state.pos < max) { - if (state.src.charCodeAt(state.pos) === marker) { - res = scanDelims(state, state.pos); - count = res.delims; - tagCount = Math.floor(count / 2); - if (res.can_close) { - if (tagCount >= stack) { - state.pos += count - 2; - found = true; - break; - } - stack -= tagCount; - state.pos += count; - continue; - } - - if (res.can_open) { stack += tagCount; } - state.pos += count; - continue; - } - - state.md.inline.skipToken(state); - } - - if (!found) { - // parser failed to find ending tag, so it's not valid emphasis - state.pos = start; - return false; - } - - // found! - state.posMax = state.pos; - state.pos = start + 2; - - if (!silent) { - state.push({ type: 'ins_open', level: state.level++ }); - state.md.inline.tokenize(state); - state.push({ type: 'ins_close', level: --state.level }); - } - - state.pos = state.posMax + 2; - state.posMax = max; - return true; -}; diff --git a/lib/rules_inline/mark.js b/lib/rules_inline/mark.js deleted file mode 100644 index da588df..0000000 --- a/lib/rules_inline/mark.js +++ /dev/null @@ -1,101 +0,0 @@ -'use strict'; - - -// parse sequence of markers, -// "start" should point at a valid marker -function scanDelims(state, start) { - var pos = start, lastChar, nextChar, count, - can_open = true, - can_close = true, - max = state.posMax, - marker = state.src.charCodeAt(start); - - lastChar = start > 0 ? state.src.charCodeAt(start - 1) : -1; - - while (pos < max && state.src.charCodeAt(pos) === marker) { pos++; } - if (pos >= max) { can_open = false; } - count = pos - start; - - nextChar = pos < max ? state.src.charCodeAt(pos) : -1; - - // check whitespace conditions - if (nextChar === 0x20 || nextChar === 0x0A) { can_open = false; } - if (lastChar === 0x20 || lastChar === 0x0A) { can_close = false; } - - return { - can_open: can_open, - can_close: can_close, - delims: count - }; -} - -module.exports = function(state, silent) { - var startCount, - count, - tagCount, - found, - stack, - res, - max = state.posMax, - start = state.pos, - marker = state.src.charCodeAt(start); - - if (marker !== 0x3D/* = */) { return false; } - if (silent) { return false; } // don't run any pairs in validation mode - - res = scanDelims(state, start); - startCount = res.delims; - if (!res.can_open) { - state.pos += startCount; - if (!silent) { state.pending += state.src.slice(start, state.pos); } - return true; - } - - stack = Math.floor(startCount / 2); - if (stack <= 0) { return false; } - state.pos = start + startCount; - - while (state.pos < max) { - if (state.src.charCodeAt(state.pos) === marker) { - res = scanDelims(state, state.pos); - count = res.delims; - tagCount = Math.floor(count / 2); - if (res.can_close) { - if (tagCount >= stack) { - state.pos += count - 2; - found = true; - break; - } - stack -= tagCount; - state.pos += count; - continue; - } - - if (res.can_open) { stack += tagCount; } - state.pos += count; - continue; - } - - state.md.inline.skipToken(state); - } - - if (!found) { - // parser failed to find ending tag, so it's not valid emphasis - state.pos = start; - return false; - } - - // found! - state.posMax = state.pos; - state.pos = start + 2; - - if (!silent) { - state.push({ type: 'mark_open', level: state.level++ }); - state.md.inline.tokenize(state); - state.push({ type: 'mark_close', level: --state.level }); - } - - state.pos = state.posMax + 2; - state.posMax = max; - return true; -}; diff --git a/lib/rules_inline/sub.js b/lib/rules_inline/sub.js deleted file mode 100644 index e468e67..0000000 --- a/lib/rules_inline/sub.js +++ /dev/null @@ -1,59 +0,0 @@ -// Process ~subscript~ - -'use strict'; - -// same as UNESCAPE_MD_RE plus a space -var UNESCAPE_RE = /\\([ \\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g; - -module.exports = function sub(state, silent) { - var found, - content, - max = state.posMax, - start = state.pos; - - if (state.src.charCodeAt(start) !== 0x7E/* ~ */) { return false; } - if (silent) { return false; } // don't run any pairs in validation mode - if (start + 2 >= max) { return false; } - - state.pos = start + 1; - - while (state.pos < max) { - if (state.src.charCodeAt(state.pos) === 0x7E/* ~ */) { - found = true; - break; - } - - state.md.inline.skipToken(state); - } - - if (!found || start + 1 === state.pos) { - state.pos = start; - return false; - } - - content = state.src.slice(start + 1, state.pos); - - // don't allow unescaped spaces/newlines inside - if (content.match(/(^|[^\\])(\\\\)*\s/)) { - state.pos = start; - return false; - } - - // found! - state.posMax = state.pos; - state.pos = start + 1; - - if (!silent) { - state.push({ type: 'sub_open', level: state.level++ }); - state.push({ - type: 'text', - level: state.level, - content: content.replace(UNESCAPE_RE, '$1') - }); - state.push({ type: 'sub_close', level: --state.level }); - } - - state.pos = state.posMax + 1; - state.posMax = max; - return true; -}; diff --git a/lib/rules_inline/sup.js b/lib/rules_inline/sup.js deleted file mode 100644 index 8a184bd..0000000 --- a/lib/rules_inline/sup.js +++ /dev/null @@ -1,59 +0,0 @@ -// Process ^superscript^ - -'use strict'; - -// same as UNESCAPE_MD_RE plus a space -var UNESCAPE_RE = /\\([ \\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g; - -module.exports = function sup(state, silent) { - var found, - content, - max = state.posMax, - start = state.pos; - - if (state.src.charCodeAt(start) !== 0x5E/* ^ */) { return false; } - if (silent) { return false; } // don't run any pairs in validation mode - if (start + 2 >= max) { return false; } - - state.pos = start + 1; - - while (state.pos < max) { - if (state.src.charCodeAt(state.pos) === 0x5E/* ^ */) { - found = true; - break; - } - - state.md.inline.skipToken(state); - } - - if (!found || start + 1 === state.pos) { - state.pos = start; - return false; - } - - content = state.src.slice(start + 1, state.pos); - - // don't allow unescaped spaces/newlines inside - if (content.match(/(^|[^\\])(\\\\)*\s/)) { - state.pos = start; - return false; - } - - // found! - state.posMax = state.pos; - state.pos = start + 1; - - if (!silent) { - state.push({ type: 'sup_open', level: state.level++ }); - state.push({ - type: 'text', - level: state.level, - content: content.replace(UNESCAPE_RE, '$1') - }); - state.push({ type: 'sup_close', level: --state.level }); - } - - state.pos = state.posMax + 1; - state.posMax = max; - return true; -}; diff --git a/test/fixtures/markdown-it/del.txt b/test/fixtures/markdown-it/del.txt index 5e2035f..65e7933 100644 --- a/test/fixtures/markdown-it/del.txt +++ b/test/fixtures/markdown-it/del.txt @@ -22,11 +22,12 @@ x ~~~~foo~~~~

x foo

. -. -x ~~~foo~~~ -. -

x foo

-. +# Disabled since we moved subsripts to plugins +#. +#x ~~~foo~~~ +#. +#

x foo

+#. Strikeouts have the same priority as emphases: diff --git a/test/fixtures/markdown-it/ins.txt b/test/fixtures/markdown-it/ins.txt deleted file mode 100644 index 5f3e067..0000000 --- a/test/fixtures/markdown-it/ins.txt +++ /dev/null @@ -1,104 +0,0 @@ -. -++Insert++ -. -

Insert

-. - - -. -x ++++foo++ bar++ -. -

x foo bar

-. - -. -x ++foo ++bar++++ -. -

x foo bar

-. - -. -x ++++foo++++ -. -

x foo

-. - -. -x +++foo+++ -. -

x +foo+

-. - -Inserts have the same priority as emphases: - -. -**++test**++ - -++**test++** -. -

++test++

-

**test**

-. - -Inserts have the same priority as emphases with respect to links: -. -[++link]()++ - -++[link++]() -. -

++link++

-

++link++

-. - -Inserts have the same priority as emphases with respect to backticks: -. -++`code++` - -`++code`++ -. -

++code++

-

++code++

-. - -Nested inserts: -. -++foo ++bar++ baz++ -. -

foo bar baz

-. - -. -++f **o ++o b++ a** r++ -. -

f o o b a r

-. - -Should not have a whitespace between text and "++": -. -foo ++ bar ++ baz -. -

foo ++ bar ++ baz

-. - - -Newline should be considered a whitespace: - -. -++test -++ - -++ -test++ - -++ -test -++ -. -

++test -++

-

++ -test++

-

++ -test -++

-. diff --git a/test/fixtures/markdown-it/mark.txt b/test/fixtures/markdown-it/mark.txt deleted file mode 100644 index 26cd70a..0000000 --- a/test/fixtures/markdown-it/mark.txt +++ /dev/null @@ -1,102 +0,0 @@ -. -==Mark== -. -

Mark

-. - -. -x ====foo== bar== -. -

x foo bar

-. - -. -x ==foo ==bar==== -. -

x foo bar

-. - -. -x ====foo==== -. -

x foo

-. - -. -x ===foo=== -. -

x =foo=

-. - -Marks have the same priority as emphases: - -. -**==test**== - -==**test==** -. -

==test==

-

**test**

-. - -Marks have the same priority as emphases with respect to links: -. -[==link]()== - -==[link==]() -. -

==link==

-

==link==

-. - -Marks have the same priority as emphases with respect to backticks: -. -==`code==` - -`==code`== -. -

==code==

-

==code==

-. - -Nested marks: -. -==foo ==bar== baz== -. -

foo bar baz

-. - -. -==f **o ==o b== a** r== -. -

f o o b a r

-. - -Should not have a whitespace between text and "==": -. -foo == bar == baz -. -

foo == bar == baz

-. - - -Newline should be considered a whitespace: - -. -==test -== - -== -test== - -== -test -== -. -

==test

-

== -test==

-

== -test -==

-. diff --git a/test/fixtures/markdown-it/sub.txt b/test/fixtures/markdown-it/sub.txt deleted file mode 100644 index f4c7804..0000000 --- a/test/fixtures/markdown-it/sub.txt +++ /dev/null @@ -1,36 +0,0 @@ - -. -~foo\~ -. -

~foo~

-. - -. -~foo bar~ -. -

~foo bar~

-. - -. -~foo\ bar\ baz~ -. -

foo bar baz

-. - -. -~\ foo\ ~ -. -

foo

-. - -. -~foo\\\\\\\ bar~ -. -

foo\\\ bar

-. - -. -~foo\\\\\\ bar~ -. -

~foo\\\ bar~

-. diff --git a/test/fixtures/markdown-it/sup.txt b/test/fixtures/markdown-it/sup.txt deleted file mode 100644 index 1db493f..0000000 --- a/test/fixtures/markdown-it/sup.txt +++ /dev/null @@ -1,42 +0,0 @@ - -. -^test^ -. -

test

-. - -. -^foo\^ -. -

^foo^

-. - -. -2^4 + 3^5 -. -

2^4 + 3^5

-. - -. -^foo~bar^baz^bar~foo^ -. -

foo~barbazbar~foo

-. - -. -^\ foo\ ^ -. -

foo

-. - -. -^foo\\\\\\\ bar^ -. -

foo\\\ bar

-. - -. -^foo\\\\\\ bar^ -. -

^foo\\\ bar^

-.