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;
|
||||
|
||||
#ifndef QT_NO_DEBUG
|
||||
// #define VX_DEBUG_WEB
|
||||
#define VX_DEBUG_WEB
|
||||
#endif
|
||||
|
||||
const QString ConfigMgr::c_orgName = "VNote";
|
||||
|
@ -21,10 +21,13 @@ class TurndownConverter {
|
||||
|
||||
// TODO: verify and copy several rules from VNote 2.0.
|
||||
this.fixMark();
|
||||
|
||||
this.fixParagraph();
|
||||
}
|
||||
|
||||
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.
|
||||
@ -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() {
|
||||
this.ts.addRule('img_fix', {
|
||||
filter: 'img',
|
||||
|
@ -61,6 +61,8 @@ void ImageInsertDialog::setupUI(const QString &p_title,
|
||||
auto gridLayout = new QGridLayout();
|
||||
mainLayout->addLayout(gridLayout);
|
||||
|
||||
mainLayout->addStretch();
|
||||
|
||||
// Image Path.
|
||||
m_imagePathEdit = WidgetsFactory::createLineEdit(p_imagePath, mainWidget);
|
||||
m_imagePathEdit->setReadOnly(!m_browserEnabled);
|
||||
@ -172,7 +174,13 @@ void ImageInsertDialog::checkImagePathInput()
|
||||
}
|
||||
|
||||
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;
|
||||
} else {
|
||||
setImage(QImage());
|
||||
|
@ -1049,7 +1049,7 @@ void MarkdownEditor::fetchImagesToLocalAndReplace(QString &p_text)
|
||||
}
|
||||
|
||||
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;
|
||||
QString urlToDisplay(imageUrl);
|
||||
@ -1091,6 +1091,10 @@ void MarkdownEditor::fetchImagesToLocalAndReplace(QString &p_text)
|
||||
}
|
||||
} else {
|
||||
// Network path.
|
||||
// Prepend the protocol if missing.
|
||||
if (imageUrl.startsWith(QStringLiteral("//"))) {
|
||||
imageUrl.prepend(QStringLiteral("https:"));
|
||||
}
|
||||
QByteArray data = vte::Downloader::download(QUrl(imageUrl));
|
||||
if (!data.isEmpty()) {
|
||||
auto suffix = info.suffix();
|
||||
|
Loading…
x
Reference in New Issue
Block a user