Parse MFM options with values

This commit is contained in:
Sol Fisher Romanoff 2022-07-10 17:38:35 +03:00
parent f15465f0d3
commit 8c9821e444
No known key found for this signature in database
GPG key ID: 9D3F2B64F2341B62
2 changed files with 25 additions and 15 deletions

View file

@ -126,7 +126,26 @@ export default {
gfm: false,
breaks: true
})
return marked.parse(content)
const mfmHtml = document.createElement('template')
mfmHtml.innerHTML = marked.parse(content)
// Add options with set values to CSS
Array.from(mfmHtml.content.firstChild.getElementsByClassName('mfm')).map((el) => {
if (el.dataset.speed) {
el.style.animationDuration = el.dataset.speed
}
if (el.dataset.deg) {
el.style.transform = `rotate(${el.dataset.deg}deg)`
}
if (Array.from(el.classList).includes('_mfm_font_')) {
const font = Object.keys(el.dataset)[0]
if (['serif', 'monospace', 'cursive', 'fantasy', 'emoji', 'math'].includes(font)) {
el.style.fontFamily = font
}
}
})
return mfmHtml.innerHTML
}
// Processor to use with html_tree_converter