diff options
-rw-r--r-- | app.js | 107 | ||||
-rw-r--r-- | package.json | 3 |
2 files changed, 5 insertions, 105 deletions
@@ -3,114 +3,13 @@ const START = '[__'; const END = '__]'; +const parseAttr = require('md-attr-parser'); + function locator(value, fromIndex) { const index = value.indexOf(START, fromIndex); return index; } -function parseHTMLparam(value, indexNext) { - let letsEat = '{'; - indexNext++; - - const eat = chars => { - let eaten = ''; - while (chars.indexOf(value.charAt(indexNext)) >= 0) { - letsEat += value.charAt(indexNext); - eaten += value.charAt(indexNext); - indexNext++; - } - return eaten; - }; - const eatUntil = chars => { - let eaten = ''; - while (chars.indexOf(value.charAt(indexNext)) < 0) { - letsEat += value.charAt(indexNext); - eaten += value.charAt(indexNext); - indexNext++; - } - return eaten; - }; - - const prop = {key: undefined /* {} */, class: undefined /* [] */, id: undefined, type: 'text'}; - let type; - - while (value.charAt(indexNext) !== '}') { - let labelFirst = ''; - let labelSecond; - - eat(' \t\n\r\v'); - - if (value.charAt(indexNext) === '}') { // Fin l'accolade - continue; - } else if (value.charAt(indexNext) === '.') { // Classes - type = 'class'; - indexNext++; - letsEat += '.'; - } else if (value.charAt(indexNext) === '#') { // ID - type = 'id'; - indexNext++; - letsEat += '#'; - } else { // Key - type = 'key'; - } - - // Extract name - labelFirst = eatUntil('=\t\b\r\v }'); - - if (value.charAt(indexNext) === '=') { // Set labelSecond - indexNext++; - letsEat += '='; - - if (value.charAt(indexNext) === '"') { - indexNext++; - letsEat += '"'; - labelSecond = eatUntil('"}\n'); - - if (value.charAt(indexNext) === '"') { - indexNext++; - letsEat += '"'; - } else { - // Erreur - } - } else if (value.charAt(indexNext) === '\'') { - indexNext++; - letsEat += '\''; - labelSecond = eatUntil('\'}\n'); - - if (value.charAt(indexNext) === '\'') { - indexNext++; - letsEat += '\''; - } else { - // Erreur - } - } else { - labelSecond = eatUntil(' \t\n\r\v=}'); - } - } - switch (type) { - case 'id': // ID - prop.id = prop.id || labelFirst; - break; - case 'class': - if (!prop.class) { - prop.class = []; - } - prop.class.push(labelFirst); - break; - case 'key': - if (labelFirst !== 'id' && labelFirst !== 'class') { - prop[labelFirst] = labelSecond || ''; - } - break; - default: - - } - } - letsEat += '}'; - - return {type, prop, eaten: letsEat}; -} - function plugin() { function inlineTokenizer(eat, value, silent) { if (!this.options.gfm || !value.startsWith(START)) { @@ -133,7 +32,7 @@ function plugin() { let letsEat = ''; let prop = {key: undefined /* {} */, class: undefined /* [] */, id: undefined}; if (value.charAt(index + END.length) === '{') { - const res = parseHTMLparam(value, index + END.length); + const res = parseAttr(value, index + END.length); letsEat = res.eaten; prop = res.prop; } diff --git a/package.json b/package.json index 86ff3f0..bd021b6 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,8 @@ "start": "node app.js" }, "dependencies": { - "unist-util-visit": "^1.1.3" + "unist-util-visit": "^1.1.3", + "md-attr-parser": "^1.0.0" }, "author": "ache", "license": "MIT", |