浏览代码

change Marked's renderer to be identical with Hoedown

Change the style of the header to align with what Hoedown does (use id
as anchor).

Signed-off-by: Le Tan <[email protected]>
Le Tan 9 年之前
父节点
当前提交
fe3d16ba3b
共有 5 个文件被更改,包括 11 次插入44 次删除
  1. 2 17
      src/resources/pre_template.html
  2. 4 22
      src/resources/template.html
  3. 2 2
      src/vdocument.cpp
  4. 2 2
      src/vdocument.h
  5. 1 1
      src/vedittab.cpp

+ 2 - 17
src/resources/pre_template.html

@@ -16,23 +16,8 @@
   'use strict';
   var content;
 
-  // Type = 0, Hoedown, getElementById;
-  // Type = 1, Marked, getElementsByTagName;
-  var scrollToAnchor = function(anchor, type) {
-      switch (type) {
-      case 0:
-          document.getElementById(anchor).scrollIntoView();
-          break;
-      case 1:
-          var eles = document.getElementsByTagName('a');
-          for (var i = 0; i < eles.length; ++i) {
-             if (eles[i].name == anchor) {
-                eles[i].scrollIntoView();
-                break;
-             }
-          }
-          break;
-      }
+  var scrollToAnchor = function(anchor) {
+      document.getElementById(anchor).scrollIntoView();
   };
 
   new QWebChannel(qt.webChannelTransport,

+ 4 - 22
src/resources/template.html

@@ -30,11 +30,8 @@
         anchor: escapedText,
         title: text
       });
-	  return '<h' + level + '><a name="' +
-			 escapedText +
-			 '" class="anchor" href="#' +
-			 escapedText +
-			 '"><span class="header-link"></span></a>' +
+	  return '<h' + level + ' id="' +
+             escapedText + '">' +
 			 text + '</h' + level + '>';
   };
 
@@ -148,23 +145,8 @@
       handleToc(needToc);
   };
 
-  // Type = 0, Hoedown, getElementById;
-  // Type = 1, Marked, getElementsByTagName;
-  var scrollToAnchor = function(anchor, type) {
-      switch (type) {
-      case 0:
-          document.getElementById(anchor).scrollIntoView();
-          break;
-      case 1:
-          var eles = document.getElementsByTagName('a');
-          for (var i = 0; i < eles.length; ++i) {
-             if (eles[i].name == anchor) {
-                eles[i].scrollIntoView();
-                break;
-             }
-          }
-          break;
-      }
+  var scrollToAnchor = function(anchor) {
+      document.getElementById(anchor).scrollIntoView();
   };
 
   new QWebChannel(qt.webChannelTransport,

+ 2 - 2
src/vdocument.cpp

@@ -39,7 +39,7 @@ QString VDocument::getToc()
     return m_toc;
 }
 
-void VDocument::scrollToAnchor(const QString &anchor, int type)
+void VDocument::scrollToAnchor(const QString &anchor)
 {
-    emit requestScrollToAnchor(anchor, type);
+    emit requestScrollToAnchor(anchor);
 }

+ 2 - 2
src/vdocument.h

@@ -16,7 +16,7 @@ public:
     void setText(const QString &text);
     QString getText();
     QString getToc();
-    void scrollToAnchor(const QString &anchor, int type);
+    void scrollToAnchor(const QString &anchor);
 
 public slots:
     // Will be called in the HTML side
@@ -25,7 +25,7 @@ public slots:
 signals:
     void textChanged(const QString &text);
     void tocChanged(const QString &toc);
-    void requestScrollToAnchor(const QString &anchor, int type);
+    void requestScrollToAnchor(const QString &anchor);
 
 private:
     QString m_text;

+ 1 - 1
src/vedittab.cpp

@@ -345,7 +345,7 @@ void VEditTab::scrollToAnchor(const VAnchor &anchor)
         }
     } else {
         if (!anchor.anchor.isEmpty()) {
-            document.scrollToAnchor(anchor.anchor.mid(1), mdConverterType);
+            document.scrollToAnchor(anchor.anchor.mid(1));
         }
     }
 }