Added note root headings, changed some formatting, and improved export

This commit is contained in:
Veronica K. B. Olsen
2020-05-23 21:15:08 +02:00
parent cf58823f37
commit fd27f8d1e8
4 changed files with 110 additions and 75 deletions
+3 -3
View File
@@ -119,9 +119,9 @@ class ToHtml(Tokenizer):
if self.isNovel and self.genMode != self.M_PREVIEW:
# For novel files for export, we bump the titles one level
# up, as this is more useful for printing and word processor
# up as this is more useful for printing and word processor
# imports.
h1 = "h1 class=\"title\""
h1 = "h1 class='title'"
h2 = "h1"
h3 = "h2"
h4 = "h3"
@@ -254,7 +254,7 @@ class ToHtml(Tokenizer):
theStyles.append(r"h1, h2 {color: rgb(66, 113, 174);}")
theStyles.append(r"h3, h4 {color: rgb(50, 50, 50);}")
theStyles.append(r"h1, h2, h3, h4 {page-break-after: avoid;}")
theStyles.append(r".title {font-size: 2.5em; font-weight: bold;}")
theStyles.append(r".title {font-size: 2.5em;}")
theStyles.append(r".tags {color: rgb(245, 135, 31); font-weight: bold;}")
theStyles.append(r".break {text-align: left;}")
theStyles.append(r".sep {text-align: center; margin-top: 1em; margin-bottom: 1em;}")
+26 -5
View File
@@ -34,7 +34,7 @@ from PyQt5.QtCore import QRegularExpression
from nw.core.document import NWDoc
from nw.core.tools import numberToWord
from nw.constants import nwItemLayout
from nw.constants import nwItemLayout, nwItemType
logger = logging.getLogger(__name__)
@@ -198,6 +198,25 @@ class Tokenizer():
# Class Methods
##
def addRootHeading(self, theHandle):
"""Add a heading at the start if a new root folder.
"""
theItem = self.theProject.projTree[theHandle]
if theItem is None:
return False
if theItem.itemType != nwItemType.ROOT:
return False
theTitle = "Notes: %s" % theItem.itemName
self.theTokens = []
self.theTokens.append((
self.T_TITLE, theTitle, None, self.A_PBB | self.A_CENTRE
))
self.theMarkdown = "# %s\n\n" % theTitle
return True
def setText(self, theHandle, theText=None):
"""Set the text for the tokenizer from a handle. If theText is
not set, load it from the file.
@@ -205,6 +224,8 @@ class Tokenizer():
self.theHandle = theHandle
self.theItem = self.theProject.projTree[theHandle]
if self.theItem is None:
return
if theText is not None:
# If the text is set, just use that
@@ -319,7 +340,7 @@ class Tokenizer():
elif aLine[:2] == "# ":
self.theTokens.append((
self.T_HEAD1, aLine[2:].strip(), None, self.A_PBB
self.T_HEAD1, aLine[2:].strip(), None, self.A_NONE
))
tmpMarkdown.append("%s\n" % aLine)
@@ -386,8 +407,8 @@ class Tokenizer():
if self.isNone or self.isNote:
return
# For novel files, we need to handle chapter numbering and scene
# breaks
# For novel files, we need to handle chapter numbering, scene
# numbering, and scene breaks
if self.isNovel:
for n in range(len(self.theTokens)):
@@ -504,7 +525,7 @@ class Tokenizer():
)
else:
self.theTokens[n] = (
tType, tText, tFormat, self.A_PBB | self.A_CENTRE
tType, tText, tFormat, self.A_PBB | self.A_CENTRE
)
else:
self.theTokens[n] = (