bugfix: escape special symbols (&) in TOC during generation

This commit is contained in:
Le Tan 2017-05-26 18:19:42 +08:00
parent 7d05f96f94
commit 4c63839c4d
4 changed files with 17 additions and 4 deletions

View File

@ -60,7 +60,7 @@ mdit = mdit.use(window.markdownitHeadingAnchor, {
toc.push({ toc.push({
level: getHeadingLevel(openToken.tag), level: getHeadingLevel(openToken.tag),
anchor: anchor, anchor: anchor,
title: inlineToken.content title: escapeHtml(inlineToken.content)
}); });
} }
}); });

View File

@ -313,3 +313,16 @@ var insertImageCaption = function() {
var finishLogics = function() { var finishLogics = function() {
content.finishLogics(); content.finishLogics();
}; };
// Escape @text to Html.
var escapeHtml = function(text) {
var map = {
'&': '&',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&#039;'
};
return text.replace(/[&<>"']/g, function(m) { return map[m]; });
};

View File

@ -24,7 +24,7 @@ var parseHeadings = function(html) {
toc.push({ toc.push({
level: level, level: level,
anchor: ele.id, anchor: ele.id,
title: ele.innerText title: ele.innerHTML
}); });
} }

View File

@ -43,8 +43,8 @@ VEditWindow::VEditWindow(VNote *vnote, VEditArea *editArea, QWidget *parent)
void VEditWindow::initTabActions() void VEditWindow::initTabActions()
{ {
m_locateAct = new QAction(QIcon(":/resources/icons/locate_note.svg"), m_locateAct = new QAction(QIcon(":/resources/icons/locate_note.svg"),
tr("Locate To Directory"), this); tr("Locate To Folder"), this);
m_locateAct->setToolTip(tr("Locate the directory of current note")); m_locateAct->setToolTip(tr("Locate the folder of current note"));
connect(m_locateAct, &QAction::triggered, connect(m_locateAct, &QAction::triggered,
this, &VEditWindow::handleLocateAct); this, &VEditWindow::handleLocateAct);