diff --git a/src/utils/vutils.cpp b/src/utils/vutils.cpp index 9faaf9a1..be701227 100644 --- a/src/utils/vutils.cpp +++ b/src/utils/vutils.cpp @@ -1580,3 +1580,9 @@ QString VUtils::promptForFileName(const QString &p_title, return name; } + +bool VUtils::onlyHasImgInHtml(const QString &p_html) +{ + // Tricky. + return !p_html.contains("

content. + static bool onlyHasImgInHtml(const QString &p_html); + // Regular expression for image link. // ![image title]( http://github.com/tamlok/vnote.jpg "alt text" =200x100) // Captured texts (need to be trimmed): diff --git a/src/vmdeditor.cpp b/src/vmdeditor.cpp index dde892e3..853d3eb8 100644 --- a/src/vmdeditor.cpp +++ b/src/vmdeditor.cpp @@ -766,7 +766,8 @@ void VMdEditor::insertFromMimeData(const QMimeData *p_source) if (p_source->hasHtml()) { // Handle . QRegExp reg("]*)src=\"([^\"]+)\"([^>]*)>"); - if (reg.indexIn(p_source->html()) != -1) { + QString html(p_source->html()); + if (reg.indexIn(html) != -1 && VUtils::onlyHasImgInHtml(html)) { if (p_source->hasImage()) { // Both image data and URL are embedded. VSelectDialog dialog(tr("Insert From Clipboard"), this); @@ -858,9 +859,15 @@ void VMdEditor::insertFromMimeData(const QMimeData *p_source) int selection = dialog.getSelection(); if (selection == 0) { // Insert as image. - QUrl url(text); + QUrl url; + if (QFileInfo::exists(text)) { + url = QUrl::fromLocalFile(text); + } else { + url = QUrl(text); + } + if (url.isValid()) { - m_editOps->insertImageFromURL(QUrl(text)); + m_editOps->insertImageFromURL(url); } return;