mirror of
https://github.com/olivierkes/manuskript.git
synced 2024-05-21 21:32:26 +12:00
More export format added
This commit is contained in:
parent
a956856da9
commit
cb04c39362
|
@ -68,6 +68,15 @@ SOURCES += ../manuskript/ui/exporters/exportersManager.py
|
|||
SOURCES += ../manuskript/ui/exporters/manuskript/plainTextSettings.py
|
||||
|
||||
|
||||
SOURCES += ../manuskript/exporter/basic.py
|
||||
SOURCES += ../manuskript/exporter/mmd.py
|
||||
SOURCES += ../manuskript/exporter/pandoc.py
|
||||
SOURCES += ../manuskript/exporter/manuskript/__init__.py
|
||||
SOURCES += ../manuskript/exporter/manuskript/HTML.py
|
||||
SOURCES += ../manuskript/exporter/manuskript/markdown.py
|
||||
SOURCES += ../manuskript/exporter/manuskript/plainText.py
|
||||
|
||||
|
||||
|
||||
TRANSLATIONS += manuskript_fr.ts
|
||||
TRANSLATIONS += manuskript_es.ts
|
||||
|
|
|
@ -62,6 +62,7 @@ class basicExporter:
|
|||
class basicFormat:
|
||||
|
||||
implemented = False
|
||||
InvalidBecause = ""
|
||||
requires = {
|
||||
"Settings": False,
|
||||
"Preview": False,
|
||||
|
@ -102,3 +103,7 @@ class basicFormat:
|
|||
text = text.replace(B, A)
|
||||
return text
|
||||
|
||||
@classmethod
|
||||
def isValid(cls):
|
||||
return True
|
||||
|
||||
|
|
69
manuskript/exporter/manuskript/HTML.py
Normal file
69
manuskript/exporter/manuskript/HTML.py
Normal file
|
@ -0,0 +1,69 @@
|
|||
#!/usr/bin/env python
|
||||
# --!-- coding: utf8 --!--
|
||||
from PyQt5.QtCore import Qt
|
||||
from PyQt5.QtWebKitWidgets import QWebView
|
||||
from PyQt5.QtWidgets import QPlainTextEdit, qApp, QTabWidget, QFrame
|
||||
|
||||
from manuskript.exporter.manuskript.markdown import markdown
|
||||
from manuskript.ui.exporters.manuskript.plainTextSettings import exporterSettings
|
||||
|
||||
try:
|
||||
import markdown as MD
|
||||
except ImportError:
|
||||
MD = None
|
||||
|
||||
class HTML(markdown):
|
||||
name = qApp.tr("HTML")
|
||||
description = qApp.tr("Basic HTML output using python module 'markdown'.")
|
||||
InvalidBecause = qApp.tr("python module 'markdown'.")
|
||||
|
||||
@classmethod
|
||||
def isValid(cls):
|
||||
return MD is not None
|
||||
|
||||
@classmethod
|
||||
def settingsWidget(cls):
|
||||
w = exporterSettings(cls)
|
||||
w.loadSettings()
|
||||
return w
|
||||
|
||||
@classmethod
|
||||
def previewWidget(cls):
|
||||
t = QTabWidget()
|
||||
t.setDocumentMode(True)
|
||||
t.setStyleSheet("""
|
||||
QTabBar::tab{
|
||||
background-color: #BBB;
|
||||
padding: 2px;
|
||||
border: none;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
QTabBar::tab:selected, QToolBox::tab:hover{
|
||||
background-color:skyblue;
|
||||
}
|
||||
""")
|
||||
w1 = QPlainTextEdit()
|
||||
w1.setFrameShape(QFrame.NoFrame)
|
||||
w1.setReadOnly(True)
|
||||
w2 = QWebView()
|
||||
t.addTab(w2, qApp.tr("HTML"))
|
||||
t.addTab(w1, qApp.tr("Source"))
|
||||
return t
|
||||
|
||||
@classmethod
|
||||
def preview(cls, settingsWidget, previewWidget):
|
||||
settings = settingsWidget.getSettings()
|
||||
|
||||
# Save settings
|
||||
settingsWidget.writeSettings()
|
||||
|
||||
src = markdown.output(settings)
|
||||
html = MD.markdown(src)
|
||||
|
||||
cls.preparesTextEditView(previewWidget.widget(1), settings["Preview"]["PreviewFont"])
|
||||
previewWidget.widget(1).setPlainText(html)
|
||||
previewWidget.widget(0).setHtml(html)
|
||||
|
||||
|
||||
|
|
@ -3,6 +3,7 @@
|
|||
from PyQt5.QtWidgets import QTextEdit, qApp
|
||||
|
||||
from manuskript.exporter.basic import basicExporter, basicFormat
|
||||
from manuskript.exporter.manuskript.HTML import HTML
|
||||
from manuskript.exporter.manuskript.markdown import markdown
|
||||
from manuskript.exporter.manuskript.plainText import plainText
|
||||
|
||||
|
@ -14,7 +15,7 @@ class manuskriptExporter(basicExporter):
|
|||
exportTo = [
|
||||
plainText,
|
||||
markdown,
|
||||
basicFormat("HTML"),
|
||||
HTML,
|
||||
basicFormat("OPML")
|
||||
]
|
||||
|
||||
|
|
|
@ -11,8 +11,8 @@ from manuskript.ui.exporters.manuskript.plainTextSettings import exporterSetting
|
|||
|
||||
class markdown(plainText):
|
||||
name = qApp.tr("Markdown")
|
||||
description = qApp.tr("Just like plain text, excepts adds markdown titles. \
|
||||
Presupposes that texts are formatted in markdown.")
|
||||
description = qApp.tr("""Just like plain text, excepts adds markdown titles.
|
||||
Presupposes that texts are formatted in markdown.""")
|
||||
|
||||
@classmethod
|
||||
def settingsWidget(cls):
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
# --!-- coding: utf8 --!--
|
||||
import re
|
||||
from PyQt5.QtGui import QFont, QTextCharFormat
|
||||
from PyQt5.QtWidgets import QPlainTextEdit, qApp
|
||||
from PyQt5.QtWidgets import QPlainTextEdit, qApp, QFrame
|
||||
|
||||
from manuskript.exporter.basic import basicFormat
|
||||
from manuskript.functions import mainWindow
|
||||
|
@ -12,8 +12,8 @@ from manuskript.ui.exporters.manuskript.plainTextSettings import exporterSetting
|
|||
|
||||
class plainText(basicFormat):
|
||||
name = qApp.tr("Plain text")
|
||||
description = qApp.tr("Simplest export to plain text. Allows you to use your own markup not understood " \
|
||||
"by manuskript, for example <a href='www.fountain.io'>Fountain</a>.")
|
||||
description = qApp.tr("""Simplest export to plain text. Allows you to use your own markup not understood
|
||||
by manuskript, for example <a href='www.fountain.io'>Fountain</a>.""")
|
||||
implemented = True
|
||||
requires = {
|
||||
"Settings": True,
|
||||
|
@ -29,9 +29,14 @@ class plainText(basicFormat):
|
|||
@classmethod
|
||||
def previewWidget(cls):
|
||||
w = QPlainTextEdit()
|
||||
w.setFrameShape(QFrame.NoFrame)
|
||||
w.setReadOnly(True)
|
||||
return w
|
||||
|
||||
@classmethod
|
||||
def output(cls, settings):
|
||||
return cls.concatenate(mainWindow().mdlOutline.rootItem, settings)
|
||||
|
||||
@classmethod
|
||||
def preview(cls, settingsWidget, previewWidget):
|
||||
settings = settingsWidget.getSettings()
|
||||
|
@ -39,17 +44,21 @@ class plainText(basicFormat):
|
|||
# Save settings
|
||||
settingsWidget.writeSettings()
|
||||
|
||||
r = cls.concatenate(mainWindow().mdlOutline.rootItem, settings)
|
||||
r = cls.output(settings)
|
||||
|
||||
# Set preview font
|
||||
cf = QTextCharFormat()
|
||||
f = QFont()
|
||||
f.fromString(settings["Preview"]["PreviewFont"])
|
||||
cf.setFont(f)
|
||||
previewWidget.setCurrentCharFormat(cf)
|
||||
cls.preparesTextEditView(previewWidget, settings["Preview"]["PreviewFont"])
|
||||
|
||||
previewWidget.setPlainText(r)
|
||||
|
||||
@classmethod
|
||||
def preparesTextEditView(cls, view, textFont):
|
||||
cf = QTextCharFormat()
|
||||
f = QFont()
|
||||
f.fromString(textFont)
|
||||
cf.setFont(f)
|
||||
view.setCurrentCharFormat(cf)
|
||||
|
||||
@classmethod
|
||||
def concatenate(cls, item: outlineItem, settings) -> str:
|
||||
s = settings
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#!/usr/bin/env python
|
||||
# --!-- coding: utf8 --!--
|
||||
from PyQt5.QtWidgets import qApp
|
||||
|
||||
from manuskript.exporter.basic import basicExporter, basicFormat
|
||||
|
||||
|
@ -7,9 +8,9 @@ from manuskript.exporter.basic import basicExporter, basicFormat
|
|||
class mmdExporter(basicExporter):
|
||||
|
||||
name = "MultiMarkdown"
|
||||
description = """<p>A superset of markdown.</p>
|
||||
description = qApp.tr("""<p>A superset of markdown.</p>
|
||||
<p>Website: <a href="http://fletcherpenney.net/multimarkdown/">http://fletcherpenney.net/multimarkdown/</a></p>
|
||||
"""
|
||||
""")
|
||||
exportTo = [
|
||||
basicFormat("HTML", "A little known format modestly used. You know, web sites for example."),
|
||||
basicFormat("latex", ""),
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
#!/usr/bin/env python
|
||||
# --!-- coding: utf8 --!--
|
||||
from PyQt5.QtWidgets import qApp
|
||||
|
||||
from manuskript.exporter.basic import basicExporter, basicFormat
|
||||
|
||||
class HTMLFormat(basicFormat):
|
||||
name = "HTML"
|
||||
description = "A little known format modestly used. You know, web sites for example."
|
||||
description = qApp.tr("A little known format modestly used. You know, web sites for example.")
|
||||
implemented = False
|
||||
requires = {
|
||||
"Settings": True,
|
||||
|
@ -16,10 +17,10 @@ class HTMLFormat(basicFormat):
|
|||
class pandocExporter(basicExporter):
|
||||
|
||||
name = "Pandoc"
|
||||
description = """<p>A universal document convertor. Can be used to convert markdown to a wide range of other
|
||||
description = qApp.tr("""<p>A universal document convertor. Can be used to convert markdown to a wide range of other
|
||||
formats.</p>
|
||||
<p>Website: <a href="http://www.pandoc.org">http://pandoc.org/</a></p>
|
||||
"""
|
||||
""")
|
||||
exportTo = [
|
||||
HTMLFormat,
|
||||
basicFormat("ePub", "Books that don't kill trees."),
|
||||
|
|
|
@ -36,6 +36,10 @@ class exporterDialog(QWidget, Ui_exporter):
|
|||
item.setFlags(Qt.ItemIsEnabled)
|
||||
|
||||
for f in E.exportTo:
|
||||
|
||||
if not f.isValid():
|
||||
continue
|
||||
|
||||
name = f.name if f.implemented else self.tr("{} (not implemented yet)").format(f.name)
|
||||
self.cmbExporters.addItem(name, E.name)
|
||||
|
||||
|
@ -113,7 +117,9 @@ class exporterDialog(QWidget, Ui_exporter):
|
|||
# Removes every items from given layout.
|
||||
l = group.layout()
|
||||
while l.count():
|
||||
l.removeItem(l.itemAt(0))
|
||||
item = l.itemAt(0)
|
||||
l.removeItem(item)
|
||||
item.widget().deleteLater()
|
||||
|
||||
l.addWidget(widget)
|
||||
widget.setParent(group)
|
|
@ -92,8 +92,15 @@ class exportersManager(QWidget, Ui_ExportersManager):
|
|||
self.lblExportToDescription.setText("")
|
||||
|
||||
else:
|
||||
self.lblExportToDescription.setText("<b>{}:</b> {}".format(
|
||||
|
||||
desc = "<b>{}:</b> {}".format(
|
||||
name,
|
||||
f.description))
|
||||
f.description)
|
||||
|
||||
if not f.isValid():
|
||||
desc += "<br><br>" + \
|
||||
self.tr("<b>Status:</b> uninstalled.") + \
|
||||
"<br><br>" + \
|
||||
self.tr("<b>Requires:</b> ") + f.InvalidBecause
|
||||
|
||||
self.lblExportToDescription.setText(desc)
|
||||
|
|
|
@ -104,7 +104,7 @@ class exporterSettings(QWidget, Ui_exporterSettings):
|
|||
cmb.currentIndexChanged.connect(self.transCmbChanged)
|
||||
cmb.currentIndexChanged.emit(0)
|
||||
|
||||
self.btnTransAdd.clicked.connect(self.transAddTableRow)
|
||||
self.btnTransAdd.clicked.connect(lambda: self.transAddTableRow(checked=True))
|
||||
self.btnTransRemove.clicked.connect(self.transRemoveTableRow)
|
||||
self.tableWidgetAdjustToContent(self.tblReplacements)
|
||||
|
||||
|
@ -308,13 +308,13 @@ class exporterSettings(QWidget, Ui_exporterSettings):
|
|||
|
||||
def contentUpdateTable(self):
|
||||
|
||||
def addFolderRow(text="Folder"):
|
||||
def addFolderRow(text=self.tr("Folder")):
|
||||
self.tableWidgetAddRow(self.tblContent, [
|
||||
self.tableWidgetMakeItem(text, "folder"),
|
||||
self.tableWidgetMakeItem("", "", True, True),
|
||||
])
|
||||
|
||||
def addTextRow(text="Text"):
|
||||
def addTextRow(text=self.tr("Text")):
|
||||
self.tableWidgetAddRow(self.tblContent, [
|
||||
self.tableWidgetMakeItem(text, "text-x-generic"),
|
||||
self.tableWidgetMakeItem("", "", True, False),
|
||||
|
@ -331,10 +331,10 @@ class exporterSettings(QWidget, Ui_exporterSettings):
|
|||
level = self.mw.mdlOutline.maxLevel()
|
||||
|
||||
for i in range(level):
|
||||
addFolderRow("{}Level {} folder".format(" " * i, i + 1))
|
||||
addFolderRow(self.tr("{}Level {} folder").format(" " * i, i + 1))
|
||||
|
||||
for i in range(level):
|
||||
addTextRow("{}Level {} text".format(" " * i, i + 1))
|
||||
addTextRow(self.tr("{}Level {} text").format(" " * i, i + 1))
|
||||
|
||||
self.tableWidgetAdjustToContent(self.tblContent)
|
||||
|
||||
|
|
Loading…
Reference in a new issue