From e9cb50f4c92e88739fb3af99ea6abc1f06826e3c Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Thu, 15 Sep 2022 23:28:55 -0300 Subject: new html.noEdgeWhitespace tag option --- src/misc-templates.js | 5 ++++- src/util/html.js | 26 ++++++++++++++++++++------ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/misc-templates.js b/src/misc-templates.js index b5a635d..09c8f43 100644 --- a/src/misc-templates.js +++ b/src/misc-templates.js @@ -101,7 +101,10 @@ export function getArtistString( const externalLinks = hasExternalPart && html.tag('span', - {class: 'icons'}, + { + [html.noEdgeWhitespace]: true, + class: 'icons' + }, language.formatUnitList( urls.map(url => iconifyURL(url, {language})))); diff --git a/src/util/html.js b/src/util/html.js index bdb385b..752291e 100644 --- a/src/util/html.js +++ b/src/util/html.js @@ -32,6 +32,14 @@ export const onlyIfContent = Symbol(); // string. export const joinChildren = Symbol(); +// Pass to tag() as an attributes key to prevent additional whitespace from +// being added to the inner start and end of the tag's content - basically, +// ensuring that the start of the content begins immediately after the ">" +// ending the opening tag, and ends immediately before the "<" at the start of +// the closing tag. This has effect when a single child spans multiple lines, +// or when there are multiple children. +export const noEdgeWhitespace = Symbol(); + export function tag(tagName, ...args) { const selfClosing = selfClosingTags.includes(tagName); @@ -75,14 +83,20 @@ export function tag(tagName, ...args) { if (content) { if (content.includes('\n')) { - return ( - `<${openTag}>\n` + + return [ + `<${openTag}>`, content .split('\n') - .map((line) => ' ' + line + '\n') - .join('') + - `` - ); + .map((line, i) => + (i === 0 && attrs?.[noEdgeWhitespace] + ? line + : ' ' + line)) + .join('\n'), + ``, + ].join( + (attrs?.[noEdgeWhitespace] + ? '' + : '\n')); } else { return `<${openTag}>${content}`; } -- cgit 1.3.0-6-gf8a5