Use a set to track comment styles to include in build
This commit is contained in:
@@ -30,7 +30,7 @@ from novelwriter.constants import nwHeadFmt
|
||||
from novelwriter.core.buildsettings import BuildSettings
|
||||
from novelwriter.core.docbuild import NWBuildDocument
|
||||
from novelwriter.core.project import NWProject
|
||||
from novelwriter.enum import nwBuildFmt
|
||||
from novelwriter.enum import nwBuildFmt, nwComment
|
||||
from novelwriter.formats.shared import BlockFmt, BlockTyp
|
||||
from novelwriter.formats.todocx import OOXML_SCM, ToDocX, _mkTag, _wTag
|
||||
|
||||
@@ -226,8 +226,9 @@ def testFmtToDocX_ParagraphStyles(mockGUI):
|
||||
"""Test formatting of paragraphs."""
|
||||
project = NWProject()
|
||||
doc = ToDocX(project)
|
||||
doc.setSynopsis(True)
|
||||
doc.setComments(True)
|
||||
doc.setCommentType(nwComment.PLAIN, True)
|
||||
doc.setCommentType(nwComment.SYNOPSIS, True)
|
||||
doc.setCommentType(nwComment.SHORT, True)
|
||||
doc.setKeywords(True)
|
||||
doc.initDocument()
|
||||
|
||||
@@ -389,8 +390,8 @@ def testFmtToDocX_ParagraphFormatting(mockGUI):
|
||||
"""Test formatting of paragraphs."""
|
||||
project = NWProject()
|
||||
doc = ToDocX(project)
|
||||
doc.setSynopsis(True)
|
||||
doc.setComments(True)
|
||||
doc.setCommentType(nwComment.PLAIN, True)
|
||||
doc.setCommentType(nwComment.SYNOPSIS, True)
|
||||
doc.setKeywords(True)
|
||||
doc.initDocument()
|
||||
|
||||
@@ -743,7 +744,7 @@ def testFmtToDocX_SaveDocument(mockGUI, prjLipsum, fncPath, tstPaths):
|
||||
def prettifyXml(inFile, outFile):
|
||||
with open(outFile, mode="wb") as fStream:
|
||||
xml = ET.parse(inFile)
|
||||
xmlIndent(xml)
|
||||
xmlIndent(xml) # type: ignore
|
||||
xml.write(fStream, encoding="utf-8", xml_declaration=True)
|
||||
|
||||
expected = [
|
||||
|
||||
@@ -27,6 +27,7 @@ import pytest
|
||||
from novelwriter import CONFIG
|
||||
from novelwriter.constants import nwHeadFmt
|
||||
from novelwriter.core.project import NWProject
|
||||
from novelwriter.enum import nwComment
|
||||
from novelwriter.formats.shared import BlockFmt, BlockTyp
|
||||
from novelwriter.formats.tohtml import ToHtml
|
||||
|
||||
@@ -185,7 +186,7 @@ def testFmtToHtml_ConvertParagraphs(mockGUI):
|
||||
html.doConvert()
|
||||
assert html._pages[-1] == ""
|
||||
|
||||
html.setSynopsis(True)
|
||||
html.setCommentType(nwComment.SYNOPSIS, True)
|
||||
html._text = "%synopsis: The synopsis ...\n"
|
||||
html.tokenizeText()
|
||||
html.doConvert()
|
||||
@@ -196,7 +197,7 @@ def testFmtToHtml_ConvertParagraphs(mockGUI):
|
||||
"</p>\n"
|
||||
)
|
||||
|
||||
html.setSynopsis(True)
|
||||
html.setCommentType(nwComment.SHORT, True)
|
||||
html._text = "%short: A short description ...\n"
|
||||
html.tokenizeText()
|
||||
html.doConvert()
|
||||
@@ -213,7 +214,7 @@ def testFmtToHtml_ConvertParagraphs(mockGUI):
|
||||
html.doConvert()
|
||||
assert html._pages[-1] == ""
|
||||
|
||||
html.setComments(True)
|
||||
html.setCommentType(nwComment.PLAIN, True)
|
||||
html._text = "% A comment ...\n"
|
||||
html.tokenizeText()
|
||||
html.doConvert()
|
||||
@@ -575,7 +576,7 @@ def testFmtToHtml_SpecialCases(mockGUI):
|
||||
# ===================
|
||||
# See: https://github.com/vkbo/novelWriter/issues/950
|
||||
|
||||
html.setComments(True)
|
||||
html.setCommentType(nwComment.PLAIN, True)
|
||||
html._text = "% Test > text _<**bold**>_ and more.\n"
|
||||
html.tokenizeText()
|
||||
html.doConvert()
|
||||
|
||||
@@ -99,8 +99,7 @@ def testFmtToken_Setters(mockGUI):
|
||||
assert tokens._hideSection is False
|
||||
assert tokens._linkHeadings is False
|
||||
assert tokens._doBodyText is True
|
||||
assert tokens._doSynopsis is False
|
||||
assert tokens._doComments is False
|
||||
assert tokens._doComments == {nwComment.FOOTNOTE}
|
||||
assert tokens._doKeywords is False
|
||||
|
||||
# Set new values
|
||||
@@ -124,8 +123,9 @@ def testFmtToken_Setters(mockGUI):
|
||||
tokens.setSeparatorMargins(2.0, 2.0)
|
||||
tokens.setLinkHeadings(True)
|
||||
tokens.setBodyText(False)
|
||||
tokens.setSynopsis(True)
|
||||
tokens.setComments(True)
|
||||
tokens.setCommentType(nwComment.PLAIN, True)
|
||||
tokens.setCommentType(nwComment.SHORT, True)
|
||||
tokens.setCommentType(nwComment.SYNOPSIS, True)
|
||||
tokens.setKeywords(True)
|
||||
|
||||
# Check new values
|
||||
@@ -155,8 +155,9 @@ def testFmtToken_Setters(mockGUI):
|
||||
assert tokens._hideSection is True
|
||||
assert tokens._linkHeadings is True
|
||||
assert tokens._doBodyText is False
|
||||
assert tokens._doSynopsis is True
|
||||
assert tokens._doComments is True
|
||||
assert tokens._doComments == {
|
||||
nwComment.FOOTNOTE, nwComment.PLAIN, nwComment.SYNOPSIS, nwComment.SHORT,
|
||||
}
|
||||
assert tokens._doKeywords is True
|
||||
|
||||
# Properties
|
||||
@@ -756,12 +757,12 @@ def testFmtToken_MetaFormat(mockGUI):
|
||||
assert tokens._blocks == []
|
||||
|
||||
# Comment
|
||||
tokens.setComments(False)
|
||||
tokens.setCommentType(nwComment.PLAIN, False)
|
||||
tokens._text = "% A comment\n"
|
||||
tokens.tokenizeText()
|
||||
assert tokens._blocks == []
|
||||
|
||||
tokens.setComments(True)
|
||||
tokens.setCommentType(nwComment.PLAIN, True)
|
||||
tokens._text = "% A comment\n"
|
||||
tokens.tokenizeText()
|
||||
assert tokens._blocks == [(
|
||||
@@ -773,12 +774,12 @@ def testFmtToken_MetaFormat(mockGUI):
|
||||
)]
|
||||
|
||||
# Synopsis
|
||||
tokens.setSynopsis(False)
|
||||
tokens.setCommentType(nwComment.SYNOPSIS, False)
|
||||
tokens._text = "%synopsis: The synopsis\n"
|
||||
tokens.tokenizeText()
|
||||
assert tokens._blocks == []
|
||||
|
||||
tokens.setSynopsis(True)
|
||||
tokens.setCommentType(nwComment.SYNOPSIS, True)
|
||||
tokens._text = "% synopsis: The synopsis\n"
|
||||
tokens.tokenizeText()
|
||||
assert tokens._blocks == [(
|
||||
@@ -790,12 +791,12 @@ def testFmtToken_MetaFormat(mockGUI):
|
||||
)]
|
||||
|
||||
# Short
|
||||
tokens.setSynopsis(False)
|
||||
tokens.setCommentType(nwComment.SHORT, False)
|
||||
tokens._text = "% short: A short description\n"
|
||||
tokens.tokenizeText()
|
||||
assert tokens._blocks == []
|
||||
|
||||
tokens.setSynopsis(True)
|
||||
tokens.setCommentType(nwComment.SHORT, True)
|
||||
tokens._text = "% short: A short description\n"
|
||||
tokens.tokenizeText()
|
||||
assert tokens._blocks == [(
|
||||
@@ -1151,7 +1152,7 @@ def testFmtToken_LineBreak(mockGUI):
|
||||
project = NWProject()
|
||||
tokens = BareTokenizer(project)
|
||||
tokens._handle = TMH
|
||||
tokens.setComments(True)
|
||||
tokens.setCommentType(nwComment.PLAIN, True)
|
||||
|
||||
# They are stripped in headers
|
||||
tokens._text = "## Hello[br] World"
|
||||
@@ -1516,7 +1517,7 @@ def testFmtToken_TextIndent(mockGUI):
|
||||
"""Test the handling of text indent in the Tokenizer class."""
|
||||
project = NWProject()
|
||||
tokens = BareTokenizer(project)
|
||||
tokens.setSynopsis(True)
|
||||
tokens.setCommentType(nwComment.SYNOPSIS, True)
|
||||
tokens._handle = TMH
|
||||
|
||||
# No First Indent
|
||||
@@ -1987,7 +1988,7 @@ def testFmtToken_CountStats(mockGUI, ipsumText):
|
||||
tokens._counts = {}
|
||||
tokens.setChapterFormat(nwHeadFmt.TITLE)
|
||||
tokens.setSceneFormat("* * *", False)
|
||||
tokens.setSynopsis(True)
|
||||
tokens.setCommentType(nwComment.SYNOPSIS, True)
|
||||
tokens.tokenizeText()
|
||||
tokens.countStats()
|
||||
assert [t[2] for t in tokens._blocks] == ["Chapter", "Synopsis: Stuff", "Text"]
|
||||
@@ -2004,7 +2005,7 @@ def testFmtToken_CountStats(mockGUI, ipsumText):
|
||||
tokens._counts = {}
|
||||
tokens.setChapterFormat(nwHeadFmt.TITLE)
|
||||
tokens.setSceneFormat("* * *", False)
|
||||
tokens.setSynopsis(True)
|
||||
tokens.setCommentType(nwComment.SHORT, True)
|
||||
tokens.tokenizeText()
|
||||
tokens.countStats()
|
||||
assert [t[2] for t in tokens._blocks] == ["Chapter", "Short Description: Stuff", "Text"]
|
||||
@@ -2021,7 +2022,7 @@ def testFmtToken_CountStats(mockGUI, ipsumText):
|
||||
tokens._counts = {}
|
||||
tokens.setChapterFormat(nwHeadFmt.TITLE)
|
||||
tokens.setSceneFormat("* * *", False)
|
||||
tokens.setComments(True)
|
||||
tokens.setCommentType(nwComment.PLAIN, True)
|
||||
tokens.tokenizeText()
|
||||
tokens.countStats()
|
||||
assert [t[2] for t in tokens._blocks] == ["Chapter", "Comment: Stuff", "Text"]
|
||||
@@ -2095,8 +2096,8 @@ def testFmtToken_CountStats(mockGUI, ipsumText):
|
||||
tokens.setPartitionFormat(f"T: {nwHeadFmt.TITLE}")
|
||||
tokens.setChapterFormat(f"C {nwHeadFmt.CH_NUM}: {nwHeadFmt.TITLE}")
|
||||
tokens.setSceneFormat("* * *", False)
|
||||
tokens.setSynopsis(True)
|
||||
tokens.setComments(True)
|
||||
tokens.setCommentType(nwComment.SYNOPSIS, True)
|
||||
tokens.setCommentType(nwComment.PLAIN, True)
|
||||
tokens.setKeywords(True)
|
||||
|
||||
tokens.tokenizeText()
|
||||
|
||||
@@ -24,6 +24,7 @@ import pytest
|
||||
|
||||
from novelwriter.constants import nwHeadFmt
|
||||
from novelwriter.core.project import NWProject
|
||||
from novelwriter.enum import nwComment
|
||||
from novelwriter.formats.shared import BlockFmt, BlockTyp
|
||||
from novelwriter.formats.tomarkdown import ToMarkdown
|
||||
|
||||
@@ -148,13 +149,13 @@ def testFmtToMarkdown_ConvertParagraphs(mockGUI):
|
||||
md.doConvert()
|
||||
assert md._pages[-1] == ""
|
||||
|
||||
md.setSynopsis(True)
|
||||
md.setCommentType(nwComment.SYNOPSIS, True)
|
||||
md._text = "%synopsis: The synopsis ...\n"
|
||||
md.tokenizeText()
|
||||
md.doConvert()
|
||||
assert md._pages[-1] == "**Synopsis:** The synopsis ...\n\n"
|
||||
|
||||
md.setSynopsis(True)
|
||||
md.setCommentType(nwComment.SHORT, True)
|
||||
md._text = "%short: A description ...\n"
|
||||
md.tokenizeText()
|
||||
md.doConvert()
|
||||
@@ -166,7 +167,7 @@ def testFmtToMarkdown_ConvertParagraphs(mockGUI):
|
||||
md.doConvert()
|
||||
assert md._pages[-1] == ""
|
||||
|
||||
md.setComments(True)
|
||||
md.setCommentType(nwComment.PLAIN, True)
|
||||
md._text = "% A comment ...\n"
|
||||
md.tokenizeText()
|
||||
md.doConvert()
|
||||
|
||||
@@ -32,6 +32,7 @@ from PyQt6.QtGui import QColor
|
||||
from novelwriter.common import xmlIndent
|
||||
from novelwriter.constants import nwHeadFmt
|
||||
from novelwriter.core.project import NWProject
|
||||
from novelwriter.enum import nwComment
|
||||
from novelwriter.formats.shared import BlockFmt, BlockTyp, TextFmt
|
||||
from novelwriter.formats.toodt import ODTParagraphStyle, ODTTextStyle, ToOdt, XMLParagraph, _mkTag
|
||||
|
||||
@@ -611,8 +612,9 @@ def testFmtToOdt_ConvertParagraphs(mockGUI):
|
||||
"% short: Then what\n\n"
|
||||
"% A plain comment\n\n"
|
||||
)
|
||||
odt.setSynopsis(True)
|
||||
odt.setComments(True)
|
||||
odt.setCommentType(nwComment.SYNOPSIS, True)
|
||||
odt.setCommentType(nwComment.SHORT, True)
|
||||
odt.setCommentType(nwComment.PLAIN, True)
|
||||
odt.setKeywords(True)
|
||||
odt.tokenizeText()
|
||||
odt.initDocument()
|
||||
|
||||
@@ -27,6 +27,7 @@ from PyQt6.QtGui import QFont, QTextBlock, QTextCharFormat, QTextCursor
|
||||
from novelwriter import CONFIG
|
||||
from novelwriter.constants import nwUnicode
|
||||
from novelwriter.core.project import NWProject
|
||||
from novelwriter.enum import nwComment
|
||||
from novelwriter.formats.shared import BlockFmt, BlockTyp, TextDocumentTheme
|
||||
from novelwriter.formats.toqdoc import ToQTextDocument
|
||||
from novelwriter.types import (
|
||||
@@ -195,8 +196,8 @@ def testFmtToQTextDocument_NovelMeta(mockGUI):
|
||||
|
||||
doc._isNovel = True
|
||||
doc._isFirst = True
|
||||
doc.setComments(True)
|
||||
doc.setSynopsis(True)
|
||||
doc.setCommentType(nwComment.PLAIN, True)
|
||||
doc.setCommentType(nwComment.SYNOPSIS, True)
|
||||
doc.setKeywords(True)
|
||||
doc._text = (
|
||||
"### Scene\n\n"
|
||||
@@ -272,8 +273,8 @@ def testFmtToQTextDocument_NoteMeta(mockGUI):
|
||||
|
||||
doc._isNovel = False
|
||||
doc._isFirst = True
|
||||
doc.setComments(True)
|
||||
doc.setSynopsis(True)
|
||||
doc.setCommentType(nwComment.PLAIN, True)
|
||||
doc.setCommentType(nwComment.SHORT, True)
|
||||
doc.setKeywords(True)
|
||||
doc._text = (
|
||||
"# Jane Smith\n\n"
|
||||
|
||||
Reference in New Issue
Block a user