fix Hoedown's toc

Hoedown will treat '_' in title as '<em>'.

Signed-off-by: Le Tan <tamlokveer@gmail.com>
This commit is contained in:
Le Tan 2016-12-17 12:57:06 +08:00
parent a22bf1059d
commit 87c668bc67
2 changed files with 12 additions and 1 deletions

View File

@ -135,10 +135,20 @@ void VEditTab::previewByConverter()
QString html = mdConverter.generateHtml(content, vconfig.getMarkdownExtensions());
QRegularExpression tocExp("<p>\\[TOC\\]<\\/p>", QRegularExpression::CaseInsensitiveOption);
QString toc = mdConverter.generateToc(content, vconfig.getMarkdownExtensions());
processHoedownToc(toc);
html.replace(tocExp, toc);
document.setHtml(html);
// Hoedown will add '\n' while Marked does not
updateTocFromHtml(toc.replace("\n", ""));
updateTocFromHtml(toc);
}
void VEditTab::processHoedownToc(QString &p_toc)
{
// Hoedown will add '\n'.
p_toc.replace("\n", "");
// Hoedown will translate `_` in title to `<em>`.
p_toc.replace("<em>", "_");
p_toc.replace("</em>", "_");
}
void VEditTab::showFileEditMode()

View File

@ -60,6 +60,7 @@ private:
void showFileEditMode();
void setupMarkdownPreview();
void previewByConverter();
void processHoedownToc(QString &p_toc);
inline bool isChild(QObject *obj);
void parseTocUl(QXmlStreamReader &xml, QVector<VHeader> &headers, int level);
void parseTocLi(QXmlStreamReader &xml, QVector<VHeader> &headers, int level);