Fix a few issues with markdown export
This commit is contained in:
@@ -168,6 +168,7 @@ class ToHtml(Tokenizer):
|
|||||||
parStyle = None
|
parStyle = None
|
||||||
tmpResult = []
|
tmpResult = []
|
||||||
hasHardBreak = False
|
hasHardBreak = False
|
||||||
|
|
||||||
for tType, tLine, tText, tFormat, tStyle in self.theTokens:
|
for tType, tLine, tText, tFormat, tStyle in self.theTokens:
|
||||||
|
|
||||||
# Styles
|
# Styles
|
||||||
|
|||||||
+20
-16
@@ -58,7 +58,7 @@ class ToMarkdown(Tokenizer):
|
|||||||
return
|
return
|
||||||
|
|
||||||
def setNovelWriterMarkdown(self):
|
def setNovelWriterMarkdown(self):
|
||||||
self.genMode = self.M_MD
|
self.genMode = self.M_NW
|
||||||
return
|
return
|
||||||
|
|
||||||
##
|
##
|
||||||
@@ -100,29 +100,28 @@ class ToMarkdown(Tokenizer):
|
|||||||
if tType == self.T_EMPTY:
|
if tType == self.T_EMPTY:
|
||||||
if len(thisPar) > 0:
|
if len(thisPar) > 0:
|
||||||
tTemp = "".join(thisPar)
|
tTemp = "".join(thisPar)
|
||||||
tmpResult.append("%s\n" % tTemp)
|
tmpResult.append("%s\n\n" % tTemp.rstrip(" "))
|
||||||
|
|
||||||
thisPar = []
|
thisPar = []
|
||||||
|
|
||||||
elif tType == self.T_TITLE:
|
elif tType == self.T_TITLE:
|
||||||
tHead = tText.replace(r"\\", "\n")
|
tHead = tText.replace(r"\\", "\n")
|
||||||
tmpResult.append("# %s\n" % tHead)
|
tmpResult.append("# %s\n\n" % tHead)
|
||||||
|
|
||||||
elif tType == self.T_HEAD1:
|
elif tType == self.T_HEAD1:
|
||||||
tHead = tText.replace(r"\\", "\n")
|
tHead = tText.replace(r"\\", "\n")
|
||||||
tmpResult.append("# %s\n" % tHead)
|
tmpResult.append("# %s\n\n" % tHead)
|
||||||
|
|
||||||
elif tType == self.T_HEAD2:
|
elif tType == self.T_HEAD2:
|
||||||
tHead = tText.replace(r"\\", "\n")
|
tHead = tText.replace(r"\\", "\n")
|
||||||
tmpResult.append("## %s\n" % tHead)
|
tmpResult.append("## %s\n\n" % tHead)
|
||||||
|
|
||||||
elif tType == self.T_HEAD3:
|
elif tType == self.T_HEAD3:
|
||||||
tHead = tText.replace(r"\\", "\n")
|
tHead = tText.replace(r"\\", "\n")
|
||||||
tmpResult.append("### %s\n" % tHead)
|
tmpResult.append("### %s\n\n" % tHead)
|
||||||
|
|
||||||
elif tType == self.T_HEAD4:
|
elif tType == self.T_HEAD4:
|
||||||
tHead = tText.replace(r"\\", "\n")
|
tHead = tText.replace(r"\\", "\n")
|
||||||
tmpResult.append("#### %s\n" % tHead)
|
tmpResult.append("#### %s\n\n" % tHead)
|
||||||
|
|
||||||
elif tType == self.T_SEP:
|
elif tType == self.T_SEP:
|
||||||
tmpResult.append("%s\n\n" % tText)
|
tmpResult.append("%s\n\n" % tText)
|
||||||
@@ -135,7 +134,7 @@ class ToMarkdown(Tokenizer):
|
|||||||
for xPos, xLen, xFmt in reversed(tFormat):
|
for xPos, xLen, xFmt in reversed(tFormat):
|
||||||
tTemp = tTemp[:xPos] + mdTags[xFmt] + tTemp[xPos+xLen:]
|
tTemp = tTemp[:xPos] + mdTags[xFmt] + tTemp[xPos+xLen:]
|
||||||
if tText.endswith(" "):
|
if tText.endswith(" "):
|
||||||
thisPar.append(tTemp.rstrip() + " ")
|
thisPar.append(tTemp.rstrip() + " \n")
|
||||||
else:
|
else:
|
||||||
thisPar.append(tTemp.rstrip() + " ")
|
thisPar.append(tTemp.rstrip() + " ")
|
||||||
|
|
||||||
@@ -146,7 +145,7 @@ class ToMarkdown(Tokenizer):
|
|||||||
tmpResult.append(self._formatComments(tText))
|
tmpResult.append(self._formatComments(tText))
|
||||||
|
|
||||||
elif tType == self.T_KEYWORD and self.doKeywords:
|
elif tType == self.T_KEYWORD and self.doKeywords:
|
||||||
tmpResult.append(self._formatKeywords(tText))
|
tmpResult.append(self._formatKeywords(tText, tStyle))
|
||||||
|
|
||||||
self.theResult = "".join(tmpResult)
|
self.theResult = "".join(tmpResult)
|
||||||
tmpResult = []
|
tmpResult = []
|
||||||
@@ -183,19 +182,19 @@ class ToMarkdown(Tokenizer):
|
|||||||
"""Apply Markdown formatting to synopsis.
|
"""Apply Markdown formatting to synopsis.
|
||||||
"""
|
"""
|
||||||
if self.genMode == self.M_NW:
|
if self.genMode == self.M_NW:
|
||||||
return "%% Synopsis: %s\n" % tText
|
return "%% Synopsis: %s\n\n" % tText
|
||||||
else:
|
else:
|
||||||
return "**Synopsis:** %s\n" % tText
|
return "**Synopsis:** %s\n\n" % tText
|
||||||
|
|
||||||
def _formatComments(self, tText):
|
def _formatComments(self, tText):
|
||||||
"""Apply Markdown formatting to comments.
|
"""Apply Markdown formatting to comments.
|
||||||
"""
|
"""
|
||||||
if self.genMode == self.M_NW:
|
if self.genMode == self.M_NW:
|
||||||
return "%% %s\n" % tText
|
return "%% %s\n\n" % tText
|
||||||
else:
|
else:
|
||||||
return "**Comment:** %s\n" % tText
|
return "**Comment:** %s\n\n" % tText
|
||||||
|
|
||||||
def _formatKeywords(self, tText):
|
def _formatKeywords(self, tText, tStyle):
|
||||||
"""Apply Markdown formatting to keywords.
|
"""Apply Markdown formatting to keywords.
|
||||||
"""
|
"""
|
||||||
isValid, theBits, thePos = self.theParent.theIndex.scanThis("@"+tText)
|
isValid, theBits, thePos = self.theParent.theIndex.scanThis("@"+tText)
|
||||||
@@ -205,13 +204,18 @@ 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:
|
if self.genMode == self.M_NW:
|
||||||
retText += "@%s: " % theBits[0]
|
retText += "%s: " % theBits[0]
|
||||||
else:
|
else:
|
||||||
retText += "**%s:** " % nwLabels.KEY_NAME[theBits[0]]
|
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:
|
||||||
|
retText += " \n"
|
||||||
|
else:
|
||||||
|
retText += "\n\n"
|
||||||
|
|
||||||
return retText
|
return retText
|
||||||
|
|
||||||
# END Class ToMarkdown
|
# END Class ToMarkdown
|
||||||
|
|||||||
+2
-2
@@ -854,13 +854,13 @@ class GuiBuildNovel(QDialog):
|
|||||||
if theFmt == self.FMT_NWD:
|
if theFmt == self.FMT_NWD:
|
||||||
makeMd.setNovelWriterMarkdown()
|
makeMd.setNovelWriterMarkdown()
|
||||||
elif theFmt == self.FMT_GH:
|
elif theFmt == self.FMT_GH:
|
||||||
makeMd.setGitHubMarkdown
|
makeMd.setGitHubMarkdown()
|
||||||
else:
|
else:
|
||||||
makeMd.setStandardMarkdown()
|
makeMd.setStandardMarkdown()
|
||||||
|
|
||||||
self._doBuild(makeMd)
|
self._doBuild(makeMd)
|
||||||
if replaceTabs:
|
if replaceTabs:
|
||||||
makeMd.replaceTabs(spaceChar=" ")
|
makeMd.replaceTabs(nSpaces=4, spaceChar=" ")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
makeMd.saveMarkdown(savePath)
|
makeMd.saveMarkdown(savePath)
|
||||||
|
|||||||
Reference in New Issue
Block a user