- fix: unneeded empty lines when copy as HTML

This commit is contained in:
royqh1979@gmail.com 2021-10-10 22:48:54 +08:00
parent 3a81281f7d
commit 58e849063c
3 changed files with 10 additions and 5 deletions

View File

@ -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());

View File

@ -2,7 +2,7 @@
#include "../MiscProcs.h"
#include <functional>
SynHTMLExporter::SynHTMLExporter()
SynHTMLExporter::SynHTMLExporter(int tabSize)
{
mClipboardFormat = "text/html";
mDefaultFilter = "HTML Documents (*.htm;*.html)|*.htm;*.html";
@ -11,6 +11,8 @@ SynHTMLExporter::SynHTMLExporter()
mReplaceReserved['<'] = "&lt;";
mReplaceReserved['>'] = "&gt;";
mReplaceReserved['"'] = "&quot;";
mReplaceReserved[' '] = "&nbsp;";
mReplaceReserved['\t'] = mReplaceReserved[' '].repeated(tabSize);
mCreateHTMLFragment = false;
}
@ -120,13 +122,14 @@ void SynHTMLExporter::FormatBeforeFirstAttribute(bool, bool, SynFontStyles)
void SynHTMLExporter::FormatNewLine()
{
AddData("<br />");
AddNewLine();
}
QString SynHTMLExporter::GetFooter()
{
QString Result = "";
Result = "</span></code></pre>" + lineBreak();
Result = "</span>" + lineBreak();
if (mCreateHTMLFragment)
Result += "<!--EndFragment-->";
Result += "</body>"+lineBreak()+ "</html>";
@ -172,7 +175,7 @@ QString SynHTMLExporter::GetHeader()
if (mCreateHTMLFragment) {
Result += "<!--StartFragment-->";
}
Result += QString("<pre><code><span style=\"font: %1pt %2;\">")
Result += QString("<span style=\"font: %1pt %2;\">")
.arg(mFont.pointSize())
.arg(mFont.family());

View File

@ -6,7 +6,7 @@
class SynHTMLExporter : public SynExporter
{
public:
SynHTMLExporter();
SynHTMLExporter(int tabSize);
bool createHTMLFragment() const;
void setCreateHTMLFragment(bool createHTMLFragment);