0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-04 21:12:41 +00:00

Add tests for arbitrary attributes.

Also shifted around the adding of spaces for the attributes.
This commit is contained in:
David Bolack
2023-11-07 19:07:58 -06:00
parent c58c8777f1
commit 837306c9a7
2 changed files with 10 additions and 3 deletions

View File

@@ -338,13 +338,13 @@ const processStyleTags = (string)=>{
const styles = tags.map((tag)=>tag.replace(/:"?([^"]*)"?/g, ':$1;').trim()); const styles = tags.map((tag)=>tag.replace(/:"?([^"]*)"?/g, ':$1;').trim());
if(attributes.length) { if(attributes.length) {
attributes = attributes.map((attribute)=>attribute.replace(/(\w+)=(.+)/, '$1="$2"')); attributes = attributes.map((attribute)=>attribute.replace(/(\w+)=(.+)/, ' $1="$2"'));
} }
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

@@ -124,6 +124,12 @@ describe('Inline: When using the Inline syntax {{ }}', ()=>{
const rendered = Markdown.render(source); const rendered = Markdown.render(source);
expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('<span class="inline-block pen" id="author" style="color:orange; font-family:trebuchet ms;">text</span>'); expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('<span class="inline-block pen" id="author" style="color:orange; font-family:trebuchet ms;">text</span>');
}); });
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 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>`);
});
}); });
// BLOCK SYNTAX // BLOCK SYNTAX
@@ -216,6 +222,7 @@ describe(`Block: When using the Block syntax {{tags\\ntext\\n}}`, ()=>{
// FIXME: adds extra \s before closing `>` in opening tag, and another after class names // FIXME: adds extra \s before closing `>` in opening tag, and another after class names
expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe(`<div class="block" id="cat"><p>Sample text.</p></div>`); expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe(`<div class="block" id="cat"><p>Sample text.</p></div>`);
}); });
}); });
// MUSTACHE INJECTION SYNTAX // MUSTACHE INJECTION SYNTAX