mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
bug fix
1. InsertImageDialog crashes when file does not exist; 2. Use for leading spaces of <p> element in Turndown;
This commit is contained in:
parent
36dd070d05
commit
30e3b5721e
@ -24,7 +24,7 @@
|
|||||||
using namespace vnotex;
|
using namespace vnotex;
|
||||||
|
|
||||||
#ifndef QT_NO_DEBUG
|
#ifndef QT_NO_DEBUG
|
||||||
// #define VX_DEBUG_WEB
|
#define VX_DEBUG_WEB
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const QString ConfigMgr::c_orgName = "VNote";
|
const QString ConfigMgr::c_orgName = "VNote";
|
||||||
|
@ -21,10 +21,13 @@ class TurndownConverter {
|
|||||||
|
|
||||||
// TODO: verify and copy several rules from VNote 2.0.
|
// TODO: verify and copy several rules from VNote 2.0.
|
||||||
this.fixMark();
|
this.fixMark();
|
||||||
|
|
||||||
|
this.fixParagraph();
|
||||||
}
|
}
|
||||||
|
|
||||||
turndown(p_html) {
|
turndown(p_html) {
|
||||||
return this.ts.turndown(p_html);
|
let markdown = this.ts.turndown(p_html);
|
||||||
|
return markdown;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Trim a string into 3 parts: leading spaces, content, trailing spaces.
|
// Trim a string into 3 parts: leading spaces, content, trailing spaces.
|
||||||
@ -69,6 +72,25 @@ class TurndownConverter {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fixParagraph() {
|
||||||
|
this.ts.addRule('paragraph', {
|
||||||
|
filter: 'p',
|
||||||
|
replacement: function(content) {
|
||||||
|
// Replace leading spaces with to avoid being parsed as code block.
|
||||||
|
let lRe = /^\s+/;
|
||||||
|
let ret = lRe.exec(content);
|
||||||
|
if (ret) {
|
||||||
|
let leadingSpaces = ret[0];
|
||||||
|
if (leadingSpaces.length > 3) {
|
||||||
|
content = ' '.repeat(leadingSpaces.length) + content.slice(leadingSpaces.length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return '\n\n' + content + '\n\n'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
fixImage() {
|
fixImage() {
|
||||||
this.ts.addRule('img_fix', {
|
this.ts.addRule('img_fix', {
|
||||||
filter: 'img',
|
filter: 'img',
|
||||||
|
@ -61,6 +61,8 @@ void ImageInsertDialog::setupUI(const QString &p_title,
|
|||||||
auto gridLayout = new QGridLayout();
|
auto gridLayout = new QGridLayout();
|
||||||
mainLayout->addLayout(gridLayout);
|
mainLayout->addLayout(gridLayout);
|
||||||
|
|
||||||
|
mainLayout->addStretch();
|
||||||
|
|
||||||
// Image Path.
|
// Image Path.
|
||||||
m_imagePathEdit = WidgetsFactory::createLineEdit(p_imagePath, mainWidget);
|
m_imagePathEdit = WidgetsFactory::createLineEdit(p_imagePath, mainWidget);
|
||||||
m_imagePathEdit->setReadOnly(!m_browserEnabled);
|
m_imagePathEdit->setReadOnly(!m_browserEnabled);
|
||||||
@ -172,7 +174,13 @@ void ImageInsertDialog::checkImagePathInput()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (url.isLocalFile()) {
|
if (url.isLocalFile()) {
|
||||||
setImage(FileUtils::imageFromFile(url.toLocalFile()));
|
const auto localFile = url.toLocalFile();
|
||||||
|
if (QFileInfo::exists(localFile)) {
|
||||||
|
setImage(FileUtils::imageFromFile(localFile));
|
||||||
|
} else {
|
||||||
|
setImage(QImage());
|
||||||
|
}
|
||||||
|
|
||||||
m_source = Source::LocalFile;
|
m_source = Source::LocalFile;
|
||||||
} else {
|
} else {
|
||||||
setImage(QImage());
|
setImage(QImage());
|
||||||
|
@ -1049,7 +1049,7 @@ void MarkdownEditor::fetchImagesToLocalAndReplace(QString &p_text)
|
|||||||
}
|
}
|
||||||
|
|
||||||
const QString imageTitle = purifyImageTitle(regExp.cap(1).trimmed());
|
const QString imageTitle = purifyImageTitle(regExp.cap(1).trimmed());
|
||||||
const QString imageUrl = regExp.cap(2).trimmed();
|
QString imageUrl = regExp.cap(2).trimmed();
|
||||||
|
|
||||||
const int maxUrlLength = 100;
|
const int maxUrlLength = 100;
|
||||||
QString urlToDisplay(imageUrl);
|
QString urlToDisplay(imageUrl);
|
||||||
@ -1091,6 +1091,10 @@ void MarkdownEditor::fetchImagesToLocalAndReplace(QString &p_text)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Network path.
|
// Network path.
|
||||||
|
// Prepend the protocol if missing.
|
||||||
|
if (imageUrl.startsWith(QStringLiteral("//"))) {
|
||||||
|
imageUrl.prepend(QStringLiteral("https:"));
|
||||||
|
}
|
||||||
QByteArray data = vte::Downloader::download(QUrl(imageUrl));
|
QByteArray data = vte::Downloader::download(QUrl(imageUrl));
|
||||||
if (!data.isEmpty()) {
|
if (!data.isEmpty()) {
|
||||||
auto suffix = info.suffix();
|
auto suffix = info.suffix();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user