Add support for dialogue highlighting in HTML output
This commit is contained in:
@@ -52,6 +52,10 @@ HTML5_TAGS = {
|
|||||||
Tokenizer.FMT_SUP_E: "</sup>",
|
Tokenizer.FMT_SUP_E: "</sup>",
|
||||||
Tokenizer.FMT_SUB_B: "<sub>",
|
Tokenizer.FMT_SUB_B: "<sub>",
|
||||||
Tokenizer.FMT_SUB_E: "</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: "",
|
Tokenizer.FMT_STRIP: "",
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -431,6 +435,8 @@ class ToHtml(Tokenizer):
|
|||||||
styles.append(".break {text-align: left;}")
|
styles.append(".break {text-align: left;}")
|
||||||
styles.append(".synopsis {font-style: italic;}")
|
styles.append(".synopsis {font-style: italic;}")
|
||||||
styles.append(".comment {font-style: italic; color: rgb(100, 100, 100);}")
|
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
|
return styles
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ mark {background: rgb(255, 255, 166);}
|
|||||||
.break {text-align: left;}
|
.break {text-align: left;}
|
||||||
.synopsis {font-style: italic;}
|
.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);}
|
||||||
</style>
|
</style>
|
||||||
<body>
|
<body>
|
||||||
<article>
|
<article>
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
"meta": {
|
"meta": {
|
||||||
"projectName": "Lorem Ipsum",
|
"projectName": "Lorem Ipsum",
|
||||||
"novelAuthor": "lipsum.com",
|
"novelAuthor": "lipsum.com",
|
||||||
"buildTime": 1716803284,
|
"buildTime": 1718032228,
|
||||||
"buildTimeStr": "2024-05-27 11:48:04"
|
"buildTimeStr": "2024-06-10 17:10:28"
|
||||||
},
|
},
|
||||||
"text": {
|
"text": {
|
||||||
"css": [
|
"css": [
|
||||||
@@ -20,7 +20,9 @@
|
|||||||
".keyword {color: rgb(245, 135, 31); font-weight: bold;}",
|
".keyword {color: rgb(245, 135, 31); font-weight: bold;}",
|
||||||
".break {text-align: left;}",
|
".break {text-align: left;}",
|
||||||
".synopsis {font-style: italic;}",
|
".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": [
|
"html": [
|
||||||
[
|
[
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import json
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
from novelwriter import CONFIG
|
||||||
from novelwriter.core.project import NWProject
|
from novelwriter.core.project import NWProject
|
||||||
from novelwriter.core.tohtml import ToHtml
|
from novelwriter.core.tohtml import ToHtml
|
||||||
|
|
||||||
@@ -260,6 +261,28 @@ def testCoreToHtml_ConvertParagraphs(mockGUI):
|
|||||||
"<a class='tag' href='#tag_Europe'>Europe</a></p>\n"
|
"<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
|
# Footnotes
|
||||||
# =========
|
# =========
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user