From 36ce75e9370e9a288d3c74f67ae0ca5acf5bebe8 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Fri, 1 Nov 2019 17:13:47 +0100 Subject: [PATCH 1/4] Properly export tabs to text and html --- nw/convert/text/tohtml.py | 7 ++++--- nw/convert/text/totext.py | 3 ++- nw/convert/tokenizer.py | 8 ++++---- .../sampleNovel/data_5/3b69b83cdafc_main.nwd | 7 +++++++ .../sampleNovel/data_b/a8a28a246524_main.nwd | 6 +++--- sample/sampleNovel/nwProject.nwx | 20 +++++++++---------- 6 files changed, 30 insertions(+), 21 deletions(-) diff --git a/nw/convert/text/tohtml.py b/nw/convert/text/tohtml.py index 3a67df48..28d09bf3 100644 --- a/nw/convert/text/tohtml.py +++ b/nw/convert/text/tohtml.py @@ -41,9 +41,10 @@ class ToHtml(Tokenizer): Tokenizer.doAutoReplace(self) repDict = { - "<" : "<", - ">" : ">", - "&" : "&", + "<" : "<", + ">" : ">", + "&" : "&", + "\t" : " ", nwUnicode.U_ENDASH : nwUnicode.H_ENDASH, nwUnicode.U_EMDASH : nwUnicode.H_EMDASH, nwUnicode.U_HELLIP : nwUnicode.H_HELLIP, diff --git a/nw/convert/text/totext.py b/nw/convert/text/totext.py index 5b226999..e6073012 100644 --- a/nw/convert/text/totext.py +++ b/nw/convert/text/totext.py @@ -30,6 +30,7 @@ class ToText(Tokenizer): Tokenizer.doAutoReplace(self) repDict = { + "\t" : " ", nwUnicode.U_NBSP : " ", } xRep = re.compile("|".join([re.escape(k) for k in repDict.keys()]), flags=re.DOTALL) @@ -92,7 +93,7 @@ class ToText(Tokenizer): # indicating a new paragraph. if tType == self.T_EMPTY: if len(thisPar) > 0: - tTemp = " ".join(thisPar) + tTemp = "\n".join(thisPar) self.theResult += "%s\n\n" % tTemp.rstrip() thisPar = [] diff --git a/nw/convert/tokenizer.py b/nw/convert/tokenizer.py index 7be25952..81543ad1 100644 --- a/nw/convert/tokenizer.py +++ b/nw/convert/tokenizer.py @@ -62,14 +62,14 @@ class Tokenizer(): self.theTokens = None self.theResult = None - self.wordWrap = 80 + self.wordWrap = 0 self.doComments = False self.doKeywords = False self.fmtTitle = "%title%" - self.fmtChapter = "Chapter %numword%: %title%" + self.fmtChapter = "%title%" self.fmtUnNum = "%title%" - self.fmtScene = "* * *" + self.fmtScene = "%title%" self.fmtSection = "%title%" self.hideScene = False @@ -224,7 +224,7 @@ class Tokenizer(): isScene = self.theItem.itemLayout == nwItemLayout.SCENE isNote = self.theItem.itemLayout == nwItemLayout.NOTE - # No special header formatting for notes and no layout files + # No special header formatting for notes and no-layout files if isNone: return if isNote: return diff --git a/sample/sampleNovel/data_5/3b69b83cdafc_main.nwd b/sample/sampleNovel/data_5/3b69b83cdafc_main.nwd index 9a7abf96..fcd759f0 100644 --- a/sample/sampleNovel/data_5/3b69b83cdafc_main.nwd +++ b/sample/sampleNovel/data_5/3b69b83cdafc_main.nwd @@ -2,3 +2,10 @@ **By Jane Doh** +More Text + +Even More Text + +What is this? + +Where is this? \ No newline at end of file diff --git a/sample/sampleNovel/data_b/a8a28a246524_main.nwd b/sample/sampleNovel/data_b/a8a28a246524_main.nwd index fd3199ca..f6a5d16b 100644 --- a/sample/sampleNovel/data_b/a8a28a246524_main.nwd +++ b/sample/sampleNovel/data_b/a8a28a246524_main.nwd @@ -10,6 +10,6 @@ I understand equations, both the simple and quadratical About binomial theorem I'm teeming with a lot o’ news With many cheerful facts about the square of the hypotenuse -With many cheerful facts about the square of the hypotenuse -With many cheerful facts about the square of the hypotenuse -With many cheerful facts about the square of the hypotepotenuse + With many cheerful facts about the square of the hypotenuse + With many cheerful facts about the square of the hypotenuse + With many cheerful facts about the square of the hypotepotenuse diff --git a/sample/sampleNovel/nwProject.nwx b/sample/sampleNovel/nwProject.nwx index 847d7659..32567aed 100644 --- a/sample/sampleNovel/nwProject.nwx +++ b/sample/sampleNovel/nwProject.nwx @@ -1,5 +1,5 @@ - + Sample Project Sample Project @@ -9,9 +9,9 @@ True - b8136a5a774a0 + 53b69b83cdafc ba8a28a246524 - 884 + 895 B E @@ -48,10 +48,10 @@ Started False TITLE - 23 - 5 - 1 - 16 + 73 + 16 + 5 + 85 Some Chapter @@ -94,7 +94,7 @@ 412 82 2 - 448 + 43 Interlude @@ -103,10 +103,10 @@ Finished False UNNUMBERED - 630 + 633 101 3 - 648 + 164 A Note on Ipsums From f823367917fc7b41d57112d2f77169a8700a894a Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Fri, 1 Nov 2019 18:24:42 +0100 Subject: [PATCH 2/4] Fixed rendering of tabs in the document viewer --- nw/convert/text/tohtml.py | 7 ++++++- nw/gui/elements/docviewer.py | 34 ++++++++++++++++------------------ 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/nw/convert/text/tohtml.py b/nw/convert/text/tohtml.py index 28d09bf3..c8615f75 100644 --- a/nw/convert/text/tohtml.py +++ b/nw/convert/text/tohtml.py @@ -40,11 +40,16 @@ class ToHtml(Tokenizer): def doAutoReplace(self): Tokenizer.doAutoReplace(self) + if self.forPreview: + tabFmt = " "*8 + else: + tabFmt = " " + repDict = { "<" : "<", ">" : ">", "&" : "&", - "\t" : " ", + "\t" : tabFmt, nwUnicode.U_ENDASH : nwUnicode.H_ENDASH, nwUnicode.U_EMDASH : nwUnicode.H_EMDASH, nwUnicode.U_HELLIP : nwUnicode.H_HELLIP, diff --git a/nw/gui/elements/docviewer.py b/nw/gui/elements/docviewer.py index b669b2d2..b4a71b88 100644 --- a/nw/gui/elements/docviewer.py +++ b/nw/gui/elements/docviewer.py @@ -39,6 +39,7 @@ class GuiDocViewer(QTextBrowser): self.qDocument = self.document() self.setMinimumWidth(300) + self.setOpenExternalLinks(False) self.initViewer() theOpt = QTextOption() @@ -116,6 +117,18 @@ class GuiDocViewer(QTextBrowser): self.theHandle = tHandle self.theProject.setLastViewed(tHandle) + print("") + print("*"*140) + print("") + print(aDoc.theResult) + print("") + print("*"*140) + print("") + print(self.toHtml()) + print("") + print("*"*140) + print("") + self.theParent.docMeta.refreshReferences(tHandle) return True @@ -173,21 +186,8 @@ class GuiDocViewer(QTextBrowser): " font-size: {textSize:.1f}pt;" " color: rgb({tColR},{tColG},{tColB});" "}}\n" - "h1 {{" + "h1, h2, h3, h4 {{" " color: rgb({hColR},{hColG},{hColB});" - " font-size: {h1Size:.1f}pt;" - "}}\n" - "h2 {{" - " color: rgb({hColR},{hColG},{hColB});" - " font-size: {h2Size:.1f}pt;" - "}}\n" - "h3 {{" - " color: rgb({hColR},{hColG},{hColB});" - " font-size: {h3Size:.1f}pt;" - "}}\n" - "h4 {{" - " color: rgb({hColR},{hColG},{hColB});" - " font-size: {h4Size:.1f}pt;" "}}\n" "a {{" " color: rgb({aColR},{aColG},{aColB});" @@ -212,10 +212,6 @@ class GuiDocViewer(QTextBrowser): ).format( textSize = self.mainConf.textSize, preSize = self.mainConf.textSize*0.9, - h1Size = self.mainConf.textSize*1.8, - h2Size = self.mainConf.textSize*1.6, - h3Size = self.mainConf.textSize*1.4, - h4Size = self.mainConf.textSize*1.2, tColR = self.theTheme.colText[0], tColG = self.theTheme.colText[1], tColB = self.theTheme.colText[2], @@ -237,6 +233,8 @@ class GuiDocViewer(QTextBrowser): ) self.qDocument.setDefaultStyleSheet(styleSheet) + print(styleSheet) + return True # END Class GuiDocViewer From bc105c1f715d539171b04e8b5f22e40ab614d609 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Fri, 1 Nov 2019 19:32:35 +0100 Subject: [PATCH 3/4] Remove debug code --- nw/gui/elements/docviewer.py | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/nw/gui/elements/docviewer.py b/nw/gui/elements/docviewer.py index b4a71b88..629a9824 100644 --- a/nw/gui/elements/docviewer.py +++ b/nw/gui/elements/docviewer.py @@ -117,18 +117,6 @@ class GuiDocViewer(QTextBrowser): self.theHandle = tHandle self.theProject.setLastViewed(tHandle) - print("") - print("*"*140) - print("") - print(aDoc.theResult) - print("") - print("*"*140) - print("") - print(self.toHtml()) - print("") - print("*"*140) - print("") - self.theParent.docMeta.refreshReferences(tHandle) return True @@ -183,8 +171,8 @@ class GuiDocViewer(QTextBrowser): styleSheet = ( "body {{" - " font-size: {textSize:.1f}pt;" " color: rgb({tColR},{tColG},{tColB});" + " font-size: {textSize:.1f}pt;" "}}\n" "h1, h2, h3, h4 {{" " color: rgb({hColR},{hColG},{hColB});" @@ -233,8 +221,6 @@ class GuiDocViewer(QTextBrowser): ) self.qDocument.setDefaultStyleSheet(styleSheet) - print(styleSheet) - return True # END Class GuiDocViewer From bc4fc5a0f01b30c5f11242f37a9dff2cf29d8ce8 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Fri, 1 Nov 2019 19:39:27 +0100 Subject: [PATCH 4/4] Fixed bug where the page break was written over the last line of ttile/part page instead of appended --- nw/convert/tokenizer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nw/convert/tokenizer.py b/nw/convert/tokenizer.py index 81543ad1..55452915 100644 --- a/nw/convert/tokenizer.py +++ b/nw/convert/tokenizer.py @@ -285,7 +285,7 @@ class Tokenizer(): tFormat = tToken[2] self.theTokens[n] = (tType,tText,tFormat,self.A_CENTRE) - self.theTokens[n] = (self.T_PBREAK,"",None,self.A_LEFT) + self.theTokens.append((self.T_PBREAK,"",None,self.A_LEFT)) return