mirror of
https://github.com/olivierkes/manuskript.git
synced 2024-05-15 18:32:27 +12:00
Better exporter, cleaner html
This commit is contained in:
parent
6744d2350a
commit
c195892992
|
@ -5,6 +5,7 @@ from qt import *
|
|||
from enums import *
|
||||
from functions import *
|
||||
import subprocess
|
||||
import re
|
||||
|
||||
class basicExporter():
|
||||
|
||||
|
@ -24,3 +25,8 @@ class basicExporter():
|
|||
cmd.wait()
|
||||
|
||||
return output.decode("utf-8")
|
||||
|
||||
def htmlBody(self, text):
|
||||
text = text.replace("\n", "")
|
||||
text = re.sub(r".*<body[^>]*?>(.*)</body>.*", "\\1", text)
|
||||
return text
|
||||
|
|
|
@ -5,7 +5,6 @@ from qt import *
|
|||
from enums import *
|
||||
from functions import *
|
||||
from exporter.basic import basicExporter
|
||||
import subprocess
|
||||
|
||||
class htmlExporter(basicExporter):
|
||||
|
||||
|
@ -68,19 +67,9 @@ class htmlExporter(basicExporter):
|
|||
|
||||
elif _type == "txt":
|
||||
text = text.replace("\n", "<br>")
|
||||
|
||||
elif _type == "html":
|
||||
# keep only body
|
||||
text = self.htmlBody(text)
|
||||
|
||||
return text + "<br>"
|
||||
|
||||
def runT2T(self, text, target="html"):
|
||||
|
||||
cmdl = ['txt2tags', '-t', target, '--enc=utf-8', '--no-headers', '-o', '-', '-']
|
||||
|
||||
cmd = subprocess.Popen(('echo', text), stdout=subprocess.PIPE)
|
||||
try:
|
||||
output = subprocess.check_output(cmdl, stdin=cmd.stdout, stderr=subprocess.STDOUT) # , cwd="/tmp"
|
||||
except subprocess.CalledProcessError as e:
|
||||
print("Error!")
|
||||
return text
|
||||
cmd.wait()
|
||||
|
||||
return output.decode("utf-8")
|
||||
|
|
|
@ -55,4 +55,7 @@ class odtExporter(basicExporter):
|
|||
elif _type == "txt":
|
||||
text = text.replace("\n", "<br>")
|
||||
|
||||
elif _type == "html":
|
||||
text = self.htmlBody(text)
|
||||
|
||||
return text + "<br>"
|
||||
|
|
|
@ -49,6 +49,7 @@ defaultTextType = "t2t"
|
|||
fullScreenTheme = "spacedreams"
|
||||
|
||||
textEditor = {
|
||||
"background": "fff",
|
||||
"fontColor": "#000",
|
||||
"font": qApp.font().toString(),
|
||||
"misspelled": "#F00",
|
||||
|
|
|
@ -102,6 +102,8 @@ class settingsWindow(QWidget, Ui_Settings):
|
|||
self.btnEditorFontColor.clicked.connect(self.choseEditorFontColor)
|
||||
self.setButtonColor(self.btnEditorMisspelledColor, opt["misspelled"])
|
||||
self.btnEditorMisspelledColor.clicked.connect(self.choseEditorMisspelledColor)
|
||||
self.setButtonColor(self.btnEditorBackgroundColor, opt["background"])
|
||||
self.btnEditorBackgroundColor.clicked.connect(self.choseEditorBackgroundColor)
|
||||
f = QFont()
|
||||
f.fromString(opt["font"])
|
||||
self.cmbEditorFontFamily.setCurrentFont(f)
|
||||
|
@ -353,6 +355,17 @@ class settingsWindow(QWidget, Ui_Settings):
|
|||
settings.textEditor["misspelled"] = color.name()
|
||||
self.setButtonColor(self.btnEditorMisspelledColor, color.name())
|
||||
self.updateEditorSettings()
|
||||
|
||||
def choseEditorBackgroundColor(self):
|
||||
color = settings.textEditor["background"]
|
||||
self.colorDialog = QColorDialog(QColor(color), self)
|
||||
color = self.colorDialog.getColor(QColor(color))
|
||||
if color.isValid():
|
||||
settings.textEditor["background"] = color.name()
|
||||
self.setButtonColor(self.btnEditorBackgroundColor, color.name())
|
||||
self.updateEditorSettings()
|
||||
|
||||
|
||||
|
||||
####################################################################################################
|
||||
# STATUS #
|
||||
|
|
|
@ -724,7 +724,7 @@ class Ui_Settings(object):
|
|||
font.setWeight(50)
|
||||
self.label_37.setFont(font)
|
||||
self.label_37.setObjectName("label_37")
|
||||
self.formLayout_8.setWidget(0, QtWidgets.QFormLayout.LabelRole, self.label_37)
|
||||
self.formLayout_8.setWidget(1, QtWidgets.QFormLayout.LabelRole, self.label_37)
|
||||
self.btnEditorFontColor = QtWidgets.QPushButton(self.groupBox_12)
|
||||
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Fixed)
|
||||
sizePolicy.setHorizontalStretch(0)
|
||||
|
@ -737,14 +737,14 @@ class Ui_Settings(object):
|
|||
self.btnEditorFontColor.setFont(font)
|
||||
self.btnEditorFontColor.setText("")
|
||||
self.btnEditorFontColor.setObjectName("btnEditorFontColor")
|
||||
self.formLayout_8.setWidget(0, QtWidgets.QFormLayout.FieldRole, self.btnEditorFontColor)
|
||||
self.formLayout_8.setWidget(1, QtWidgets.QFormLayout.FieldRole, self.btnEditorFontColor)
|
||||
self.label_39 = QtWidgets.QLabel(self.groupBox_12)
|
||||
font = QtGui.QFont()
|
||||
font.setBold(False)
|
||||
font.setWeight(50)
|
||||
self.label_39.setFont(font)
|
||||
self.label_39.setObjectName("label_39")
|
||||
self.formLayout_8.setWidget(1, QtWidgets.QFormLayout.LabelRole, self.label_39)
|
||||
self.formLayout_8.setWidget(2, QtWidgets.QFormLayout.LabelRole, self.label_39)
|
||||
self.cmbEditorFontFamily = QtWidgets.QFontComboBox(self.groupBox_12)
|
||||
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Fixed)
|
||||
sizePolicy.setHorizontalStretch(0)
|
||||
|
@ -757,21 +757,21 @@ class Ui_Settings(object):
|
|||
font.setWeight(50)
|
||||
self.cmbEditorFontFamily.setFont(font)
|
||||
self.cmbEditorFontFamily.setObjectName("cmbEditorFontFamily")
|
||||
self.formLayout_8.setWidget(1, QtWidgets.QFormLayout.FieldRole, self.cmbEditorFontFamily)
|
||||
self.formLayout_8.setWidget(2, QtWidgets.QFormLayout.FieldRole, self.cmbEditorFontFamily)
|
||||
self.label_38 = QtWidgets.QLabel(self.groupBox_12)
|
||||
font = QtGui.QFont()
|
||||
font.setBold(False)
|
||||
font.setWeight(50)
|
||||
self.label_38.setFont(font)
|
||||
self.label_38.setObjectName("label_38")
|
||||
self.formLayout_8.setWidget(2, QtWidgets.QFormLayout.LabelRole, self.label_38)
|
||||
self.formLayout_8.setWidget(3, QtWidgets.QFormLayout.LabelRole, self.label_38)
|
||||
self.label_36 = QtWidgets.QLabel(self.groupBox_12)
|
||||
font = QtGui.QFont()
|
||||
font.setBold(False)
|
||||
font.setWeight(50)
|
||||
self.label_36.setFont(font)
|
||||
self.label_36.setObjectName("label_36")
|
||||
self.formLayout_8.setWidget(3, QtWidgets.QFormLayout.LabelRole, self.label_36)
|
||||
self.formLayout_8.setWidget(4, QtWidgets.QFormLayout.LabelRole, self.label_36)
|
||||
self.btnEditorMisspelledColor = QtWidgets.QPushButton(self.groupBox_12)
|
||||
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Fixed)
|
||||
sizePolicy.setHorizontalStretch(0)
|
||||
|
@ -784,7 +784,7 @@ class Ui_Settings(object):
|
|||
self.btnEditorMisspelledColor.setFont(font)
|
||||
self.btnEditorMisspelledColor.setText("")
|
||||
self.btnEditorMisspelledColor.setObjectName("btnEditorMisspelledColor")
|
||||
self.formLayout_8.setWidget(3, QtWidgets.QFormLayout.FieldRole, self.btnEditorMisspelledColor)
|
||||
self.formLayout_8.setWidget(4, QtWidgets.QFormLayout.FieldRole, self.btnEditorMisspelledColor)
|
||||
self.spnEditorFontSize = QtWidgets.QSpinBox(self.groupBox_12)
|
||||
font = QtGui.QFont()
|
||||
font.setBold(False)
|
||||
|
@ -794,7 +794,27 @@ class Ui_Settings(object):
|
|||
self.spnEditorFontSize.setMaximum(299)
|
||||
self.spnEditorFontSize.setProperty("value", 10)
|
||||
self.spnEditorFontSize.setObjectName("spnEditorFontSize")
|
||||
self.formLayout_8.setWidget(2, QtWidgets.QFormLayout.FieldRole, self.spnEditorFontSize)
|
||||
self.formLayout_8.setWidget(3, QtWidgets.QFormLayout.FieldRole, self.spnEditorFontSize)
|
||||
self.label_43 = QtWidgets.QLabel(self.groupBox_12)
|
||||
font = QtGui.QFont()
|
||||
font.setBold(False)
|
||||
font.setWeight(50)
|
||||
self.label_43.setFont(font)
|
||||
self.label_43.setObjectName("label_43")
|
||||
self.formLayout_8.setWidget(0, QtWidgets.QFormLayout.LabelRole, self.label_43)
|
||||
self.btnEditorBackgroundColor = QtWidgets.QPushButton(self.groupBox_12)
|
||||
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Fixed)
|
||||
sizePolicy.setHorizontalStretch(0)
|
||||
sizePolicy.setVerticalStretch(0)
|
||||
sizePolicy.setHeightForWidth(self.btnEditorBackgroundColor.sizePolicy().hasHeightForWidth())
|
||||
self.btnEditorBackgroundColor.setSizePolicy(sizePolicy)
|
||||
font = QtGui.QFont()
|
||||
font.setBold(False)
|
||||
font.setWeight(50)
|
||||
self.btnEditorBackgroundColor.setFont(font)
|
||||
self.btnEditorBackgroundColor.setText("")
|
||||
self.btnEditorBackgroundColor.setObjectName("btnEditorBackgroundColor")
|
||||
self.formLayout_8.setWidget(0, QtWidgets.QFormLayout.FieldRole, self.btnEditorBackgroundColor)
|
||||
self.horizontalLayout_11.addWidget(self.groupBox_12)
|
||||
self.groupBox_13 = QtWidgets.QGroupBox(self.tab_4)
|
||||
font = QtGui.QFont()
|
||||
|
@ -1533,6 +1553,7 @@ class Ui_Settings(object):
|
|||
self.label_39.setText(_translate("Settings", "Family:"))
|
||||
self.label_38.setText(_translate("Settings", "Size:"))
|
||||
self.label_36.setText(_translate("Settings", "Misspelled:"))
|
||||
self.label_43.setText(_translate("Settings", "Background:"))
|
||||
self.groupBox_13.setTitle(_translate("Settings", "Paragraphs"))
|
||||
self.label_40.setText(_translate("Settings", "Line spacing:"))
|
||||
self.cmbEditorLineSpacing.setItemText(0, _translate("Settings", "Single"))
|
||||
|
|
|
@ -1502,7 +1502,7 @@ text-align:center;</string>
|
|||
<string>Font</string>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="formLayout_8">
|
||||
<item row="0" column="0">
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_37">
|
||||
<property name="font">
|
||||
<font>
|
||||
|
@ -1515,7 +1515,7 @@ text-align:center;</string>
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<item row="1" column="1">
|
||||
<widget class="QPushButton" name="btnEditorFontColor">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
|
@ -1534,7 +1534,7 @@ text-align:center;</string>
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_39">
|
||||
<property name="font">
|
||||
<font>
|
||||
|
@ -1547,7 +1547,7 @@ text-align:center;</string>
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<item row="2" column="1">
|
||||
<widget class="QFontComboBox" name="cmbEditorFontFamily">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
|
@ -1569,7 +1569,7 @@ text-align:center;</string>
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_38">
|
||||
<property name="font">
|
||||
<font>
|
||||
|
@ -1582,7 +1582,7 @@ text-align:center;</string>
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="label_36">
|
||||
<property name="font">
|
||||
<font>
|
||||
|
@ -1595,7 +1595,7 @@ text-align:center;</string>
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<item row="4" column="1">
|
||||
<widget class="QPushButton" name="btnEditorMisspelledColor">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
|
@ -1614,7 +1614,7 @@ text-align:center;</string>
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<item row="3" column="1">
|
||||
<widget class="QSpinBox" name="spnEditorFontSize">
|
||||
<property name="font">
|
||||
<font>
|
||||
|
@ -1633,6 +1633,38 @@ text-align:center;</string>
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_43">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>50</weight>
|
||||
<bold>false</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Background:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QPushButton" name="btnEditorBackgroundColor">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>50</weight>
|
||||
<bold>false</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
|
@ -172,10 +172,12 @@ class textEditView(QTextEdit):
|
|||
f.fromString(opt["font"])
|
||||
#self.setFont(f)
|
||||
self.setStyleSheet("""
|
||||
background: {bg};
|
||||
color: {foreground};
|
||||
font-family: {ff};
|
||||
font-size: {fs};
|
||||
""".format(
|
||||
bg=opt["background"],
|
||||
foreground=opt["fontColor"],
|
||||
ff=f.family(),
|
||||
fs="{}pt".format(str(f.pointSize()))))
|
||||
|
@ -310,9 +312,12 @@ class textEditView(QTextEdit):
|
|||
#print(" Submitting html")
|
||||
self._updating = True
|
||||
html = self.toHtml()
|
||||
# We don't store font settings
|
||||
html = re.sub(r"font-family:.*?;", "", html)
|
||||
html = re.sub(r"font-size:.*?;", "", html)
|
||||
# We don't store paragraph and font settings
|
||||
html = re.sub(r"font-family:.*?;\s*", "", html)
|
||||
html = re.sub(r"font-size:.*?;\s*", "", html)
|
||||
html = re.sub(r"margin-.*?;\s*", "", html)
|
||||
html = re.sub(r"text-indent:.*?;\s*", "", html)
|
||||
html = re.sub(r"line-height:.*?;\s*", "", html)
|
||||
#print("Submitting:", html)
|
||||
self._model.setData(self._index, html)
|
||||
self._updating = False
|
||||
|
|
Loading…
Reference in a new issue