Pass the Markdown style to the constructor
This commit is contained in:
@@ -149,26 +149,35 @@ class NWBuildDocument:
|
||||
|
||||
def iterBuildDocument(self, path: Path, bFormat: nwBuildFmt) -> Iterable[tuple[int, bool]]:
|
||||
"""Wrapper for builders based on format."""
|
||||
if bFormat in (nwBuildFmt.J_HTML, nwBuildFmt.J_NWD):
|
||||
# Ensure that JSON output has the correct extension
|
||||
path = path.with_suffix(".json")
|
||||
|
||||
if bFormat in (nwBuildFmt.ODT, nwBuildFmt.FODT):
|
||||
makeObj = ToOdt(self._project, bFormat == nwBuildFmt.FODT)
|
||||
filtered = self._setupBuild(makeObj)
|
||||
makeObj.initDocument()
|
||||
|
||||
yield from self._iterBuild(makeObj, filtered)
|
||||
|
||||
makeObj.closeDocument()
|
||||
|
||||
elif bFormat in (nwBuildFmt.HTML, nwBuildFmt.J_HTML):
|
||||
makeObj = ToHtml(self._project)
|
||||
filtered = self._setupBuild(makeObj)
|
||||
|
||||
yield from self._iterBuild(makeObj, filtered)
|
||||
|
||||
makeObj.appendFootnotes()
|
||||
if not self._build.getBool("html.preserveTabs"):
|
||||
makeObj.replaceTabs()
|
||||
|
||||
elif bFormat in (nwBuildFmt.STD_MD, nwBuildFmt.EXT_MD):
|
||||
makeObj = ToMarkdown(self._project)
|
||||
makeObj.setExtendedMarkdown(bFormat == nwBuildFmt.EXT_MD)
|
||||
makeObj = ToMarkdown(self._project, bFormat == nwBuildFmt.EXT_MD)
|
||||
filtered = self._setupBuild(makeObj)
|
||||
|
||||
yield from self._iterBuild(makeObj, filtered)
|
||||
|
||||
makeObj.appendFootnotes()
|
||||
if self._build.getBool("format.replaceTabs"):
|
||||
makeObj.replaceTabs(nSpaces=4, spaceChar=" ")
|
||||
@@ -176,7 +185,9 @@ class NWBuildDocument:
|
||||
elif bFormat in (nwBuildFmt.NWD, nwBuildFmt.J_NWD):
|
||||
makeObj = ToRaw(self._project)
|
||||
filtered = self._setupBuild(makeObj)
|
||||
|
||||
yield from self._iterBuild(makeObj, filtered)
|
||||
|
||||
if self._build.getBool("format.replaceTabs"):
|
||||
makeObj.replaceTabs(nSpaces=4, spaceChar=" ")
|
||||
|
||||
|
||||
@@ -81,11 +81,11 @@ class ToMarkdown(Tokenizer):
|
||||
supports concatenating novelWriter markup files.
|
||||
"""
|
||||
|
||||
def __init__(self, project: NWProject) -> None:
|
||||
def __init__(self, project: NWProject, extended: bool) -> None:
|
||||
super().__init__(project)
|
||||
self._fullMD: list[str] = []
|
||||
self._usedNotes: dict[str, int] = {}
|
||||
self._extended = True
|
||||
self._extended = extended
|
||||
return
|
||||
|
||||
##
|
||||
@@ -97,15 +97,6 @@ class ToMarkdown(Tokenizer):
|
||||
"""Return the markdown as a list."""
|
||||
return self._fullMD
|
||||
|
||||
##
|
||||
# Setters
|
||||
##
|
||||
|
||||
def setExtendedMarkdown(self, state: bool) -> None:
|
||||
"""Set the converter to use Extended Markdown formatting."""
|
||||
self._extended = state
|
||||
return
|
||||
|
||||
##
|
||||
# Class Methods
|
||||
##
|
||||
|
||||
@@ -1887,7 +1887,7 @@ def testFmtToken_SceneSeparators(mockGUI):
|
||||
project = NWProject()
|
||||
project.data.setLanguage("en")
|
||||
project._loadProjectLocalisation()
|
||||
md = ToMarkdown(project)
|
||||
md = ToMarkdown(project, False)
|
||||
md._isNovel = True
|
||||
|
||||
# Separator Handling, Titles
|
||||
@@ -2002,8 +2002,7 @@ def testFmtToken_SceneSeparators(mockGUI):
|
||||
# Separators with Scenes Only
|
||||
# ===========================
|
||||
# Requires a fresh builder class
|
||||
md = ToMarkdown(project)
|
||||
md.setExtendedMarkdown(True)
|
||||
md = ToMarkdown(project, True)
|
||||
md._isNovel = True
|
||||
|
||||
md._text = (
|
||||
@@ -2038,7 +2037,7 @@ def testFmtToken_HeaderVisibility(mockGUI):
|
||||
project = NWProject()
|
||||
project.data.setLanguage("en")
|
||||
project._loadProjectLocalisation()
|
||||
md = ToMarkdown(project)
|
||||
md = ToMarkdown(project, False)
|
||||
|
||||
md._text = (
|
||||
"#! Novel\n\n"
|
||||
@@ -2150,7 +2149,7 @@ def testFmtToken_CounterHandling(mockGUI):
|
||||
project = NWProject()
|
||||
project.data.setLanguage("en")
|
||||
project._loadProjectLocalisation()
|
||||
md = ToMarkdown(project)
|
||||
md = ToMarkdown(project, False)
|
||||
md._isNovel = True
|
||||
|
||||
# Counter Handling, Novel Titles
|
||||
|
||||
@@ -30,7 +30,7 @@ from novelwriter.formats.tomarkdown import ToMarkdown
|
||||
def testFmtToMarkdown_ConvertHeaders(mockGUI):
|
||||
"""Test header formats in the ToMarkdown class."""
|
||||
project = NWProject()
|
||||
toMD = ToMarkdown(project)
|
||||
toMD = ToMarkdown(project, False)
|
||||
|
||||
toMD._isNovel = True
|
||||
toMD._isFirst = True
|
||||
@@ -76,13 +76,13 @@ def testFmtToMarkdown_ConvertHeaders(mockGUI):
|
||||
def testFmtToMarkdown_ConvertParagraphs(mockGUI):
|
||||
"""Test paragraph formats in the ToMarkdown class."""
|
||||
project = NWProject()
|
||||
toMD = ToMarkdown(project)
|
||||
toMD = ToMarkdown(project, False)
|
||||
|
||||
toMD._isNovel = True
|
||||
toMD._isFirst = True
|
||||
|
||||
# Text for Extended Markdown
|
||||
toMD.setExtendedMarkdown(True)
|
||||
toMD._extended = True
|
||||
toMD._text = "Some **nested bold and _italic_ and ~~strikethrough~~ text** here\n"
|
||||
toMD.tokenizeText()
|
||||
toMD.doConvert()
|
||||
@@ -91,7 +91,7 @@ def testFmtToMarkdown_ConvertParagraphs(mockGUI):
|
||||
)
|
||||
|
||||
# Text for Standard Markdown
|
||||
toMD.setExtendedMarkdown(False)
|
||||
toMD._extended = False
|
||||
toMD._text = "Some **nested bold and _italic_ and ~~strikethrough~~ text** here\n"
|
||||
toMD.tokenizeText()
|
||||
toMD.doConvert()
|
||||
@@ -100,7 +100,7 @@ def testFmtToMarkdown_ConvertParagraphs(mockGUI):
|
||||
)
|
||||
|
||||
# Shortcodes for Extended Markdown
|
||||
toMD.setExtendedMarkdown(True)
|
||||
toMD._extended = True
|
||||
toMD._text = (
|
||||
"Some [b]bold[/b], [i]italic[/i], [s]strike[/s], [u]underline[/u], [m]mark[/m], "
|
||||
"super[sup]script[/sup], sub[sub]script[/sub] here\n"
|
||||
@@ -113,7 +113,7 @@ def testFmtToMarkdown_ConvertParagraphs(mockGUI):
|
||||
)
|
||||
|
||||
# Shortcodes for Standard Markdown
|
||||
toMD.setExtendedMarkdown(False)
|
||||
toMD._extended = False
|
||||
toMD._text = (
|
||||
"Some [b]bold[/b], [i]italic[/i], [s]strike[/s], [u]underline[/u], [m]mark[/m], "
|
||||
"super[sup]script[/sup], sub[sub]script[/sub] here\n"
|
||||
@@ -212,10 +212,8 @@ def testFmtToMarkdown_ConvertParagraphs(mockGUI):
|
||||
def testFmtToMarkdown_ConvertDirect(mockGUI):
|
||||
"""Test the converter directly using the ToMarkdown class."""
|
||||
project = NWProject()
|
||||
toMD = ToMarkdown(project)
|
||||
|
||||
toMD = ToMarkdown(project, False)
|
||||
toMD._isNovel = True
|
||||
toMD.setExtendedMarkdown(False)
|
||||
|
||||
# Special Titles
|
||||
# ==============
|
||||
@@ -249,7 +247,7 @@ def testFmtToMarkdown_ConvertDirect(mockGUI):
|
||||
def testFmtToMarkdown_Save(mockGUI, fncPath):
|
||||
"""Test the save method of the ToMarkdown class."""
|
||||
project = NWProject()
|
||||
toMD = ToMarkdown(project)
|
||||
toMD = ToMarkdown(project, False)
|
||||
toMD._isNovel = True
|
||||
|
||||
# Build Project
|
||||
@@ -300,7 +298,7 @@ def testFmtToMarkdown_Save(mockGUI, fncPath):
|
||||
def testFmtToMarkdown_Format(mockGUI):
|
||||
"""Test all the formatters for the ToMarkdown class."""
|
||||
project = NWProject()
|
||||
toMD = ToMarkdown(project)
|
||||
toMD = ToMarkdown(project, False)
|
||||
|
||||
assert toMD._formatKeywords("", toMD.A_NONE) == ""
|
||||
assert toMD._formatKeywords("tag: Jane", toMD.A_NONE) == "**Tag:** Jane\n\n"
|
||||
|
||||
Reference in New Issue
Block a user