Move highlighting CSS into the ToHtml class
This commit is contained in:
@@ -368,13 +368,12 @@ class ToHtml(Tokenizer):
|
||||
|
||||
def getStyleSheet(self) -> list[str]:
|
||||
"""Generate a stylesheet for the current settings."""
|
||||
styles = []
|
||||
if not self._cssStyles:
|
||||
return styles
|
||||
return []
|
||||
|
||||
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(
|
||||
self._textFont, self._textSize
|
||||
))
|
||||
@@ -384,7 +383,7 @@ class ToHtml(Tokenizer):
|
||||
"margin-top: {2:.2f}em; margin-bottom: {3:.2f}em;"
|
||||
"}}"
|
||||
).format(
|
||||
textAlign,
|
||||
"justify" if self._doJustify else "left",
|
||||
round(100 * self._lineHeight),
|
||||
mScale * self._marginText[0],
|
||||
mScale * self._marginText[1],
|
||||
@@ -449,6 +448,7 @@ class ToHtml(Tokenizer):
|
||||
))
|
||||
|
||||
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(".break {text-align: left;}")
|
||||
styles.append(".synopsis {font-style: italic;}")
|
||||
|
||||
@@ -756,20 +756,13 @@ class _PreviewWidget(QTextBrowser):
|
||||
self.buildProgress.setCentreText(self.tr("Processing ..."))
|
||||
qApp.processEvents()
|
||||
|
||||
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;}",
|
||||
]))
|
||||
styles = "\n".join(data.get("styles", []))
|
||||
self.document().setDefaultStyleSheet(styles)
|
||||
|
||||
html = "".join(data.get("html", []))
|
||||
html = html.replace("\t", "!!tab!!")
|
||||
html = html.replace("<del>", "<span style='text-decoration: line-through;'>")
|
||||
html = html.replace("</del>", "</span>")
|
||||
html = html.replace("<mark>", "<span style='background-color: #ffffa6;'>")
|
||||
html = html.replace("</mark>", "</span>")
|
||||
self.setHtml(html)
|
||||
qApp.processEvents()
|
||||
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;}
|
||||
.sep, .skip {text-align: center; margin-top: 1.30em; margin-bottom: 1.30em;}
|
||||
a {color: rgb(66, 113, 174);}
|
||||
mark {background: rgb(255, 255, 166);}
|
||||
.tags {color: rgb(245, 135, 31); font-weight: bold;}
|
||||
.break {text-align: left;}
|
||||
.synopsis {font-style: italic;}
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
"meta": {
|
||||
"projectName": "Lorem Ipsum",
|
||||
"novelAuthor": "lipsum.com",
|
||||
"buildTime": 1706648755,
|
||||
"buildTimeStr": "2024-01-30 22:05:55"
|
||||
"buildTime": 1709024252,
|
||||
"buildTimeStr": "2024-02-27 09:57:32"
|
||||
},
|
||||
"text": {
|
||||
"css": [
|
||||
@@ -16,6 +16,7 @@
|
||||
".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;}",
|
||||
"a {color: rgb(66, 113, 174);}",
|
||||
"mark {background: rgb(255, 255, 166);}",
|
||||
".tags {color: rgb(245, 135, 31); font-weight: bold;}",
|
||||
".break {text-align: left;}",
|
||||
".synopsis {font-style: italic;}",
|
||||
|
||||
Reference in New Issue
Block a user