mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
Turndown: remove title and alt text if they contains invalid characters
It is useful especially for OneNoe.
This commit is contained in:
parent
1b95b636e7
commit
ec15475c87
@ -1638,6 +1638,26 @@ var htmlToText = function(identifier, id, timeStamp, html) {
|
||||
}
|
||||
});
|
||||
|
||||
ts.addRule('img_fix', {
|
||||
filter: 'img',
|
||||
replacement: function (content, node) {
|
||||
var alt = node.alt || '';
|
||||
if (/[\r\n\[\]]/g.test(alt)) {
|
||||
alt= '';
|
||||
}
|
||||
|
||||
var src = node.getAttribute('src') || '';
|
||||
|
||||
var title = node.title || '';
|
||||
if (/[\r\n\)"]/g.test(title)) {
|
||||
title = '';
|
||||
}
|
||||
|
||||
var titlePart = title ? ' "' + title + '"' : '';
|
||||
return src ? '![' + alt + ']' + '(' + src + titlePart + ')' : ''
|
||||
}
|
||||
});
|
||||
|
||||
var markdown = ts.turndown(html);
|
||||
content.htmlToTextCB(identifier, id, timeStamp, markdown);
|
||||
};
|
||||
|
@ -46,7 +46,7 @@ QVector<QPair<QString, QString>> VUtils::s_availableLanguages;
|
||||
const QString VUtils::c_imageLinkRegExp = QString("\\!\\[([^\\[\\]]*)\\]"
|
||||
"\\(\\s*"
|
||||
"([^\\)\"'\\s]+)"
|
||||
"(\\s*(\"[^\"\\)\\n]*\")|('[^'\\)\\n]*'))?"
|
||||
"(\\s*(\"[^\"\\)\\n\\r]*\")|('[^'\\)\\n\\r]*'))?"
|
||||
"(\\s*=(\\d*)x(\\d*))?"
|
||||
"\\s*\\)");
|
||||
|
||||
@ -54,8 +54,8 @@ const QString VUtils::c_imageTitleRegExp = QString("[^\\[\\]]*");
|
||||
|
||||
const QString VUtils::c_linkRegExp = QString("\\[([^\\]]*)\\]"
|
||||
"\\(\\s*(\\S+)"
|
||||
"(?:\\s+((\"[^\"\\n]*\")"
|
||||
"|('[^'\\n]*')))?\\s*"
|
||||
"(?:\\s+((\"[^\"\\n\\r]*\")"
|
||||
"|('[^'\\n\\r]*')))?\\s*"
|
||||
"\\)");
|
||||
|
||||
const QString VUtils::c_fileNameRegExp = QString("(?:[^\\\\/:\\*\\?\"<>\\|\\s]| )*");
|
||||
@ -158,6 +158,8 @@ QString VUtils::generateImageFileName(const QString &path,
|
||||
const QString &title,
|
||||
const QString &format)
|
||||
{
|
||||
Q_UNUSED(title);
|
||||
|
||||
const QChar sep('_');
|
||||
|
||||
QString baseName(g_config->getImageNamePrefix());
|
||||
|
Loading…
x
Reference in New Issue
Block a user