Use the old converter for nwd file, not the markdown class
This commit is contained in:
@@ -628,6 +628,14 @@ class Tokenizer():
|
||||
|
||||
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
|
||||
##
|
||||
|
||||
+5
-29
@@ -35,7 +35,6 @@ class ToMarkdown(Tokenizer):
|
||||
|
||||
M_STD = 0 # Standard Markdown
|
||||
M_GH = 1 # GitHub Markdown
|
||||
M_NW = 2 # novelWriter Markdown
|
||||
|
||||
def __init__(self, theProject, theParent):
|
||||
Tokenizer.__init__(self, theProject, theParent)
|
||||
@@ -57,10 +56,6 @@ class ToMarkdown(Tokenizer):
|
||||
self.genMode = self.M_GH
|
||||
return
|
||||
|
||||
def setNovelWriterMarkdown(self):
|
||||
self.genMode = self.M_NW
|
||||
return
|
||||
|
||||
##
|
||||
# Class Methods
|
||||
##
|
||||
@@ -139,10 +134,10 @@ class ToMarkdown(Tokenizer):
|
||||
thisPar.append(tTemp.rstrip() + " ")
|
||||
|
||||
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:
|
||||
tmpResult.append(self._formatComments(tText))
|
||||
tmpResult.append("**Comment:** %s\n\n" % tText)
|
||||
|
||||
elif tType == self.T_KEYWORD and self.doKeywords:
|
||||
tmpResult.append(self._formatKeywords(tText, tStyle))
|
||||
@@ -155,7 +150,7 @@ class ToMarkdown(Tokenizer):
|
||||
return
|
||||
|
||||
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:
|
||||
theText = "".join(self.fullMD)
|
||||
@@ -178,22 +173,6 @@ class ToMarkdown(Tokenizer):
|
||||
# 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):
|
||||
"""Apply Markdown formatting to keywords.
|
||||
"""
|
||||
@@ -203,15 +182,12 @@ class ToMarkdown(Tokenizer):
|
||||
|
||||
retText = ""
|
||||
if theBits[0] in nwLabels.KEY_NAME:
|
||||
if self.genMode == self.M_NW:
|
||||
retText += "%s: " % theBits[0]
|
||||
else:
|
||||
retText += "**%s:** " % nwLabels.KEY_NAME[theBits[0]]
|
||||
retText += "**%s:** " % nwLabels.KEY_NAME[theBits[0]]
|
||||
|
||||
if len(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"
|
||||
else:
|
||||
retText += "\n\n"
|
||||
|
||||
+15
-5
@@ -623,7 +623,6 @@ class GuiBuildNovel(QDialog):
|
||||
|
||||
isHtml = isinstance(bldObj, ToHtml)
|
||||
isOdt = isinstance(bldObj, ToOdt)
|
||||
# isMd = isinstance(bldObj, ToMarkdown)
|
||||
|
||||
bldObj.setTitleFormat(fmtTitle)
|
||||
bldObj.setChapterFormat(fmtChapter)
|
||||
@@ -849,11 +848,22 @@ class GuiBuildNovel(QDialog):
|
||||
except Exception as 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)
|
||||
if theFmt == self.FMT_NWD:
|
||||
makeMd.setNovelWriterMarkdown()
|
||||
elif theFmt == self.FMT_GH:
|
||||
if theFmt == self.FMT_GH:
|
||||
makeMd.setGitHubMarkdown()
|
||||
else:
|
||||
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/>.
|
||||
"""
|
||||
|
||||
import os
|
||||
import pytest
|
||||
|
||||
from tools import readFile
|
||||
|
||||
from nw.core import NWProject, NWDoc
|
||||
from nw.core.tokenizer import Tokenizer
|
||||
|
||||
@@ -182,6 +185,11 @@ def testCoreToken_TextOps(monkeypatch, nwMinimal, dummyGUI):
|
||||
theToken.doPostProcessing()
|
||||
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
|
||||
|
||||
@pytest.mark.core
|
||||
@@ -397,11 +405,6 @@ def testCoreToken_Tokenize(dummyGUI):
|
||||
"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
|
||||
|
||||
@pytest.mark.core
|
||||
|
||||
Reference in New Issue
Block a user