0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-05 23:12:39 +00:00

Small tweaks to processStyle.

This changes the output on arbitrary outputs to always wrap the value in
quotes instead of only doing so on whitespaced values.
This commit is contained in:
David Bolack
2023-11-11 15:47:27 -06:00
parent fcdaef2445
commit c068aca9ff
2 changed files with 3 additions and 3 deletions

View File

@@ -331,13 +331,13 @@ const processStyleTags = (string)=>{
const id = _.remove(tags, (tag)=>tag.startsWith('#')).map((tag)=>tag.slice(1))[0]; const id = _.remove(tags, (tag)=>tag.startsWith('#')).map((tag)=>tag.slice(1))[0];
const classes = _.remove(tags, (tag)=>(!tag.includes(':')) && (!tag.includes('='))); const classes = _.remove(tags, (tag)=>(!tag.includes(':')) && (!tag.includes('=')));
const attributes = _.remove(tags, (tag)=>(!tag.includes(':')) && (!tag.includes('#'))); const attributes = _.remove(tags, (tag)=>(!tag.includes(':')) && (!tag.includes('#'))).map((attr)=>attr.replace(/="?([^"]*)"?/g, '="$1"'));;
const styles = tags.map((tag)=>tag.replace(/:"?([^"]*)"?/g, ':$1;').trim()); const styles = tags.map((tag)=>tag.replace(/:"?([^"]*)"?/g, ':$1;').trim());
return `${classes.join(' ')}" ` + return `${classes.join(' ')}" ` +
`${id ? `id="${id}"` : ''} ` + `${id ? `id="${id}"` : ''} ` +
`${styles.length ? `style="${styles.join(' ')}"` : ''}` + `${styles.length ? `style="${styles.join(' ')}"` : ''}` +
`${attributes.length ? attributes.join('') : ''}`; `${attributes.length ? ` ${attributes.join(' ')}` : ''}`;
}; };
module.exports = { module.exports = {

View File

@@ -126,7 +126,7 @@ describe('Inline: When using the Inline syntax {{ }}', ()=>{
}); });
it('Renders an image with added attributes', function() { it('Renders an image with added attributes', function() {
const source = dedent`![homebrew mug](https://i.imgur.com/hMna6G0.png) {position:absolute,bottom:20px,left:130px,width:220px,a=b and c,d=e}`; const source = dedent`![homebrew mug](https://i.imgur.com/hMna6G0.png) {position:absolute,bottom:20px,left:130px,width:220px,a="b and c",d=e}`;
const rendered = Markdown.render(source).trimReturns(); const rendered = Markdown.render(source).trimReturns();
expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe(`<p><img class=" " style="position:absolute; bottom:20px; left:130px; width:220px;" a="b and c" d="e" src="https://i.imgur.com/hMna6G0.png" alt="homebrew mug"></p>`); expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe(`<p><img class=" " style="position:absolute; bottom:20px; left:130px; width:220px;" a="b and c" d="e" src="https://i.imgur.com/hMna6G0.png" alt="homebrew mug"></p>`);
}); });