From 45aa733ceb49079a1f5ff07f54cddab9fc24c75a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20H=C3=A4usler?= Date: Thu, 16 Aug 2018 15:51:40 +0200 Subject: [PATCH] export styled HTML with heading id's (#460) * export styled HTML with heading id's * Overwrite id attribute --- src/muya/lib/utils/exportStyledHTML.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/muya/lib/utils/exportStyledHTML.js b/src/muya/lib/utils/exportStyledHTML.js index 95eb301c..6f322041 100644 --- a/src/muya/lib/utils/exportStyledHTML.js +++ b/src/muya/lib/utils/exportStyledHTML.js @@ -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('
') + // 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) {