Use the old converter for nwd file, not the markdown class
This commit is contained in:
@@ -628,6 +628,14 @@ class Tokenizer():
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def saveRawMarkdown(self, savePath):
|
||||||
|
"""Save the data to a plain text file.
|
||||||
|
"""
|
||||||
|
with open(savePath, mode="w", encoding="utf8") as outFile:
|
||||||
|
for nwdPage in self.theMarkdown:
|
||||||
|
outFile.write(nwdPage)
|
||||||
|
return
|
||||||
|
|
||||||
##
|
##
|
||||||
# Internal Functions
|
# Internal Functions
|
||||||
##
|
##
|
||||||
|
|||||||
+5
-29
@@ -35,7 +35,6 @@ class ToMarkdown(Tokenizer):
|
|||||||
|
|
||||||
M_STD = 0 # Standard Markdown
|
M_STD = 0 # Standard Markdown
|
||||||
M_GH = 1 # GitHub Markdown
|
M_GH = 1 # GitHub Markdown
|
||||||
M_NW = 2 # novelWriter Markdown
|
|
||||||
|
|
||||||
def __init__(self, theProject, theParent):
|
def __init__(self, theProject, theParent):
|
||||||
Tokenizer.__init__(self, theProject, theParent)
|
Tokenizer.__init__(self, theProject, theParent)
|
||||||
@@ -57,10 +56,6 @@ class ToMarkdown(Tokenizer):
|
|||||||
self.genMode = self.M_GH
|
self.genMode = self.M_GH
|
||||||
return
|
return
|
||||||
|
|
||||||
def setNovelWriterMarkdown(self):
|
|
||||||
self.genMode = self.M_NW
|
|
||||||
return
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# Class Methods
|
# Class Methods
|
||||||
##
|
##
|
||||||
@@ -139,10 +134,10 @@ class ToMarkdown(Tokenizer):
|
|||||||
thisPar.append(tTemp.rstrip() + " ")
|
thisPar.append(tTemp.rstrip() + " ")
|
||||||
|
|
||||||
elif tType == self.T_SYNOPSIS and self.doSynopsis:
|
elif tType == self.T_SYNOPSIS and self.doSynopsis:
|
||||||
tmpResult.append(self._formatSynopsis(tText))
|
tmpResult.append("**Synopsis:** %s\n\n" % tText)
|
||||||
|
|
||||||
elif tType == self.T_COMMENT and self.doComments:
|
elif tType == self.T_COMMENT and self.doComments:
|
||||||
tmpResult.append(self._formatComments(tText))
|
tmpResult.append("**Comment:** %s\n\n" % tText)
|
||||||
|
|
||||||
elif tType == self.T_KEYWORD and self.doKeywords:
|
elif tType == self.T_KEYWORD and self.doKeywords:
|
||||||
tmpResult.append(self._formatKeywords(tText, tStyle))
|
tmpResult.append(self._formatKeywords(tText, tStyle))
|
||||||
@@ -155,7 +150,7 @@ class ToMarkdown(Tokenizer):
|
|||||||
return
|
return
|
||||||
|
|
||||||
def saveMarkdown(self, savePath):
|
def saveMarkdown(self, savePath):
|
||||||
"""Save the data to a plain text file file.
|
"""Save the data to a plain text file.
|
||||||
"""
|
"""
|
||||||
with open(savePath, mode="w", encoding="utf8") as outFile:
|
with open(savePath, mode="w", encoding="utf8") as outFile:
|
||||||
theText = "".join(self.fullMD)
|
theText = "".join(self.fullMD)
|
||||||
@@ -178,22 +173,6 @@ class ToMarkdown(Tokenizer):
|
|||||||
# Internal Functions
|
# Internal Functions
|
||||||
##
|
##
|
||||||
|
|
||||||
def _formatSynopsis(self, tText):
|
|
||||||
"""Apply Markdown formatting to synopsis.
|
|
||||||
"""
|
|
||||||
if self.genMode == self.M_NW:
|
|
||||||
return "%% Synopsis: %s\n\n" % tText
|
|
||||||
else:
|
|
||||||
return "**Synopsis:** %s\n\n" % tText
|
|
||||||
|
|
||||||
def _formatComments(self, tText):
|
|
||||||
"""Apply Markdown formatting to comments.
|
|
||||||
"""
|
|
||||||
if self.genMode == self.M_NW:
|
|
||||||
return "%% %s\n\n" % tText
|
|
||||||
else:
|
|
||||||
return "**Comment:** %s\n\n" % tText
|
|
||||||
|
|
||||||
def _formatKeywords(self, tText, tStyle):
|
def _formatKeywords(self, tText, tStyle):
|
||||||
"""Apply Markdown formatting to keywords.
|
"""Apply Markdown formatting to keywords.
|
||||||
"""
|
"""
|
||||||
@@ -203,15 +182,12 @@ class ToMarkdown(Tokenizer):
|
|||||||
|
|
||||||
retText = ""
|
retText = ""
|
||||||
if theBits[0] in nwLabels.KEY_NAME:
|
if theBits[0] in nwLabels.KEY_NAME:
|
||||||
if self.genMode == self.M_NW:
|
retText += "**%s:** " % nwLabels.KEY_NAME[theBits[0]]
|
||||||
retText += "%s: " % theBits[0]
|
|
||||||
else:
|
|
||||||
retText += "**%s:** " % nwLabels.KEY_NAME[theBits[0]]
|
|
||||||
|
|
||||||
if len(theBits) > 1:
|
if len(theBits) > 1:
|
||||||
retText += ", ".join(theBits[1:])
|
retText += ", ".join(theBits[1:])
|
||||||
|
|
||||||
if tStyle & self.A_Z_BTMMRG and self.genMode != self.M_NW:
|
if tStyle & self.A_Z_BTMMRG:
|
||||||
retText += " \n"
|
retText += " \n"
|
||||||
else:
|
else:
|
||||||
retText += "\n\n"
|
retText += "\n\n"
|
||||||
|
|||||||
+15
-5
@@ -623,7 +623,6 @@ class GuiBuildNovel(QDialog):
|
|||||||
|
|
||||||
isHtml = isinstance(bldObj, ToHtml)
|
isHtml = isinstance(bldObj, ToHtml)
|
||||||
isOdt = isinstance(bldObj, ToOdt)
|
isOdt = isinstance(bldObj, ToOdt)
|
||||||
# isMd = isinstance(bldObj, ToMarkdown)
|
|
||||||
|
|
||||||
bldObj.setTitleFormat(fmtTitle)
|
bldObj.setTitleFormat(fmtTitle)
|
||||||
bldObj.setChapterFormat(fmtChapter)
|
bldObj.setChapterFormat(fmtChapter)
|
||||||
@@ -849,11 +848,22 @@ class GuiBuildNovel(QDialog):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
errMsg = str(e)
|
errMsg = str(e)
|
||||||
|
|
||||||
elif theFmt in (self.FMT_NWD, self.FMT_MD, self.FMT_GH):
|
elif theFmt == self.FMT_NWD:
|
||||||
|
makeNwd = ToMarkdown(self.theProject, self.theParent)
|
||||||
|
makeNwd.setKeepMarkdown(True)
|
||||||
|
self._doBuild(makeNwd, doConvert=False)
|
||||||
|
if replaceTabs:
|
||||||
|
makeNwd.replaceTabs(spaceChar=" ")
|
||||||
|
|
||||||
|
try:
|
||||||
|
makeNwd.saveRawMarkdown(savePath)
|
||||||
|
wSuccess = True
|
||||||
|
except Exception as e:
|
||||||
|
errMsg = str(e)
|
||||||
|
|
||||||
|
elif theFmt in (self.FMT_MD, self.FMT_GH):
|
||||||
makeMd = ToMarkdown(self.theProject, self.theParent)
|
makeMd = ToMarkdown(self.theProject, self.theParent)
|
||||||
if theFmt == self.FMT_NWD:
|
if theFmt == self.FMT_GH:
|
||||||
makeMd.setNovelWriterMarkdown()
|
|
||||||
elif theFmt == self.FMT_GH:
|
|
||||||
makeMd.setGitHubMarkdown()
|
makeMd.setGitHubMarkdown()
|
||||||
else:
|
else:
|
||||||
makeMd.setStandardMarkdown()
|
makeMd.setStandardMarkdown()
|
||||||
|
|||||||
@@ -20,8 +20,11 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
from tools import readFile
|
||||||
|
|
||||||
from nw.core import NWProject, NWDoc
|
from nw.core import NWProject, NWDoc
|
||||||
from nw.core.tokenizer import Tokenizer
|
from nw.core.tokenizer import Tokenizer
|
||||||
|
|
||||||
@@ -182,6 +185,11 @@ def testCoreToken_TextOps(monkeypatch, nwMinimal, dummyGUI):
|
|||||||
theToken.doPostProcessing()
|
theToken.doPostProcessing()
|
||||||
assert theToken.theResult == "This is text with escapes: ** ~~ __"
|
assert theToken.theResult == "This is text with escapes: ** ~~ __"
|
||||||
|
|
||||||
|
# Save File
|
||||||
|
savePath = os.path.join(nwMinimal, "dump.nwd")
|
||||||
|
theToken.saveRawMarkdown(savePath)
|
||||||
|
assert readFile(savePath) == "# Notes: Plot\n\n"
|
||||||
|
|
||||||
# END Test testCoreToken_TextOps
|
# END Test testCoreToken_TextOps
|
||||||
|
|
||||||
@pytest.mark.core
|
@pytest.mark.core
|
||||||
@@ -397,11 +405,6 @@ def testCoreToken_Tokenize(dummyGUI):
|
|||||||
"Some **nested bold and _italic_ and ~~strikethrough~~ text** here\n\n"
|
"Some **nested bold and _italic_ and ~~strikethrough~~ text** here\n\n"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Check the markdown function as well
|
|
||||||
assert theToken.theMarkdown[-1] == (
|
|
||||||
"Some **nested bold and _italic_ and ~~strikethrough~~ text** here\n\n"
|
|
||||||
)
|
|
||||||
|
|
||||||
# END Test testCoreToken_Tokenize
|
# END Test testCoreToken_Tokenize
|
||||||
|
|
||||||
@pytest.mark.core
|
@pytest.mark.core
|
||||||
|
|||||||
Reference in New Issue
Block a user