From 632a0078089d7d98d2bd0824524542ebf66ff3a5 Mon Sep 17 00:00:00 2001 From: Le Tan Date: Wed, 10 Jan 2018 20:16:40 +0800 Subject: [PATCH] support copy as Web Editor --- src/resources/vnote.ini | 6 ++- src/utils/vwebutils.cpp | 88 ++++++++++++++++++++++++++++++++++++++++- src/utils/vwebutils.h | 6 +++ src/vwebview.cpp | 4 +- 4 files changed, 98 insertions(+), 6 deletions(-) diff --git a/src/resources/vnote.ini b/src/resources/vnote.ini index b600bd8d..11fdcda1 100644 --- a/src/resources/vnote.ini +++ b/src/resources/vnote.ini @@ -203,7 +203,7 @@ style_of_span_for_mark="background-color: #FFFF00;" ; CSS properties to embed as inline styles when copied in edit mode ; tag1:tag2:tag3$property1:property2:property3,tag4:tag5$property2:property3 ; "all" for all tags not specified explicitly -styles_to_inline_when_copied=all$border:color:display:font-family:font-size:font-style:white-space:word-spacing:line-height:text-align:text-indent:padding-top:padding-bottom:margin-top:margin-bottom:background-color,code$font-family:font-size:line-height:color:display:overfow-x:background-color,li$line-height:background-color,a$color:vertical-align:background-color,pre$display:overflow-y:overflow-x:color:font-size:font-style:font-weight:letter-spacing:text-align:text-indent:word-spacing:background-color +styles_to_inline_when_copied=all$border:color:display:font-family:font-size:font-style:white-space:word-spacing:line-height:text-align:text-indent:padding-top:padding-bottom:margin-top:margin-bottom:background-color:font-weight,code$font-family:font-size:line-height:color:display:overfow-x:background-color:font-weight,li$line-height:background-color:font-weight,a$color:vertical-align:background-color:font-weight,pre$display:overflow-y:overflow-x:color:font-size:font-style:font-weight:letter-spacing:text-align:text-indent:word-spacing:background-color ; Define targets the copied content will be pasted into ; target_name$action1:action2:action3,targeet_name2$action2:action3 @@ -217,7 +217,9 @@ styles_to_inline_when_copied=all$border:color:display:font-family:font-size:font ; a - transform to ; x(tag1|tag2) - remove styles specified in [styles_to_inline_when_copied] of all tags except tag1 and tag2 ; p - replace the background color of
 with that of its child 
-copy_targets=WithoutBackground$s:b(mark):c:i:x,OneNote$s:b(mark):c:i:m:a:x,MicroSoftWord$s:p:b(mark|pre):c(pre):i:m:a:x,RawHTML$r
+; n - replace the \n in 
 with 
+; g - replace local relative/absolute tag with a warning label +copy_targets="Without Background"$s:b(mark):c:i:x,OneNote$s:b(mark):c:i:m:a:x,"Microsoft Word"$s:p:b(mark|pre):c(pre):i:m:a:x,"WeChat Public Account"$s:p:b(mark|pre):c(pre):g:m:x:n,"Web Editor"$s:p:b(mark|pre):c(pre):m:x:n,"Raw HTML"$r:x [shortcuts] ; Define shortcuts here, with each item in the form "operation=keysequence". diff --git a/src/utils/vwebutils.cpp b/src/utils/vwebutils.cpp index 2cdeb335..2fdd60bc 100644 --- a/src/utils/vwebutils.cpp +++ b/src/utils/vwebutils.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include "vpalette.h" @@ -87,7 +88,7 @@ bool VWebUtils::fixImageSrc(const QUrl &p_baseUrl, QString &p_html) QUrl::ComponentFormattingOption strOpt = QUrl::FullyEncoded; #endif - QRegExp reg("(= preEnd) { + break; + } + + QString br("
"); + p_html.replace(idx, 1, br); + pos = idx + br.size() - 1; + preEnd = preEnd + br.size() - 1; + + altered = true; + } + + pos = preEnd; + } + + return altered; +} + +bool VWebUtils::replaceLocalImgWithWarningLabel(QString &p_html) +{ + bool altered = false; + + QRegExp reg("]*>"); + + QString label = QString("%1") + .arg(QObject::tr("Insert_Image_HERE")); + + int pos = 0; + while (pos < p_html.size()) { + int idx = p_html.indexOf(reg, pos); + if (idx == -1) { + break; + } + + QString urlStr = reg.cap(1); + QUrl imgUrl(urlStr); + + if (imgUrl.scheme() == "https" || imgUrl.scheme() == "http") { + pos = idx + reg.matchedLength(); + continue; + } + + p_html.replace(idx, reg.matchedLength(), label); + pos = idx + label.size(); + } + + return altered; +} diff --git a/src/utils/vwebutils.h b/src/utils/vwebutils.h index e66c89a1..c811c553 100644 --- a/src/utils/vwebutils.h +++ b/src/utils/vwebutils.h @@ -91,6 +91,12 @@ private: VWebUtils::HtmlTag readNextTag(const QString &p_html, int p_pos); + // Replace \n with
in
.
+    bool replaceNewLineWithBR(QString &p_html);
+
+    // Replace local absolute/relative  tag with a warning label.
+    bool replaceLocalImgWithWarningLabel(QString &p_html);
+
     QVector m_copyTargets;
 
     // Custom styles to remove when copied.
diff --git a/src/vwebview.cpp b/src/vwebview.cpp
index 3be1df13..f9d506e7 100644
--- a/src/vwebview.cpp
+++ b/src/vwebview.cpp
@@ -111,8 +111,6 @@ void VWebView::handleEditAction()
 
 void VWebView::copyImage()
 {
-    m_afterCopyImage = true;
-
 #if defined(Q_OS_WIN)
     Q_ASSERT(m_copyImageUrlActionHooked);
     // triggerPageAction(QWebEnginePage::CopyImageUrlToClipboard) will not really
@@ -145,6 +143,8 @@ void VWebView::copyImage()
     }
 #endif
 
+    m_afterCopyImage = true;
+
     // Fall back.
     triggerPageAction(QWebEnginePage::CopyImageToClipboard);
 }