novelWriter 2.5.3__py3-none-any.whl → 2.6b2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. {novelWriter-2.5.3.dist-info → novelWriter-2.6b2.dist-info}/METADATA +1 -1
  2. {novelWriter-2.5.3.dist-info → novelWriter-2.6b2.dist-info}/RECORD +80 -60
  3. novelwriter/__init__.py +49 -10
  4. novelwriter/assets/i18n/project_en_GB.json +1 -0
  5. novelwriter/assets/icons/typicons_dark/icons.conf +8 -0
  6. novelwriter/assets/icons/typicons_dark/mixed_copy.svg +4 -0
  7. novelwriter/assets/icons/typicons_dark/mixed_margin-bottom.svg +6 -0
  8. novelwriter/assets/icons/typicons_dark/mixed_margin-left.svg +6 -0
  9. novelwriter/assets/icons/typicons_dark/mixed_margin-right.svg +6 -0
  10. novelwriter/assets/icons/typicons_dark/mixed_margin-top.svg +6 -0
  11. novelwriter/assets/icons/typicons_dark/mixed_size-height.svg +6 -0
  12. novelwriter/assets/icons/typicons_dark/mixed_size-width.svg +6 -0
  13. novelwriter/assets/icons/typicons_dark/nw_toolbar.svg +5 -0
  14. novelwriter/assets/icons/typicons_light/icons.conf +8 -0
  15. novelwriter/assets/icons/typicons_light/mixed_copy.svg +4 -0
  16. novelwriter/assets/icons/typicons_light/mixed_margin-bottom.svg +6 -0
  17. novelwriter/assets/icons/typicons_light/mixed_margin-left.svg +6 -0
  18. novelwriter/assets/icons/typicons_light/mixed_margin-right.svg +6 -0
  19. novelwriter/assets/icons/typicons_light/mixed_margin-top.svg +6 -0
  20. novelwriter/assets/icons/typicons_light/mixed_size-height.svg +6 -0
  21. novelwriter/assets/icons/typicons_light/mixed_size-width.svg +6 -0
  22. novelwriter/assets/icons/typicons_light/nw_toolbar.svg +5 -0
  23. novelwriter/assets/manual.pdf +0 -0
  24. novelwriter/assets/sample.zip +0 -0
  25. novelwriter/common.py +100 -2
  26. novelwriter/config.py +25 -15
  27. novelwriter/constants.py +168 -60
  28. novelwriter/core/buildsettings.py +66 -39
  29. novelwriter/core/coretools.py +145 -147
  30. novelwriter/core/docbuild.py +132 -170
  31. novelwriter/core/index.py +38 -37
  32. novelwriter/core/item.py +41 -8
  33. novelwriter/core/itemmodel.py +518 -0
  34. novelwriter/core/options.py +4 -1
  35. novelwriter/core/project.py +67 -89
  36. novelwriter/core/spellcheck.py +9 -14
  37. novelwriter/core/status.py +7 -5
  38. novelwriter/core/tree.py +268 -287
  39. novelwriter/dialogs/docmerge.py +7 -17
  40. novelwriter/dialogs/preferences.py +46 -33
  41. novelwriter/dialogs/projectsettings.py +5 -5
  42. novelwriter/enum.py +36 -23
  43. novelwriter/extensions/configlayout.py +27 -12
  44. novelwriter/extensions/modified.py +13 -1
  45. novelwriter/extensions/pagedsidebar.py +5 -5
  46. novelwriter/formats/shared.py +155 -0
  47. novelwriter/formats/todocx.py +1191 -0
  48. novelwriter/formats/tohtml.py +451 -0
  49. novelwriter/{core → formats}/tokenizer.py +487 -491
  50. novelwriter/formats/tomarkdown.py +217 -0
  51. novelwriter/{core → formats}/toodt.py +311 -432
  52. novelwriter/formats/toqdoc.py +484 -0
  53. novelwriter/formats/toraw.py +91 -0
  54. novelwriter/gui/doceditor.py +342 -284
  55. novelwriter/gui/dochighlight.py +96 -84
  56. novelwriter/gui/docviewer.py +88 -31
  57. novelwriter/gui/docviewerpanel.py +17 -25
  58. novelwriter/gui/editordocument.py +17 -2
  59. novelwriter/gui/itemdetails.py +25 -28
  60. novelwriter/gui/mainmenu.py +129 -63
  61. novelwriter/gui/noveltree.py +45 -47
  62. novelwriter/gui/outline.py +196 -249
  63. novelwriter/gui/projtree.py +594 -1241
  64. novelwriter/gui/search.py +9 -10
  65. novelwriter/gui/sidebar.py +7 -6
  66. novelwriter/gui/theme.py +10 -5
  67. novelwriter/guimain.py +100 -196
  68. novelwriter/shared.py +66 -27
  69. novelwriter/text/counting.py +2 -0
  70. novelwriter/text/patterns.py +168 -60
  71. novelwriter/tools/manusbuild.py +14 -12
  72. novelwriter/tools/manuscript.py +120 -78
  73. novelwriter/tools/manussettings.py +424 -291
  74. novelwriter/tools/welcome.py +4 -4
  75. novelwriter/tools/writingstats.py +3 -3
  76. novelwriter/types.py +23 -7
  77. novelwriter/core/tohtml.py +0 -530
  78. novelwriter/core/tomarkdown.py +0 -252
  79. novelwriter/core/toqdoc.py +0 -419
  80. {novelWriter-2.5.3.dist-info → novelWriter-2.6b2.dist-info}/LICENSE.md +0 -0
  81. {novelWriter-2.5.3.dist-info → novelWriter-2.6b2.dist-info}/WHEEL +0 -0
  82. {novelWriter-2.5.3.dist-info → novelWriter-2.6b2.dist-info}/entry_points.txt +0 -0
  83. {novelWriter-2.5.3.dist-info → novelWriter-2.6b2.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,217 @@
1
+ """
2
+ novelWriter – Markdown Text Converter
3
+ =====================================
4
+
5
+ File History:
6
+ Created: 2021-02-06 [1.2b1] ToMarkdown
7
+
8
+ This file is a part of novelWriter
9
+ Copyright 2018–2024, Veronica Berglyd Olsen
10
+
11
+ This program is free software: you can redistribute it and/or modify
12
+ it under the terms of the GNU General Public License as published by
13
+ the Free Software Foundation, either version 3 of the License, or
14
+ (at your option) any later version.
15
+
16
+ This program is distributed in the hope that it will be useful, but
17
+ WITHOUT ANY WARRANTY; without even the implied warranty of
18
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19
+ General Public License for more details.
20
+
21
+ You should have received a copy of the GNU General Public License
22
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
23
+ """
24
+ from __future__ import annotations
25
+
26
+ import logging
27
+
28
+ from pathlib import Path
29
+
30
+ from novelwriter.constants import nwUnicode
31
+ from novelwriter.core.project import NWProject
32
+ from novelwriter.formats.shared import BlockFmt, BlockTyp, T_Formats, TextFmt
33
+ from novelwriter.formats.tokenizer import Tokenizer
34
+
35
+ logger = logging.getLogger(__name__)
36
+
37
+
38
+ # Standard Markdown
39
+ STD_MD = {
40
+ TextFmt.B_B: "**",
41
+ TextFmt.B_E: "**",
42
+ TextFmt.I_B: "_",
43
+ TextFmt.I_E: "_",
44
+ TextFmt.D_B: "",
45
+ TextFmt.D_E: "",
46
+ TextFmt.U_B: "",
47
+ TextFmt.U_E: "",
48
+ TextFmt.M_B: "",
49
+ TextFmt.M_E: "",
50
+ TextFmt.SUP_B: "",
51
+ TextFmt.SUP_E: "",
52
+ TextFmt.SUB_B: "",
53
+ TextFmt.SUB_E: "",
54
+ TextFmt.STRIP: "",
55
+ }
56
+
57
+ # Extended Markdown
58
+ EXT_MD = {
59
+ TextFmt.B_B: "**",
60
+ TextFmt.B_E: "**",
61
+ TextFmt.I_B: "_",
62
+ TextFmt.I_E: "_",
63
+ TextFmt.D_B: "~~",
64
+ TextFmt.D_E: "~~",
65
+ TextFmt.U_B: "",
66
+ TextFmt.U_E: "",
67
+ TextFmt.M_B: "==",
68
+ TextFmt.M_E: "==",
69
+ TextFmt.SUP_B: "^",
70
+ TextFmt.SUP_E: "^",
71
+ TextFmt.SUB_B: "~",
72
+ TextFmt.SUB_E: "~",
73
+ TextFmt.STRIP: "",
74
+ }
75
+
76
+
77
+ class ToMarkdown(Tokenizer):
78
+ """Core: Markdown Document Writer
79
+
80
+ Extend the Tokenizer class to writer Markdown output. It supports
81
+ both Standard Markdown and Extended Markdown. The class also
82
+ supports concatenating novelWriter markup files.
83
+ """
84
+
85
+ def __init__(self, project: NWProject, extended: bool) -> None:
86
+ super().__init__(project)
87
+ self._extended = extended
88
+ self._usedNotes: dict[str, int] = {}
89
+ self._usedFields: list[tuple[int, str]] = []
90
+ return
91
+
92
+ ##
93
+ # Class Methods
94
+ ##
95
+
96
+ def getFullResultSize(self) -> int:
97
+ """Return the size of the full Markdown result."""
98
+ return sum(len(x) for x in self._pages)
99
+
100
+ def doConvert(self) -> None:
101
+ """Convert the list of text tokens into a Markdown document."""
102
+ if self._extended:
103
+ mTags = EXT_MD
104
+ cSkip = nwUnicode.U_MMSP
105
+ else:
106
+ mTags = STD_MD
107
+ cSkip = ""
108
+
109
+ lines = []
110
+ for tType, _, tText, tFormat, tStyle in self._blocks:
111
+
112
+ if tType == BlockTyp.TEXT:
113
+ tTemp = self._formatText(tText, tFormat, mTags).replace("\n", " \n")
114
+ lines.append(f"{tTemp}\n\n")
115
+
116
+ elif tType == BlockTyp.TITLE:
117
+ tHead = tText.replace("\n", " - ")
118
+ lines.append(f"# {tHead}\n\n")
119
+
120
+ elif tType == BlockTyp.HEAD1:
121
+ tHead = tText.replace("\n", " - ")
122
+ lines.append(f"# {tHead}\n\n")
123
+
124
+ elif tType == BlockTyp.HEAD2:
125
+ tHead = tText.replace("\n", " - ")
126
+ lines.append(f"## {tHead}\n\n")
127
+
128
+ elif tType == BlockTyp.HEAD3:
129
+ tHead = tText.replace("\n", " - ")
130
+ lines.append(f"### {tHead}\n\n")
131
+
132
+ elif tType == BlockTyp.HEAD4:
133
+ tHead = tText.replace("\n", " - ")
134
+ lines.append(f"#### {tHead}\n\n")
135
+
136
+ elif tType == BlockTyp.SEP:
137
+ lines.append(f"{tText}\n\n")
138
+
139
+ elif tType == BlockTyp.SKIP:
140
+ lines.append(f"{cSkip}\n\n")
141
+
142
+ elif tType == BlockTyp.COMMENT:
143
+ lines.append(f"{self._formatText(tText, tFormat, mTags)}\n\n")
144
+
145
+ elif tType == BlockTyp.KEYWORD:
146
+ end = " \n" if tStyle & BlockFmt.Z_BTM else "\n\n"
147
+ lines.append(f"{self._formatText(tText, tFormat, mTags)}{end}")
148
+
149
+ self._pages.append("".join(lines))
150
+
151
+ return
152
+
153
+ def closeDocument(self) -> None:
154
+ """Run close document tasks."""
155
+ # Replace fields if there are stats available
156
+ if self._usedFields and self._counts:
157
+ pages = len(self._pages)
158
+ for doc, field in self._usedFields:
159
+ if doc >= 0 and doc < pages and (value := self._counts.get(field)) is not None:
160
+ self._pages[doc] = self._pages[doc].replace(
161
+ f"{{{{{field}}}}}", self._formatInt(value)
162
+ )
163
+
164
+ # Add footnotes
165
+ if self._usedNotes:
166
+ tags = EXT_MD if self._extended else STD_MD
167
+ footnotes = self._localLookup("Footnotes")
168
+
169
+ lines = []
170
+ lines.append(f"### {footnotes}\n\n")
171
+ for key, index in self._usedNotes.items():
172
+ if content := self._footnotes.get(key):
173
+ marker = f"{index}. "
174
+ text = self._formatText(content[0], content[1], tags)
175
+ lines.append(f"{marker}{text}\n")
176
+ lines.append("\n")
177
+ self._pages.append("".join(lines))
178
+
179
+ return
180
+
181
+ def saveDocument(self, path: Path) -> None:
182
+ """Save the data to a plain text file."""
183
+ with open(path, mode="w", encoding="utf-8") as outFile:
184
+ outFile.write("".join(self._pages))
185
+ logger.info("Wrote file: %s", path)
186
+ return
187
+
188
+ def replaceTabs(self, nSpaces: int = 8, spaceChar: str = " ") -> None:
189
+ """Replace tabs with spaces."""
190
+ spaces = spaceChar*nSpaces
191
+ self._pages = [p.replace("\t", spaces) for p in self._pages]
192
+ return
193
+
194
+ ##
195
+ # Internal Functions
196
+ ##
197
+
198
+ def _formatText(self, text: str, tFmt: T_Formats, tags: dict[TextFmt, str]) -> str:
199
+ """Apply formatting tags to text."""
200
+ temp = text
201
+ for pos, fmt, data in reversed(tFmt):
202
+ md = ""
203
+ if fmt == TextFmt.FNOTE:
204
+ if data in self._footnotes:
205
+ index = len(self._usedNotes) + 1
206
+ self._usedNotes[data] = index
207
+ md = f"[{index}]"
208
+ else:
209
+ md = "[ERR]"
210
+ elif fmt == TextFmt.FIELD:
211
+ if field := data.partition(":")[2]:
212
+ self._usedFields.append((len(self._pages), field))
213
+ md = f"{{{{{field}}}}}"
214
+ else:
215
+ md = tags.get(fmt, "")
216
+ temp = f"{temp[:pos]}{md}{temp[pos:]}"
217
+ return temp