mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-10 09:12:39 +00:00
Simplify Attributes parsing logic
This commit is contained in:
@@ -360,13 +360,9 @@ 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('=')));
|
||||||
let attributes = _.remove(tags, (tag)=>(!tag.includes(':')) && (!tag.includes('#')));
|
const attributes = _.remove(tags, (tag)=>(tag.includes('='))).map((tag)=>tag.replace(/="?([^"]*)"?/g, '="$1"'));
|
||||||
const styles = tags?.length ? tags.map((tag)=>tag.replace(/:"?([^"]*)"?/g, ':$1;').trim()) : [];
|
const styles = tags?.length ? tags.map((tag)=>tag.replace(/:"?([^"]*)"?/g, ':$1;').trim()) : [];
|
||||||
|
|
||||||
if(attributes) {
|
|
||||||
attributes = attributes.map((attr)=>attr.replace(/="?([^"]*)"?/g, '="$1"'));
|
|
||||||
}
|
|
||||||
|
|
||||||
return `${classes?.length ? ` ${classes.join(' ')}` : ''}"` +
|
return `${classes?.length ? ` ${classes.join(' ')}` : ''}"` +
|
||||||
`${id ? ` id="${id}"` : ''}` +
|
`${id ? ` id="${id}"` : ''}` +
|
||||||
`${styles?.length ? ` style="${styles.join(' ')}"` : ''}` +
|
`${styles?.length ? ` style="${styles.join(' ')}"` : ''}` +
|
||||||
|
|||||||
Reference in New Issue
Block a user