mirror of
https://github.com/marktext/marktext.git
synced 2025-05-10 00:09:24 +08:00
export styled HTML with heading id's (#460)
* export styled HTML with heading id's * Overwrite id attribute
This commit is contained in:
parent
d1be68372f
commit
45aa733ceb
@ -149,6 +149,9 @@ class ExportHTML {
|
||||
getHtml () {
|
||||
const rawHTML = document.querySelector(`#${CLASS_OR_ID['AG_EDITOR_ID']}`).outerHTML
|
||||
const $ = cheerio.load(rawHTML)
|
||||
const headingClassNames = [
|
||||
'h1', 'h2', 'h3', 'h4', 'h5', 'h6'
|
||||
]
|
||||
const removeClassNames = [
|
||||
`.${CLASS_OR_ID['AG_REMOVE']}`,
|
||||
`.${CLASS_OR_ID['AG_OUTPUT_REMOVE']}`,
|
||||
@ -162,6 +165,15 @@ class ExportHTML {
|
||||
$(`.${CLASS_OR_ID['AG_ACTIVE']}`).removeClass(CLASS_OR_ID['AG_ACTIVE'])
|
||||
$(`[data-role=hr]`).replaceWith('<hr>')
|
||||
|
||||
// create heading id's
|
||||
const headings = $(headingClassNames.join(', '))
|
||||
if (headings.length) {
|
||||
headings.each((i, h) => {
|
||||
const heading = $(h)
|
||||
heading.attr('id', heading.attr('data-id'))
|
||||
})
|
||||
}
|
||||
|
||||
// replace the `emoji text` with actual emoji
|
||||
const emojis = $(`span.${CLASS_OR_ID['AG_EMOJI_MARKED_TEXT']}`)
|
||||
if (emojis.length > 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user