From 58e849063c04768ccc222061255617aed7f15856 Mon Sep 17 00:00:00 2001 From: "royqh1979@gmail.com" Date: Sun, 10 Oct 2021 22:48:54 +0800 Subject: [PATCH] - fix: unneeded empty lines when copy as HTML --- RedPandaIDE/editor.cpp | 4 +++- RedPandaIDE/qsynedit/exporter/synhtmlexporter.cpp | 9 ++++++--- RedPandaIDE/qsynedit/exporter/synhtmlexporter.h | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 67d89cc9..bf831dd9 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -1123,7 +1123,7 @@ void Editor::copyAsHTML() { if (!selAvail()) return; - SynHTMLExporter SynExporterHTML; + SynHTMLExporter SynExporterHTML(tabWidth()); SynExporterHTML.setTitle(QFileInfo(mFilename).fileName()); SynExporterHTML.setExportAsText(false); @@ -1142,6 +1142,8 @@ void Editor::copyAsHTML() QMimeData * mimeData = new QMimeData; //sethtml will convert buffer to QString , which will cause encoding trouble + StringToFile(QString::fromLocal8Bit(SynExporterHTML.buffer()),"f:\\buffer.html"); + mimeData->setData(SynExporterHTML.clipboardFormat(),SynExporterHTML.buffer()); mimeData->setText(selText()); diff --git a/RedPandaIDE/qsynedit/exporter/synhtmlexporter.cpp b/RedPandaIDE/qsynedit/exporter/synhtmlexporter.cpp index e39bf1ea..6e0e38e8 100644 --- a/RedPandaIDE/qsynedit/exporter/synhtmlexporter.cpp +++ b/RedPandaIDE/qsynedit/exporter/synhtmlexporter.cpp @@ -2,7 +2,7 @@ #include "../MiscProcs.h" #include -SynHTMLExporter::SynHTMLExporter() +SynHTMLExporter::SynHTMLExporter(int tabSize) { mClipboardFormat = "text/html"; mDefaultFilter = "HTML Documents (*.htm;*.html)|*.htm;*.html"; @@ -11,6 +11,8 @@ SynHTMLExporter::SynHTMLExporter() mReplaceReserved['<'] = "<"; mReplaceReserved['>'] = ">"; mReplaceReserved['"'] = """; + mReplaceReserved[' '] = " "; + mReplaceReserved['\t'] = mReplaceReserved[' '].repeated(tabSize); mCreateHTMLFragment = false; } @@ -120,13 +122,14 @@ void SynHTMLExporter::FormatBeforeFirstAttribute(bool, bool, SynFontStyles) void SynHTMLExporter::FormatNewLine() { + AddData("
"); AddNewLine(); } QString SynHTMLExporter::GetFooter() { QString Result = ""; - Result = "" + lineBreak(); + Result = "" + lineBreak(); if (mCreateHTMLFragment) Result += ""; Result += ""+lineBreak()+ ""; @@ -172,7 +175,7 @@ QString SynHTMLExporter::GetHeader() if (mCreateHTMLFragment) { Result += ""; } - Result += QString("
")
+    Result += QString("")
             .arg(mFont.pointSize())
             .arg(mFont.family());
 
diff --git a/RedPandaIDE/qsynedit/exporter/synhtmlexporter.h b/RedPandaIDE/qsynedit/exporter/synhtmlexporter.h
index 637de40e..df0d6f2e 100644
--- a/RedPandaIDE/qsynedit/exporter/synhtmlexporter.h
+++ b/RedPandaIDE/qsynedit/exporter/synhtmlexporter.h
@@ -6,7 +6,7 @@
 class SynHTMLExporter : public SynExporter
 {
 public:
-    SynHTMLExporter();
+    SynHTMLExporter(int tabSize);
     bool createHTMLFragment() const;
     void setCreateHTMLFragment(bool createHTMLFragment);