Fix formatting of line breaks in headers
This commit is contained in:
@@ -257,6 +257,7 @@ class nwLabels:
|
|||||||
|
|
||||||
class nwHeadFmt:
|
class nwHeadFmt:
|
||||||
|
|
||||||
|
BR = "{BR}"
|
||||||
TITLE = "{Title}"
|
TITLE = "{Title}"
|
||||||
CH_NUM = "{Chapter}"
|
CH_NUM = "{Chapter}"
|
||||||
CH_WORD = "{Chapter:Word}"
|
CH_WORD = "{Chapter:Word}"
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ from pathlib import Path
|
|||||||
|
|
||||||
from novelwriter import CONFIG
|
from novelwriter import CONFIG
|
||||||
from novelwriter.common import formatTimeStamp
|
from novelwriter.common import formatTimeStamp
|
||||||
from novelwriter.constants import nwKeyWords, nwLabels, nwHtmlUnicode
|
from novelwriter.constants import nwHeadFmt, nwKeyWords, nwLabels, nwHtmlUnicode
|
||||||
from novelwriter.core.project import NWProject
|
from novelwriter.core.project import NWProject
|
||||||
from novelwriter.core.tokenizer import Tokenizer, stripEscape
|
from novelwriter.core.tokenizer import Tokenizer, stripEscape
|
||||||
|
|
||||||
@@ -244,27 +244,27 @@ class ToHtml(Tokenizer):
|
|||||||
parStyle = None
|
parStyle = None
|
||||||
|
|
||||||
elif tType == self.T_TITLE:
|
elif tType == self.T_TITLE:
|
||||||
tHead = tText.replace(r"\\", "<br/>")
|
tHead = tText.replace(nwHeadFmt.BR, "<br/>")
|
||||||
tmpResult.append(f"<h1 class='title'{hStyle}>{aNm}{tHead}</h1>\n")
|
tmpResult.append(f"<h1 class='title'{hStyle}>{aNm}{tHead}</h1>\n")
|
||||||
|
|
||||||
elif tType == self.T_UNNUM:
|
elif tType == self.T_UNNUM:
|
||||||
tHead = tText.replace(r"\\", "<br/>")
|
tHead = tText.replace(nwHeadFmt.BR, "<br/>")
|
||||||
tmpResult.append(f"<{h2}{hStyle}>{aNm}{tHead}</{h2}>\n")
|
tmpResult.append(f"<{h2}{hStyle}>{aNm}{tHead}</{h2}>\n")
|
||||||
|
|
||||||
elif tType == self.T_HEAD1:
|
elif tType == self.T_HEAD1:
|
||||||
tHead = tText.replace(r"\\", "<br/>")
|
tHead = tText.replace(nwHeadFmt.BR, "<br/>")
|
||||||
tmpResult.append(f"<{h1}{h1Cl}{hStyle}>{aNm}{tHead}</{h1}>\n")
|
tmpResult.append(f"<{h1}{h1Cl}{hStyle}>{aNm}{tHead}</{h1}>\n")
|
||||||
|
|
||||||
elif tType == self.T_HEAD2:
|
elif tType == self.T_HEAD2:
|
||||||
tHead = tText.replace(r"\\", "<br/>")
|
tHead = tText.replace(nwHeadFmt.BR, "<br/>")
|
||||||
tmpResult.append(f"<{h2}{hStyle}>{aNm}{tHead}</{h2}>\n")
|
tmpResult.append(f"<{h2}{hStyle}>{aNm}{tHead}</{h2}>\n")
|
||||||
|
|
||||||
elif tType == self.T_HEAD3:
|
elif tType == self.T_HEAD3:
|
||||||
tHead = tText.replace(r"\\", "<br/>")
|
tHead = tText.replace(nwHeadFmt.BR, "<br/>")
|
||||||
tmpResult.append(f"<{h3}{hStyle}>{aNm}{tHead}</{h3}>\n")
|
tmpResult.append(f"<{h3}{hStyle}>{aNm}{tHead}</{h3}>\n")
|
||||||
|
|
||||||
elif tType == self.T_HEAD4:
|
elif tType == self.T_HEAD4:
|
||||||
tHead = tText.replace(r"\\", "<br/>")
|
tHead = tText.replace(nwHeadFmt.BR, "<br/>")
|
||||||
tmpResult.append(f"<{h4}{hStyle}>{aNm}{tHead}</{h4}>\n")
|
tmpResult.append(f"<{h4}{hStyle}>{aNm}{tHead}</{h4}>\n")
|
||||||
|
|
||||||
elif tType == self.T_SEP:
|
elif tType == self.T_SEP:
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ import logging
|
|||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from novelwriter.constants import nwLabels
|
from novelwriter.constants import nwHeadFmt, nwLabels
|
||||||
from novelwriter.core.project import NWProject
|
from novelwriter.core.project import NWProject
|
||||||
from novelwriter.core.tokenizer import Tokenizer
|
from novelwriter.core.tokenizer import Tokenizer
|
||||||
|
|
||||||
@@ -122,27 +122,27 @@ class ToMarkdown(Tokenizer):
|
|||||||
thisPar = []
|
thisPar = []
|
||||||
|
|
||||||
elif tType == self.T_TITLE:
|
elif tType == self.T_TITLE:
|
||||||
tHead = tText.replace(r"\\", "\n")
|
tHead = tText.replace(nwHeadFmt.BR, "\n")
|
||||||
tmpResult.append(f"# {tHead}\n\n")
|
tmpResult.append(f"# {tHead}\n\n")
|
||||||
|
|
||||||
elif tType == self.T_UNNUM:
|
elif tType == self.T_UNNUM:
|
||||||
tHead = tText.replace(r"\\", "\n")
|
tHead = tText.replace(nwHeadFmt.BR, "\n")
|
||||||
tmpResult.append(f"## {tHead}\n\n")
|
tmpResult.append(f"## {tHead}\n\n")
|
||||||
|
|
||||||
elif tType == self.T_HEAD1:
|
elif tType == self.T_HEAD1:
|
||||||
tHead = tText.replace(r"\\", "\n")
|
tHead = tText.replace(nwHeadFmt.BR, "\n")
|
||||||
tmpResult.append(f"# {tHead}\n\n")
|
tmpResult.append(f"# {tHead}\n\n")
|
||||||
|
|
||||||
elif tType == self.T_HEAD2:
|
elif tType == self.T_HEAD2:
|
||||||
tHead = tText.replace(r"\\", "\n")
|
tHead = tText.replace(nwHeadFmt.BR, "\n")
|
||||||
tmpResult.append(f"## {tHead}\n\n")
|
tmpResult.append(f"## {tHead}\n\n")
|
||||||
|
|
||||||
elif tType == self.T_HEAD3:
|
elif tType == self.T_HEAD3:
|
||||||
tHead = tText.replace(r"\\", "\n")
|
tHead = tText.replace(nwHeadFmt.BR, "\n")
|
||||||
tmpResult.append(f"### {tHead}\n\n")
|
tmpResult.append(f"### {tHead}\n\n")
|
||||||
|
|
||||||
elif tType == self.T_HEAD4:
|
elif tType == self.T_HEAD4:
|
||||||
tHead = tText.replace(r"\\", "\n")
|
tHead = tText.replace(nwHeadFmt.BR, "\n")
|
||||||
tmpResult.append(f"#### {tHead}\n\n")
|
tmpResult.append(f"#### {tHead}\n\n")
|
||||||
|
|
||||||
elif tType == self.T_SEP:
|
elif tType == self.T_SEP:
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ from datetime import datetime
|
|||||||
|
|
||||||
from novelwriter import __version__
|
from novelwriter import __version__
|
||||||
from novelwriter.common import xmlIndent
|
from novelwriter.common import xmlIndent
|
||||||
from novelwriter.constants import nwKeyWords, nwLabels
|
from novelwriter.constants import nwHeadFmt, nwKeyWords, nwLabels
|
||||||
from novelwriter.core.project import NWProject
|
from novelwriter.core.project import NWProject
|
||||||
from novelwriter.core.tokenizer import Tokenizer, stripEscape
|
from novelwriter.core.tokenizer import Tokenizer, stripEscape
|
||||||
|
|
||||||
@@ -445,27 +445,27 @@ class ToOdt(Tokenizer):
|
|||||||
parStyle = None
|
parStyle = None
|
||||||
|
|
||||||
elif tType == self.T_TITLE:
|
elif tType == self.T_TITLE:
|
||||||
tHead = tText.replace(r"\\", "\n")
|
tHead = tText.replace(nwHeadFmt.BR, "\n")
|
||||||
self._addTextPar("Title", oStyle, tHead, isHead=False) # Title must be text:p
|
self._addTextPar("Title", oStyle, tHead, isHead=False) # Title must be text:p
|
||||||
|
|
||||||
elif tType == self.T_UNNUM:
|
elif tType == self.T_UNNUM:
|
||||||
tHead = tText.replace(r"\\", "\n")
|
tHead = tText.replace(nwHeadFmt.BR, "\n")
|
||||||
self._addTextPar("Heading_20_2", oStyle, tHead, isHead=True, oLevel="2")
|
self._addTextPar("Heading_20_2", oStyle, tHead, isHead=True, oLevel="2")
|
||||||
|
|
||||||
elif tType == self.T_HEAD1:
|
elif tType == self.T_HEAD1:
|
||||||
tHead = tText.replace(r"\\", "\n")
|
tHead = tText.replace(nwHeadFmt.BR, "\n")
|
||||||
self._addTextPar("Heading_20_1", oStyle, tHead, isHead=True, oLevel="1")
|
self._addTextPar("Heading_20_1", oStyle, tHead, isHead=True, oLevel="1")
|
||||||
|
|
||||||
elif tType == self.T_HEAD2:
|
elif tType == self.T_HEAD2:
|
||||||
tHead = tText.replace(r"\\", "\n")
|
tHead = tText.replace(nwHeadFmt.BR, "\n")
|
||||||
self._addTextPar("Heading_20_2", oStyle, tHead, isHead=True, oLevel="2")
|
self._addTextPar("Heading_20_2", oStyle, tHead, isHead=True, oLevel="2")
|
||||||
|
|
||||||
elif tType == self.T_HEAD3:
|
elif tType == self.T_HEAD3:
|
||||||
tHead = tText.replace(r"\\", "\n")
|
tHead = tText.replace(nwHeadFmt.BR, "\n")
|
||||||
self._addTextPar("Heading_20_3", oStyle, tHead, isHead=True, oLevel="3")
|
self._addTextPar("Heading_20_3", oStyle, tHead, isHead=True, oLevel="3")
|
||||||
|
|
||||||
elif tType == self.T_HEAD4:
|
elif tType == self.T_HEAD4:
|
||||||
tHead = tText.replace(r"\\", "\n")
|
tHead = tText.replace(nwHeadFmt.BR, "\n")
|
||||||
self._addTextPar("Heading_20_4", oStyle, tHead, isHead=True, oLevel="4")
|
self._addTextPar("Heading_20_4", oStyle, tHead, isHead=True, oLevel="4")
|
||||||
|
|
||||||
elif tType == self.T_SEP:
|
elif tType == self.T_SEP:
|
||||||
|
|||||||
@@ -822,7 +822,7 @@ class _HeadingsTab(QWidget):
|
|||||||
text = ""
|
text = ""
|
||||||
label = self.tr("None")
|
label = self.tr("None")
|
||||||
|
|
||||||
self.editTextBox.setPlainText(text.replace("//", "\n"))
|
self.editTextBox.setPlainText(text.replace(nwHeadFmt.BR, "\n"))
|
||||||
self.lblEditForm.setText(self.tr("Editing: {0}").format(label))
|
self.lblEditForm.setText(self.tr("Editing: {0}").format(label))
|
||||||
|
|
||||||
return
|
return
|
||||||
@@ -834,7 +834,7 @@ class _HeadingsTab(QWidget):
|
|||||||
def _saveFormat(self) -> None:
|
def _saveFormat(self) -> None:
|
||||||
"""Save the format from the edit text box."""
|
"""Save the format from the edit text box."""
|
||||||
heading = self._editing
|
heading = self._editing
|
||||||
text = self.editTextBox.toPlainText().strip().replace("\n", "//")
|
text = self.editTextBox.toPlainText().strip().replace("\n", nwHeadFmt.BR)
|
||||||
if heading == self.EDIT_TITLE:
|
if heading == self.EDIT_TITLE:
|
||||||
self.fmtTitle.setText(text)
|
self.fmtTitle.setText(text)
|
||||||
self._build.setValue("headings.fmtTitle", text)
|
self._build.setValue("headings.fmtTitle", text)
|
||||||
|
|||||||
@@ -429,7 +429,9 @@ def testBuildSettings_Headings(qtbot: QtBot, nwGUI: GuiMain):
|
|||||||
headTab.btnChapter.click()
|
headTab.btnChapter.click()
|
||||||
headTab.editTextBox.setPlainText(f"Chapter {nwHeadFmt.CH_NUM}\n{nwHeadFmt.TITLE}\n")
|
headTab.editTextBox.setPlainText(f"Chapter {nwHeadFmt.CH_NUM}\n{nwHeadFmt.TITLE}\n")
|
||||||
headTab.btnApply.click()
|
headTab.btnApply.click()
|
||||||
assert build.getStr("headings.fmtChapter") == f"Chapter {nwHeadFmt.CH_NUM}//{nwHeadFmt.TITLE}"
|
assert build.getStr("headings.fmtChapter") == (
|
||||||
|
f"Chapter {nwHeadFmt.CH_NUM}{nwHeadFmt.BR}{nwHeadFmt.TITLE}"
|
||||||
|
)
|
||||||
|
|
||||||
# Set all to plain title
|
# Set all to plain title
|
||||||
headTab.btnTitle.click()
|
headTab.btnTitle.click()
|
||||||
|
|||||||
Reference in New Issue
Block a user