From a9489e1f79219b6f4fd7ecf382654a77dd09b5cc Mon Sep 17 00:00:00 2001 From: Geoff Rich Date: Wed, 30 Dec 2020 15:55:22 -0800 Subject: [PATCH] refactor: remove unnecessary complexity --- site/src/routes/docs/_sections.js | 2 +- site/src/utils/attributes.js | 30 +++++++++--------------------- 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/site/src/routes/docs/_sections.js b/site/src/routes/docs/_sections.js index ba4a8bc86e..cc72a220c4 100644 --- a/site/src/routes/docs/_sections.js +++ b/site/src/routes/docs/_sections.js @@ -112,7 +112,7 @@ export default function() { } return ` - + 4 || tocIgnore ? 'data-scrollignore' : ''}> ${text} diff --git a/site/src/utils/attributes.js b/site/src/utils/attributes.js index c000814147..d474e90786 100644 --- a/site/src/utils/attributes.js +++ b/site/src/utils/attributes.js @@ -1,16 +1,15 @@ const ATTRS_REGEX = /^(.+)\s+\{(.+)\}$/; /** - * Extracts attributes from markdown text to be applied to the resulting HTML. + * Extracts attributes from Markdown text. * @example * // returns { * // text: 'Heading', * // raw: 'Heading', - * // attrs: { id: 'important', class: 'red', test: 'true' }, - * // attrstring: 'id="important" class="red" test="true"' + * // attrs: { test: 'true' } * // } * extract_attributes( - * 'Heading { #important .red test=true }', - * 'Heading { #important .red test=true }' + * 'Heading { test=true }', + * 'Heading { test=true }' * ); * ``` * @param {string} text @@ -25,16 +24,14 @@ export function extract_attributes(text, raw) { return { text: textMatch ? textMatch[1] : text, raw: rawMatch ? rawMatch[1] : raw, - attrs, - attrstring: Object.keys(attrs).map(key => `${key}="${attrs[key].trim()}"`).join(' ') + attrs } } catch (err) { console.log(err); return { text, raw, - attrs: {}, - attrstring: '' + attrs: {} }; } } @@ -44,18 +41,9 @@ function parse_attributes(raw_attributes) { const result = { }; attributes.forEach(attr => { if (!attr) return; - if (attr.startsWith('#')) { - result.id = attr.substring(1); - } else if (attr.startsWith('.')) { - if (!result.class) { - result.class = ''; - } - result.class += attr.substring(1) + ' '; - } else { - let [key, value = ''] = attr.split('='); - result[key] = value; - } - }) + let [key, value = ''] = attr.split('='); + result[key] = value; + }); return result; }