From 2f879aa5ba2e8e7e3a304beaba16c3cd4dbf370f Mon Sep 17 00:00:00 2001 From: arve0 Date: Sun, 20 May 2018 13:55:15 +0200 Subject: [PATCH] utils.getAttrs: remove unused end parameter --- patterns.js | 18 +++++++++--------- test.js | 4 ++-- utils.js | 7 +++---- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/patterns.js b/patterns.js index 13a24f5..2d1906c 100644 --- a/patterns.js +++ b/patterns.js @@ -25,7 +25,7 @@ module.exports = options => ([ transform: (tokens, i) => { let token = tokens[i]; let start = token.info.lastIndexOf(options.leftDelimiter); - let attrs = utils.getAttrs(token.info, start, null, options); + let attrs = utils.getAttrs(token.info, start, options); utils.addAttrs(attrs, token); token.info = utils.removeDelimiter(token.info, options); } @@ -57,7 +57,7 @@ module.exports = options => ([ let token = tokens[i].children[j]; let endChar = token.content.indexOf(options.rightDelimiter); let attrToken = tokens[i].children[j - 1]; - let attrs = utils.getAttrs(token.content, 0, null, options); + let attrs = utils.getAttrs(token.content, 0, options); utils.addAttrs(attrs, attrToken); if (token.content.length === (endChar + 1)) { tokens[i].children.splice(j, 1); @@ -91,7 +91,7 @@ module.exports = options => ([ transform: (tokens, i) => { let token = tokens[i + 2]; let tableOpen = utils.getMatchingOpeningToken(tokens, i); - let attrs = utils.getAttrs(token.content, 0, null, options); + let attrs = utils.getAttrs(token.content, 0, options); // add attributes utils.addAttrs(attrs, tableOpen); // remove

{.c}

@@ -121,7 +121,7 @@ module.exports = options => ([ transform: (tokens, i, j) => { let token = tokens[i].children[j]; let content = token.content; - let attrs = utils.getAttrs(content, 0, null, options); + let attrs = utils.getAttrs(content, 0, options); let openingToken = utils.getMatchingOpeningToken(tokens[i].children, j - 1); utils.addAttrs(attrs, openingToken); token.content = content.slice(content.indexOf(options.rightDelimiter) + 1); @@ -153,7 +153,7 @@ module.exports = options => ([ transform: (tokens, i, j) => { let token = tokens[i].children[j]; let content = token.content; - let attrs = utils.getAttrs(content, 0, null, options); + let attrs = utils.getAttrs(content, 0, options); let ii = i - 2; while (tokens[ii - 1] && tokens[ii - 1].type !== 'ordered_list_open' && @@ -194,7 +194,7 @@ module.exports = options => ([ transform: (tokens, i) => { let token = tokens[i + 2]; let content = token.content; - let attrs = utils.getAttrs(content, 0, null, options); + let attrs = utils.getAttrs(content, 0, options); let openingToken = utils.getMatchingOpeningToken(tokens, i); utils.addAttrs(attrs, openingToken); tokens.splice(i + 1, 3); @@ -222,7 +222,7 @@ module.exports = options => ([ transform: (tokens, i, j) => { let token = tokens[i].children[j]; let content = token.content; - let attrs = utils.getAttrs(content, content.lastIndexOf(options.leftDelimiter), null, options); + let attrs = utils.getAttrs(content, content.lastIndexOf(options.leftDelimiter), options); utils.addAttrs(attrs, tokens[i - 2]); let trimmed = content.slice(0, content.lastIndexOf(options.leftDelimiter)); token.content = last(trimmed) !== ' ' ? @@ -252,7 +252,7 @@ module.exports = options => ([ ], transform: (tokens, i, j) => { let token = tokens[i].children[j]; - let attrs = utils.getAttrs(token.content, 0, null, options); + let attrs = utils.getAttrs(token.content, 0, options); // find last closing tag let ii = i + 1; while (tokens[ii + 1] && tokens[ii + 1].nesting === -1) { ii++; } @@ -281,7 +281,7 @@ module.exports = options => ([ transform: (tokens, i, j) => { let token = tokens[i].children[j]; let content = token.content; - let attrs = utils.getAttrs(content, content.lastIndexOf(options.leftDelimiter), null, options); + let attrs = utils.getAttrs(content, content.lastIndexOf(options.leftDelimiter), options); let ii = i + 1; while (tokens[ii + 1] && tokens[ii + 1].nesting === -1) { ii++; } let openingToken = utils.getMatchingOpeningToken(tokens, ii); diff --git a/test.js b/test.js index 68595ca..db0598a 100644 --- a/test.js +++ b/test.js @@ -15,14 +15,14 @@ describe('markdown-it-attrs.utils', () => { it('should parse {.class ..css-module #id key=val}', () => { let src = '{.red ..mod #head key=val}'; let expected = [['class', 'red'], ['css-module', 'mod'], ['id', 'head'], ['key', 'val']]; - let res = utils.getAttrs(src, 0, null, options); + let res = utils.getAttrs(src, 0, options); assert.deepEqual(res, expected); }); it('should parse [.class ..css-module #id key=val]', () => { let src = '[.red ..mod #head key=val]'; let expected = [['class', 'red'], ['css-module', 'mod'], ['id', 'head'], ['key', 'val']]; - let res = utils.getAttrs(src, 0, null, { + let res = utils.getAttrs(src, 0, { leftDelimiter: '[', rightDelimiter: ']' }); diff --git a/utils.js b/utils.js index e0efcd4..9b7ba46 100644 --- a/utils.js +++ b/utils.js @@ -5,8 +5,7 @@ * @param {int} start: where to start parsing (including {) * @returns {2d array}: [['key', 'val'], ['class', 'red']] */ -exports.getAttrs = function (str, start, end, options) { - // TODO: do not require `end`, stop when } is found +exports.getAttrs = function (str, start, options) { // not tab, line feed, form feed, space, solidus, greater than sign, quotation mark, apostrophe and equals sign const allowedKeyChars = /[^\t\n\f />"'=]/; const pairSeparator = ' '; @@ -67,7 +66,7 @@ exports.getAttrs = function (str, start, end, options) { } // read next key/value pair - if ((char_ === pairSeparator && !valueInsideQuotes) || i === end) { + if ((char_ === pairSeparator && !valueInsideQuotes)) { if (key === '') { // beginning or ending space: { .red } vs {.red} continue; @@ -142,7 +141,7 @@ exports.hasDelimiter = function (where, options) { return false; } - function validCurlyLength(curly) { + function validCurlyLength (curly) { let isClass = curly.charAt(1) === '.'; let isId = curly.charAt(1) === '#'; return (isClass || isId)