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 committed 2023-11-11 15:47:27 -06:00
1 parent fcdaef2445
commit c068aca9ff
2 files changed
+3 -3

No files matched your search

+2 -2
View File
@@ -331,13 +331,13 @@ const processStyleTags = (string)=>{
const id = _.remove(tags, (tag)=>tag.startsWith('#')).map((tag)=>tag.slice(1))[0];
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());
return `${classes.join(' ')}" ` +
`${id ? `id="${id}"` : ''} ` +
`${styles.length ? `style="${styles.join(' ')}"` : ''}` +
`${attributes.length ? attributes.join('') : ''}`;
`${attributes.length ? ` ${attributes.join(' ')}` : ''}`;
};
module.exports = {
+1 -1
View File
@@ -126,7 +126,7 @@ describe('Inline: When using the Inline syntax {{ }}', ()=>{
});
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();
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>`);
});