Add support for dialogue highlighting in HTML output

This commit is contained in:
Veronica Berglyd Olsen
2024-06-10 17:18:03 +02:00
parent f61ce3919b
commit f0f5ae6dc9
4 changed files with 36 additions and 3 deletions
+6
View File
@@ -52,6 +52,10 @@ HTML5_TAGS = {
Tokenizer.FMT_SUP_E: "</sup>",
Tokenizer.FMT_SUB_B: "<sub>",
Tokenizer.FMT_SUB_E: "</sub>",
Tokenizer.FMT_DL_B: "<span class='dialog'>",
Tokenizer.FMT_DL_E: "</span>",
Tokenizer.FMT_ADL_B: "<span class='altdialog'>",
Tokenizer.FMT_ADL_E: "</span>",
Tokenizer.FMT_STRIP: "",
}
@@ -431,6 +435,8 @@ class ToHtml(Tokenizer):
styles.append(".break {text-align: left;}")
styles.append(".synopsis {font-style: italic;}")
styles.append(".comment {font-style: italic; color: rgb(100, 100, 100);}")
styles.append(".dialog {color: rgb(174, 0, 0);}")
styles.append(".altdialog {color: rgb(66, 113, 174);}")
return styles
@@ -19,6 +19,8 @@ mark {background: rgb(255, 255, 166);}
.break {text-align: left;}
.synopsis {font-style: italic;}
.comment {font-style: italic; color: rgb(100, 100, 100);}
.dialog {color: rgb(174, 0, 0);}
.altdialog {color: rgb(66, 113, 174);}
</style>
<body>
<article>
@@ -2,8 +2,8 @@
"meta": {
"projectName": "Lorem Ipsum",
"novelAuthor": "lipsum.com",
"buildTime": 1716803284,
"buildTimeStr": "2024-05-27 11:48:04"
"buildTime": 1718032228,
"buildTimeStr": "2024-06-10 17:10:28"
},
"text": {
"css": [
@@ -20,7 +20,9 @@
".keyword {color: rgb(245, 135, 31); font-weight: bold;}",
".break {text-align: left;}",
".synopsis {font-style: italic;}",
".comment {font-style: italic; color: rgb(100, 100, 100);}"
".comment {font-style: italic; color: rgb(100, 100, 100);}",
".dialog {color: rgb(174, 0, 0);}",
".altdialog {color: rgb(66, 113, 174);}"
],
"html": [
[
+23
View File
@@ -24,6 +24,7 @@ import json
import pytest
from novelwriter import CONFIG
from novelwriter.core.project import NWProject
from novelwriter.core.tohtml import ToHtml
@@ -260,6 +261,28 @@ def testCoreToHtml_ConvertParagraphs(mockGUI):
"<a class='tag' href='#tag_Europe'>Europe</a></p>\n"
)
# Dialogue
html.setDialogueHighlight(True)
html._text = "## Chapter\n\nThis text \u201chas dialogue\u201d in it.\n\n"
html.tokenizeText()
html.doConvert()
assert html.result == (
"<h1 style='page-break-before: always;'>Chapter</h1>\n"
"<p>This text <span class='dialog'>\u201chas dialogue\u201d</span> in it.</p>\n"
)
# Alt. Dialogue
CONFIG.altDialogOpen = "::"
CONFIG.altDialogClose = "::"
html.setDialogueHighlight(True)
html._text = "## Chapter\n\nThis text :: has alt dialogue :: in it.\n\n"
html.tokenizeText()
html.doConvert()
assert html.result == (
"<h1 style='page-break-before: always;'>Chapter</h1>\n"
"<p>This text <span class='altdialog'>:: has alt dialogue ::</span> in it.</p>\n"
)
# Footnotes
# =========