From 87c668bc67dd3f3c5914efc5b2a9414655f672f9 Mon Sep 17 00:00:00 2001 From: Le Tan Date: Sat, 17 Dec 2016 12:57:06 +0800 Subject: [PATCH] fix Hoedown's toc Hoedown will treat '_' in title as ''. Signed-off-by: Le Tan --- src/vedittab.cpp | 12 +++++++++++- src/vedittab.h | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/vedittab.cpp b/src/vedittab.cpp index e722950a..79f80f43 100644 --- a/src/vedittab.cpp +++ b/src/vedittab.cpp @@ -135,10 +135,20 @@ void VEditTab::previewByConverter() QString html = mdConverter.generateHtml(content, vconfig.getMarkdownExtensions()); QRegularExpression tocExp("

\\[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 ``. + p_toc.replace("", "_"); + p_toc.replace("", "_"); } void VEditTab::showFileEditMode() diff --git a/src/vedittab.h b/src/vedittab.h index 91d40858..c7eb6e63 100644 --- a/src/vedittab.h +++ b/src/vedittab.h @@ -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 &headers, int level); void parseTocLi(QXmlStreamReader &xml, QVector &headers, int level);