Move highlighting CSS into the ToHtml class

This commit is contained in:
Veronica Berglyd Olsen
2024-02-27 17:00:38 +01:00
parent f1ac1f7c21
commit a87a94ffeb
4 changed files with 9 additions and 14 deletions
+4 -4
View File
@@ -368,13 +368,12 @@ class ToHtml(Tokenizer):
def getStyleSheet(self) -> list[str]: def getStyleSheet(self) -> list[str]:
"""Generate a stylesheet for the current settings.""" """Generate a stylesheet for the current settings."""
styles = []
if not self._cssStyles: if not self._cssStyles:
return styles return []
mScale = self._lineHeight/1.15 mScale = self._lineHeight/1.15
textAlign = "justify" if self._doJustify else "left"
styles = []
styles.append("body {{font-family: '{0:s}'; font-size: {1:d}pt;}}".format( styles.append("body {{font-family: '{0:s}'; font-size: {1:d}pt;}}".format(
self._textFont, self._textSize self._textFont, self._textSize
)) ))
@@ -384,7 +383,7 @@ class ToHtml(Tokenizer):
"margin-top: {2:.2f}em; margin-bottom: {3:.2f}em;" "margin-top: {2:.2f}em; margin-bottom: {3:.2f}em;"
"}}" "}}"
).format( ).format(
textAlign, "justify" if self._doJustify else "left",
round(100 * self._lineHeight), round(100 * self._lineHeight),
mScale * self._marginText[0], mScale * self._marginText[0],
mScale * self._marginText[1], mScale * self._marginText[1],
@@ -449,6 +448,7 @@ class ToHtml(Tokenizer):
)) ))
styles.append("a {color: rgb(66, 113, 174);}") styles.append("a {color: rgb(66, 113, 174);}")
styles.append("mark {background: rgb(255, 255, 166);}")
styles.append(".tags {color: rgb(245, 135, 31); font-weight: bold;}") styles.append(".tags {color: rgb(245, 135, 31); font-weight: bold;}")
styles.append(".break {text-align: left;}") styles.append(".break {text-align: left;}")
styles.append(".synopsis {font-style: italic;}") styles.append(".synopsis {font-style: italic;}")
+1 -8
View File
@@ -756,20 +756,13 @@ class _PreviewWidget(QTextBrowser):
self.buildProgress.setCentreText(self.tr("Processing ...")) self.buildProgress.setCentreText(self.tr("Processing ..."))
qApp.processEvents() qApp.processEvents()
styles = "\n".join(data.get("styles", [ styles = "\n".join(data.get("styles", []))
"h1, h2 {color: rgb(66, 113, 174);}",
"h3, h4 {color: rgb(50, 50, 50);}",
"a {color: rgb(66, 113, 174);}",
".tags {color: rgb(245, 135, 31); font-weight: bold;}",
]))
self.document().setDefaultStyleSheet(styles) self.document().setDefaultStyleSheet(styles)
html = "".join(data.get("html", [])) html = "".join(data.get("html", []))
html = html.replace("\t", "!!tab!!") html = html.replace("\t", "!!tab!!")
html = html.replace("<del>", "<span style='text-decoration: line-through;'>") html = html.replace("<del>", "<span style='text-decoration: line-through;'>")
html = html.replace("</del>", "</span>") html = html.replace("</del>", "</span>")
html = html.replace("<mark>", "<span style='background-color: #ffffa6;'>")
html = html.replace("</mark>", "</span>")
self.setHtml(html) self.setHtml(html)
qApp.processEvents() qApp.processEvents()
while self.find("!!tab!!"): while self.find("!!tab!!"):
@@ -14,6 +14,7 @@ h4 {color: rgb(50, 50, 50); page-break-after: avoid; margin-top: 0.76em; margin-
.title {font-size: 2.5em; margin-top: 1.30em; margin-bottom: 0.65em;} .title {font-size: 2.5em; margin-top: 1.30em; margin-bottom: 0.65em;}
.sep, .skip {text-align: center; margin-top: 1.30em; margin-bottom: 1.30em;} .sep, .skip {text-align: center; margin-top: 1.30em; margin-bottom: 1.30em;}
a {color: rgb(66, 113, 174);} a {color: rgb(66, 113, 174);}
mark {background: rgb(255, 255, 166);}
.tags {color: rgb(245, 135, 31); font-weight: bold;} .tags {color: rgb(245, 135, 31); font-weight: bold;}
.break {text-align: left;} .break {text-align: left;}
.synopsis {font-style: italic;} .synopsis {font-style: italic;}
@@ -2,8 +2,8 @@
"meta": { "meta": {
"projectName": "Lorem Ipsum", "projectName": "Lorem Ipsum",
"novelAuthor": "lipsum.com", "novelAuthor": "lipsum.com",
"buildTime": 1706648755, "buildTime": 1709024252,
"buildTimeStr": "2024-01-30 22:05:55" "buildTimeStr": "2024-02-27 09:57:32"
}, },
"text": { "text": {
"css": [ "css": [
@@ -16,6 +16,7 @@
".title {font-size: 2.5em; margin-top: 1.30em; margin-bottom: 0.65em;}", ".title {font-size: 2.5em; margin-top: 1.30em; margin-bottom: 0.65em;}",
".sep, .skip {text-align: center; margin-top: 1.30em; margin-bottom: 1.30em;}", ".sep, .skip {text-align: center; margin-top: 1.30em; margin-bottom: 1.30em;}",
"a {color: rgb(66, 113, 174);}", "a {color: rgb(66, 113, 174);}",
"mark {background: rgb(255, 255, 166);}",
".tags {color: rgb(245, 135, 31); font-weight: bold;}", ".tags {color: rgb(245, 135, 31); font-weight: bold;}",
".break {text-align: left;}", ".break {text-align: left;}",
".synopsis {font-style: italic;}", ".synopsis {font-style: italic;}",