diff --git a/nw/core/tokenizer.py b/nw/core/tokenizer.py index 2fa784f5..9d820585 100644 --- a/nw/core/tokenizer.py +++ b/nw/core/tokenizer.py @@ -565,11 +565,11 @@ class Tokenizer(): def _formatHeading(self, theTitle, theText): """Replaces the %keyword% strings. """ - theTitle = theTitle.replace(r"%title%", theText) - theTitle = theTitle.replace(r"%chnum%", str(self.numChapter)) - theTitle = theTitle.replace(r"%scnum%", str(self.numChScene)) - theTitle = theTitle.replace(r"%scabsnum%", str(self.numAbsScene)) - theTitle = theTitle.replace(r"%chnumword%", numberToWord(self.numChapter,"en")) + theTitle = theTitle.replace(r"%title%", theText) + theTitle = theTitle.replace(r"%ch%", str(self.numChapter)) + theTitle = theTitle.replace(r"%sc1%", str(self.numChScene)) + theTitle = theTitle.replace(r"%sc2%", str(self.numAbsScene)) + theTitle = theTitle.replace(r"%chword%", numberToWord(self.numChapter,"en")) return theTitle # END Class Tokenizer diff --git a/nw/gui/build.py b/nw/gui/build.py index d5313707..af8f7d9e 100644 --- a/nw/gui/build.py +++ b/nw/gui/build.py @@ -98,27 +98,37 @@ class GuiBuildNovel(QDialog): self.fmtTitle = QLineEdit() self.fmtTitle.setMaxLength(200) self.fmtTitle.setFixedWidth(220) - self.fmtTitle.setText(self.theProject.titleFormat["title"]) + self.fmtTitle.setText( + self._reFmtCodes(self.theProject.titleFormat["title"]) + ) self.fmtChapter = QLineEdit() self.fmtChapter.setMaxLength(200) self.fmtChapter.setFixedWidth(220) - self.fmtChapter.setText(self.theProject.titleFormat["chapter"]) + self.fmtChapter.setText( + self._reFmtCodes(self.theProject.titleFormat["chapter"]) + ) self.fmtUnnumbered = QLineEdit() self.fmtUnnumbered.setMaxLength(200) self.fmtUnnumbered.setFixedWidth(220) - self.fmtUnnumbered.setText(self.theProject.titleFormat["unnumbered"]) + self.fmtUnnumbered.setText( + self._reFmtCodes(self.theProject.titleFormat["unnumbered"]) + ) self.fmtScene = QLineEdit() self.fmtScene.setMaxLength(200) self.fmtScene.setFixedWidth(220) - self.fmtScene.setText(self.theProject.titleFormat["scene"]) + self.fmtScene.setText( + self._reFmtCodes(self.theProject.titleFormat["scene"]) + ) self.fmtSection = QLineEdit() self.fmtSection.setMaxLength(200) self.fmtSection.setFixedWidth(220) - self.fmtSection.setText(self.theProject.titleFormat["section"]) + self.fmtSection.setText( + self._reFmtCodes(self.theProject.titleFormat["section"]) + ) self.titleForm.addWidget(QLabel("Title"), 0, 0, 1, 1, Qt.AlignLeft) self.titleForm.addWidget(self.fmtTitle, 0, 1, 1, 1, Qt.AlignRight) @@ -677,6 +687,15 @@ class GuiBuildNovel(QDialog): ) return + def _reFmtCodes(self, theFormat): + """Translates old formatting codes to new ones. + """ + theFormat = theFormat.replace(r"%chnum%", r"%ch%") + theFormat = theFormat.replace(r"%scnum%", r"%sc1%") + theFormat = theFormat.replace(r"%scabsnum%", r"%sc2%") + theFormat = theFormat.replace(r"%chnumword%", r"%chword%") + return theFormat + # END Class GuiBuildNovel class GuiBuildNovelDocView(QTextBrowser): diff --git a/sample/nwProject.nwx b/sample/nwProject.nwx index ad832035..5e29e0bd 100644 --- a/sample/nwProject.nwx +++ b/sample/nwProject.nwx @@ -1,5 +1,5 @@ - + Sample Project Sample Project @@ -20,7 +20,7 @@ %title% - Chapter %chnum%: %title% + Chapter %ch%: %title% %title% * * *