0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-09 15:52:43 +00:00

Fix ' ' removed from processStyleTags regex

Removes the case of "empty properties" that needed `.trim()`
This commit is contained in:
Trevor Buckner
2023-12-14 13:47:36 -05:00
parent ef00231c5b
commit 90b4e47861

View File

@@ -354,13 +354,12 @@ const voidTags = new Set([
]); ]);
const processStyleTags = (string)=>{ const processStyleTags = (string)=>{
//split tags up. quotes can only occur right after colons. //split tags up. quotes can only occur right after : or =.
//TODO: can we simplify to just split on commas? //TODO: can we simplify to just split on commas?
const tags = string.match(/(?:[^, ":=]+|[:=](?:"[^"]*"|))+/g); const tags = string.match(/(?:[^, ":=]+|[:=](?:"[^"]*"|))+/g);
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('=')));
console.log(classes);
let attributes = _.remove(tags, (tag)=>(!tag.includes(':')) && (!tag.includes('#'))); let attributes = _.remove(tags, (tag)=>(!tag.includes(':')) && (!tag.includes('#')));
const styles = tags?.length ? tags.map((tag)=>tag.replace(/:"?([^"]*)"?/g, ':$1;').trim()) : []; const styles = tags?.length ? tags.map((tag)=>tag.replace(/:"?([^"]*)"?/g, ':$1;').trim()) : [];
@@ -368,10 +367,10 @@ const processStyleTags = (string)=>{
attributes = attributes.map((attr)=>attr.replace(/="?([^"]*)"?/g, '="$1"')); attributes = attributes.map((attr)=>attr.replace(/="?([^"]*)"?/g, '="$1"'));
} }
return `${classes.join(' ').trim()}" ` + return `${classes?.length ? ` ${classes.join(' ')}` : ''}"` +
`${id ? ` id="${id}"` : ''}` + `${id ? ` id="${id}"` : ''}` +
`${styles?.length ? `style="${styles.join(' ').trim()}"` : ''}` + `${styles?.length ? ` style="${styles.join(' ')}"` : ''}` +
`${attributes?.length ? ` ${attributes.join(' ').trim()}` : ''}`; `${attributes?.length ? ` ${attributes.join(' ')}` : ''}`;
}; };
module.exports = { module.exports = {