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';
var content;
// Type = 0, Hoedown, getElementById;
// Type = 1, Marked, getElementsByTagName;
var scrollToAnchor = function(anchor, type) {
switch (type) {
case 0:
var scrollToAnchor = function(anchor) {
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,

View File

@ -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:
var scrollToAnchor = function(anchor) {
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,

View File

@ -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);
}

View File

@ -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;

View File

@ -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));
}
}
}