Pārlūkot izejas kodu

fix Hoedown's toc

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

Signed-off-by: Le Tan <[email protected]>
Le Tan 9 gadi atpakaļ
vecāks
revīzija
87c668bc67
2 mainītis faili ar 12 papildinājumiem un 1 dzēšanām
  1. 11 1
      src/vedittab.cpp
  2. 1 0
      src/vedittab.h

+ 11 - 1
src/vedittab.cpp

@@ -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()

+ 1 - 0
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<VHeader> &headers, int level);
     void parseTocLi(QXmlStreamReader &xml, QVector<VHeader> &headers, int level);