mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2025-12-24 18:32:41 +00:00
Add tests for arbitrary attributes.
Also shifted around the adding of spaces for the attributes.
This commit is contained in:
@@ -338,13 +338,13 @@ const processStyleTags = (string)=>{
|
||||
const styles = tags.map((tag)=>tag.replace(/:"?([^"]*)"?/g, ':$1;').trim());
|
||||
|
||||
if(attributes.length) {
|
||||
attributes = attributes.map((attribute)=>attribute.replace(/(\w+)=(.+)/, '$1="$2"'));
|
||||
attributes = attributes.map((attribute)=>attribute.replace(/(\w+)=(.+)/, ' $1="$2"'));
|
||||
}
|
||||
|
||||
return `${classes.join(' ')}" ` +
|
||||
`${id ? `id="${id}"` : ''} ` +
|
||||
`${styles.length ? `style="${styles.join(' ')}"` : ''} ` +
|
||||
`${attributes.length ? attributes.join(' ') : ''}`;
|
||||
`${styles.length ? `style="${styles.join(' ')}"` : ''}` +
|
||||
`${attributes.length ? attributes.join('') : ''}`;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
|
||||
@@ -124,6 +124,12 @@ describe('Inline: When using the Inline syntax {{ }}', ()=>{
|
||||
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>');
|
||||
});
|
||||
|
||||
it('Renders an image with added attributes', function() {
|
||||
const source = dedent` {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
|
||||
@@ -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
|
||||
expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe(`<div class="block" id="cat"><p>Sample text.</p></div>`);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
// MUSTACHE INJECTION SYNTAX
|
||||
|
||||
Reference in New Issue
Block a user