From c0ccaa79ceed2551d483fb2debec138ba63e785e Mon Sep 17 00:00:00 2001 From: Vitaly Puzrin Date: Sun, 4 Jan 2015 00:16:23 +0300 Subject: [PATCH] Removed abbr rules (move to plugin) --- lib/parser_block.js | 1 - lib/parser_core.js | 1 - lib/presets/commonmark.js | 3 +- lib/presets/default.js | 1 - lib/renderer.js | 8 --- lib/rules_block/abbr.js | 48 --------------- lib/rules_core/abbr2.js | 91 ----------------------------- test/fixtures/markdown-it/abbr.txt | 81 ------------------------- test/fixtures/markdown-it/proto.txt | 16 ----- 9 files changed, 1 insertion(+), 249 deletions(-) delete mode 100644 lib/rules_block/abbr.js delete mode 100644 lib/rules_core/abbr2.js delete mode 100644 test/fixtures/markdown-it/abbr.txt diff --git a/lib/parser_block.js b/lib/parser_block.js index f21b10e..23df821 100644 --- a/lib/parser_block.js +++ b/lib/parser_block.js @@ -15,7 +15,6 @@ var _rules = [ [ 'blockquote', require('./rules_block/blockquote'), [ 'paragraph', 'reference', 'blockquote', 'list' ] ], [ 'hr', require('./rules_block/hr'), [ 'paragraph', 'reference', 'blockquote', 'list' ] ], [ 'list', require('./rules_block/list'), [ 'paragraph', 'reference', 'blockquote' ] ], - [ 'abbr', require('./rules_block/abbr'), [ 'paragraph', 'reference' ] ], [ 'footnote', require('./rules_block/footnote'), [ 'paragraph', 'reference' ] ], [ 'reference', require('./rules_block/reference'), [ 'reference' ] ], [ 'heading', require('./rules_block/heading'), [ 'paragraph', 'reference', 'blockquote' ] ], diff --git a/lib/parser_core.js b/lib/parser_core.js index d3072f8..04cbb13 100644 --- a/lib/parser_core.js +++ b/lib/parser_core.js @@ -14,7 +14,6 @@ var _rules = [ [ 'block', require('./rules_core/block') ], [ 'inline', require('./rules_core/inline') ], [ 'footnote_tail', require('./rules_core/footnote_tail') ], - [ 'abbr2', require('./rules_core/abbr2') ], [ 'replacements', require('./rules_core/replacements') ], [ 'smartquotes', require('./rules_core/smartquotes') ], [ 'linkify', require('./rules_core/linkify') ] diff --git a/lib/presets/commonmark.js b/lib/presets/commonmark.js index 2cb61fe..670a68c 100644 --- a/lib/presets/commonmark.js +++ b/lib/presets/commonmark.js @@ -33,8 +33,7 @@ module.exports = { core: { rules: [ 'block', - 'inline', - 'abbr2' + 'inline' ] }, diff --git a/lib/presets/default.js b/lib/presets/default.js index b8c234d..cd16b75 100644 --- a/lib/presets/default.js +++ b/lib/presets/default.js @@ -37,7 +37,6 @@ module.exports = { 'replacements', 'linkify', 'smartquotes', - 'abbr2', 'footnote_tail' ] }, diff --git a/lib/renderer.js b/lib/renderer.js index f6685f7..21e8a42 100644 --- a/lib/renderer.js +++ b/lib/renderer.js @@ -231,14 +231,6 @@ rules.htmltag = function (tokens, idx /*, options, env */) { }; -rules.abbr_open = function (tokens, idx /*, options, env */) { - return ''; -}; -rules.abbr_close = function (/* tokens, idx, options, env */) { - return ''; -}; - - rules.footnote_ref = function (tokens, idx) { var n = Number(tokens[idx].id + 1).toString(); var id = 'fnref' + n; diff --git a/lib/rules_block/abbr.js b/lib/rules_block/abbr.js deleted file mode 100644 index 6113ad2..0000000 --- a/lib/rules_block/abbr.js +++ /dev/null @@ -1,48 +0,0 @@ -// Parse abbreviation definitions, i.e. `*[abbr]: description` -// - -'use strict'; - - -module.exports = function parseAbbr(state, startLine, endLine, silent) { - var label, title, ch, labelStart, labelEnd, - pos = state.bMarks[startLine] + state.tShift[startLine], - max = state.eMarks[startLine]; - - if (pos + 2 >= max) { return false; } - - if (state.src.charCodeAt(pos++) !== 0x2A/* * */) { return false; } - if (state.src.charCodeAt(pos++) !== 0x5B/* [ */) { return false; } - - labelStart = pos; - - for (; pos < max; pos++) { - ch = state.src.charCodeAt(pos); - if (ch === 0x5B /* [ */) { - return false; - } else if (ch === 0x5D /* ] */) { - labelEnd = pos; - break; - } else if (ch === 0x5C /* \ */) { - pos++; - } - } - - if (labelEnd < 0 || state.src.charCodeAt(labelEnd + 1) !== 0x3A/* : */) { - return false; - } - - if (silent) { return true; } - - label = state.src.slice(labelStart, labelEnd).replace(/\\(.)/g, '$1'); - title = state.src.slice(labelEnd + 2, max).trim(); - if (title.length === 0) { return false; } - if (!state.env.abbreviations) { state.env.abbreviations = {}; } - // prepend ':' to avoid conflict with Object.prototype members - if (typeof state.env.abbreviations[':' + label] === 'undefined') { - state.env.abbreviations[':' + label] = title; - } - - state.line = startLine + 1; - return true; -}; diff --git a/lib/rules_core/abbr2.js b/lib/rules_core/abbr2.js deleted file mode 100644 index 0a3315c..0000000 --- a/lib/rules_core/abbr2.js +++ /dev/null @@ -1,91 +0,0 @@ -// Enclose abbreviations in tags -// -'use strict'; - - -var arrayReplaceAt = require('../common/utils').arrayReplaceAt; - - -var PUNCT_CHARS = ' \n()[]\'".,!?-'; - - -// from Google closure library -// http://closure-library.googlecode.com/git-history/docs/local_closure_goog_string_string.js.source.html#line1021 -function regEscape(s) { - return s.replace(/([-()\[\]{}+?*.$\^|,:#= 0; i--) { - token = tokens[i]; - if (token.type !== 'text') { continue; } - - pos = 0; - text = token.content; - reg.lastIndex = 0; - level = token.level; - nodes = []; - - while ((m = reg.exec(text))) { - if (reg.lastIndex > pos) { - nodes.push({ - type: 'text', - content: text.slice(pos, m.index + m[1].length), - level: level - }); - } - - nodes.push({ - type: 'abbr_open', - title: state.env.abbreviations[':' + m[2]], - level: level++ - }); - nodes.push({ - type: 'text', - content: m[2], - level: level - }); - nodes.push({ - type: 'abbr_close', - level: --level - }); - pos = reg.lastIndex - m[3].length; - } - - if (!nodes.length) { continue; } - - if (pos < text.length) { - nodes.push({ - type: 'text', - content: text.slice(pos), - level: level - }); - } - - // replace current node - blockTokens[j].children = tokens = arrayReplaceAt(tokens, i, nodes); - } - } -}; diff --git a/test/fixtures/markdown-it/abbr.txt b/test/fixtures/markdown-it/abbr.txt deleted file mode 100644 index 009ebc3..0000000 --- a/test/fixtures/markdown-it/abbr.txt +++ /dev/null @@ -1,81 +0,0 @@ - -An example from php markdown readme: - -. -*[HTML]: Hyper Text Markup Language -*[W3C]: World Wide Web Consortium -The HTML specification -is maintained by the W3C. -. -

The HTML specification -is maintained by the W3C.

-. - -They can contain arbitrary markup (see pandoc implementation): - -. -*[`\]:`]: foo -\`]:\` -. -

`]:`

-. - -No empty abbreviations: - -. -*[foo]: -foo -. -

*[foo]: -foo

-. - -Intersecting abbreviations (first should match): - -. -*[Bar Foo]: 123 -*[Foo Bar]: 456 - -Foo Bar Foo - -Bar Foo Bar -. -

Foo Bar Foo

-

Bar Foo Bar

-. - -Don't bother with nested abbreviations (yet?): - -. -*[JS]: javascript -*[HTTP]: hyper text blah blah -*[JS HTTP]: is awesome -JS HTTP is a collection of low-level javascript HTTP-related modules -. -

JS HTTP is a collection of low-level javascript HTTP-related modules

-. - -Mixing up abbreviations and references: - -. -*[foo]: 123 -[bar]: 456 -*[baz]: 789 -[quux]: 012 -and a paragraph continuation - -foo [bar] baz [quux] -. -

and a paragraph continuation

-

foo bar baz quux

-. - -Don't match the middle of the string: - -. -*[foo]: blah -*[bar]: blah -foobar -. -

foobar

-. diff --git a/test/fixtures/markdown-it/proto.txt b/test/fixtures/markdown-it/proto.txt index cad943a..cbefa8c 100644 --- a/test/fixtures/markdown-it/proto.txt +++ b/test/fixtures/markdown-it/proto.txt @@ -22,14 +22,6 @@ . -. -*[__proto__]: blah - -__proto__ \_\_proto\_\_ -. -

proto __proto__

-. - . [hasOwnProperty] @@ -52,11 +44,3 @@ __proto__ \_\_proto\_\_ . - -. -*[hasOwnProperty]: blah - -hasOwnProperty -. -

hasOwnProperty

-.