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 <tamlokveer@gmail.com>
This commit is contained in:
Le Tan 2016-11-08 22:08:18 +08:00
parent d1a3a9c386
commit fe3d16ba3b
5 changed files with 11 additions and 44 deletions

View File

@ -16,23 +16,8 @@
'use strict'; 'use strict';
var content; var content;
// Type = 0, Hoedown, getElementById; var scrollToAnchor = function(anchor) {
// Type = 1, Marked, getElementsByTagName; document.getElementById(anchor).scrollIntoView();
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;
}
}; };
new QWebChannel(qt.webChannelTransport, new QWebChannel(qt.webChannelTransport,

View File

@ -30,11 +30,8 @@
anchor: escapedText, anchor: escapedText,
title: text title: text
}); });
return '<h' + level + '><a name="' + return '<h' + level + ' id="' +
escapedText + escapedText + '">' +
'" class="anchor" href="#' +
escapedText +
'"><span class="header-link"></span></a>' +
text + '</h' + level + '>'; text + '</h' + level + '>';
}; };
@ -148,23 +145,8 @@
handleToc(needToc); handleToc(needToc);
}; };
// Type = 0, Hoedown, getElementById; var scrollToAnchor = function(anchor) {
// Type = 1, Marked, getElementsByTagName; document.getElementById(anchor).scrollIntoView();
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;
}
}; };
new QWebChannel(qt.webChannelTransport, new QWebChannel(qt.webChannelTransport,

View File

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

View File

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

View File

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