novelWriter 2.5.2__py3-none-any.whl → 2.6__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 (129) hide show
  1. {novelWriter-2.5.2.dist-info → novelWriter-2.6.dist-info}/METADATA +5 -4
  2. {novelWriter-2.5.2.dist-info → novelWriter-2.6.dist-info}/RECORD +126 -105
  3. {novelWriter-2.5.2.dist-info → novelWriter-2.6.dist-info}/WHEEL +1 -1
  4. novelwriter/__init__.py +50 -11
  5. novelwriter/assets/i18n/nw_de_DE.qm +0 -0
  6. novelwriter/assets/i18n/nw_en_US.qm +0 -0
  7. novelwriter/assets/i18n/nw_es_419.qm +0 -0
  8. novelwriter/assets/i18n/nw_fr_FR.qm +0 -0
  9. novelwriter/assets/i18n/nw_it_IT.qm +0 -0
  10. novelwriter/assets/i18n/nw_ja_JP.qm +0 -0
  11. novelwriter/assets/i18n/nw_nb_NO.qm +0 -0
  12. novelwriter/assets/i18n/nw_nl_NL.qm +0 -0
  13. novelwriter/assets/i18n/nw_pl_PL.qm +0 -0
  14. novelwriter/assets/i18n/nw_pt_BR.qm +0 -0
  15. novelwriter/assets/i18n/nw_ru_RU.qm +0 -0
  16. novelwriter/assets/i18n/nw_zh_CN.qm +0 -0
  17. novelwriter/assets/i18n/project_de_DE.json +4 -2
  18. novelwriter/assets/i18n/project_en_GB.json +1 -0
  19. novelwriter/assets/i18n/project_en_US.json +2 -0
  20. novelwriter/assets/i18n/project_it_IT.json +2 -0
  21. novelwriter/assets/i18n/project_ja_JP.json +2 -0
  22. novelwriter/assets/i18n/project_nb_NO.json +2 -0
  23. novelwriter/assets/i18n/project_nl_NL.json +2 -0
  24. novelwriter/assets/i18n/project_pl_PL.json +2 -0
  25. novelwriter/assets/i18n/project_pt_BR.json +2 -0
  26. novelwriter/assets/i18n/project_ru_RU.json +11 -0
  27. novelwriter/assets/i18n/project_zh_CN.json +2 -0
  28. novelwriter/assets/icons/typicons_dark/icons.conf +8 -0
  29. novelwriter/assets/icons/typicons_dark/mixed_copy.svg +4 -0
  30. novelwriter/assets/icons/typicons_dark/mixed_margin-bottom.svg +6 -0
  31. novelwriter/assets/icons/typicons_dark/mixed_margin-left.svg +6 -0
  32. novelwriter/assets/icons/typicons_dark/mixed_margin-right.svg +6 -0
  33. novelwriter/assets/icons/typicons_dark/mixed_margin-top.svg +6 -0
  34. novelwriter/assets/icons/typicons_dark/mixed_size-height.svg +6 -0
  35. novelwriter/assets/icons/typicons_dark/mixed_size-width.svg +6 -0
  36. novelwriter/assets/icons/typicons_dark/nw_toolbar.svg +5 -0
  37. novelwriter/assets/icons/typicons_light/icons.conf +8 -0
  38. novelwriter/assets/icons/typicons_light/mixed_copy.svg +4 -0
  39. novelwriter/assets/icons/typicons_light/mixed_margin-bottom.svg +6 -0
  40. novelwriter/assets/icons/typicons_light/mixed_margin-left.svg +6 -0
  41. novelwriter/assets/icons/typicons_light/mixed_margin-right.svg +6 -0
  42. novelwriter/assets/icons/typicons_light/mixed_margin-top.svg +6 -0
  43. novelwriter/assets/icons/typicons_light/mixed_size-height.svg +6 -0
  44. novelwriter/assets/icons/typicons_light/mixed_size-width.svg +6 -0
  45. novelwriter/assets/icons/typicons_light/nw_toolbar.svg +5 -0
  46. novelwriter/assets/manual.pdf +0 -0
  47. novelwriter/assets/sample.zip +0 -0
  48. novelwriter/assets/text/credits_en.htm +1 -0
  49. novelwriter/assets/themes/default_light.conf +2 -2
  50. novelwriter/common.py +101 -3
  51. novelwriter/config.py +30 -17
  52. novelwriter/constants.py +189 -81
  53. novelwriter/core/buildsettings.py +74 -40
  54. novelwriter/core/coretools.py +146 -148
  55. novelwriter/core/docbuild.py +133 -171
  56. novelwriter/core/document.py +1 -1
  57. novelwriter/core/index.py +39 -38
  58. novelwriter/core/item.py +42 -9
  59. novelwriter/core/itemmodel.py +518 -0
  60. novelwriter/core/options.py +5 -2
  61. novelwriter/core/project.py +68 -90
  62. novelwriter/core/projectdata.py +8 -2
  63. novelwriter/core/projectxml.py +1 -1
  64. novelwriter/core/sessions.py +1 -1
  65. novelwriter/core/spellcheck.py +10 -15
  66. novelwriter/core/status.py +24 -8
  67. novelwriter/core/storage.py +1 -1
  68. novelwriter/core/tree.py +269 -288
  69. novelwriter/dialogs/about.py +1 -1
  70. novelwriter/dialogs/docmerge.py +8 -18
  71. novelwriter/dialogs/docsplit.py +1 -1
  72. novelwriter/dialogs/editlabel.py +1 -1
  73. novelwriter/dialogs/preferences.py +47 -34
  74. novelwriter/dialogs/projectsettings.py +149 -99
  75. novelwriter/dialogs/quotes.py +1 -1
  76. novelwriter/dialogs/wordlist.py +11 -10
  77. novelwriter/enum.py +37 -24
  78. novelwriter/error.py +2 -2
  79. novelwriter/extensions/configlayout.py +28 -13
  80. novelwriter/extensions/eventfilters.py +1 -1
  81. novelwriter/extensions/modified.py +30 -6
  82. novelwriter/extensions/novelselector.py +4 -3
  83. novelwriter/extensions/pagedsidebar.py +9 -9
  84. novelwriter/extensions/progressbars.py +4 -4
  85. novelwriter/extensions/statusled.py +3 -3
  86. novelwriter/extensions/switch.py +3 -3
  87. novelwriter/extensions/switchbox.py +1 -1
  88. novelwriter/extensions/versioninfo.py +1 -1
  89. novelwriter/formats/shared.py +156 -0
  90. novelwriter/formats/todocx.py +1191 -0
  91. novelwriter/formats/tohtml.py +454 -0
  92. novelwriter/{core → formats}/tokenizer.py +497 -495
  93. novelwriter/formats/tomarkdown.py +218 -0
  94. novelwriter/{core → formats}/toodt.py +312 -433
  95. novelwriter/formats/toqdoc.py +486 -0
  96. novelwriter/formats/toraw.py +91 -0
  97. novelwriter/gui/doceditor.py +347 -287
  98. novelwriter/gui/dochighlight.py +97 -85
  99. novelwriter/gui/docviewer.py +90 -33
  100. novelwriter/gui/docviewerpanel.py +18 -26
  101. novelwriter/gui/editordocument.py +18 -3
  102. novelwriter/gui/itemdetails.py +27 -29
  103. novelwriter/gui/mainmenu.py +130 -64
  104. novelwriter/gui/noveltree.py +46 -48
  105. novelwriter/gui/outline.py +202 -256
  106. novelwriter/gui/projtree.py +590 -1238
  107. novelwriter/gui/search.py +11 -19
  108. novelwriter/gui/sidebar.py +8 -7
  109. novelwriter/gui/statusbar.py +20 -3
  110. novelwriter/gui/theme.py +11 -6
  111. novelwriter/guimain.py +101 -201
  112. novelwriter/shared.py +67 -28
  113. novelwriter/text/counting.py +3 -1
  114. novelwriter/text/patterns.py +169 -61
  115. novelwriter/tools/dictionaries.py +3 -3
  116. novelwriter/tools/lipsum.py +1 -1
  117. novelwriter/tools/manusbuild.py +15 -13
  118. novelwriter/tools/manuscript.py +121 -79
  119. novelwriter/tools/manussettings.py +424 -291
  120. novelwriter/tools/noveldetails.py +1 -1
  121. novelwriter/tools/welcome.py +6 -6
  122. novelwriter/tools/writingstats.py +4 -4
  123. novelwriter/types.py +25 -9
  124. novelwriter/core/tohtml.py +0 -530
  125. novelwriter/core/tomarkdown.py +0 -252
  126. novelwriter/core/toqdoc.py +0 -419
  127. {novelWriter-2.5.2.dist-info → novelWriter-2.6.dist-info}/LICENSE.md +0 -0
  128. {novelWriter-2.5.2.dist-info → novelWriter-2.6.dist-info}/entry_points.txt +0 -0
  129. {novelWriter-2.5.2.dist-info → novelWriter-2.6.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,218 @@
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 (C) 2021 Veronica Berglyd Olsen and novelWriter contributors
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 in (BlockTyp.TITLE, BlockTyp.PART):
117
+ tHead = tText.replace("\n", " - ")
118
+ lines.append(f"{tHead}\n")
119
+ lines.append("="*len(tHead) + "\n\n")
120
+
121
+ elif tType == BlockTyp.HEAD1:
122
+ tHead = tText.replace("\n", " - ")
123
+ lines.append(f"# {tHead}\n\n")
124
+
125
+ elif tType == BlockTyp.HEAD2:
126
+ tHead = tText.replace("\n", " - ")
127
+ lines.append(f"## {tHead}\n\n")
128
+
129
+ elif tType == BlockTyp.HEAD3:
130
+ tHead = tText.replace("\n", " - ")
131
+ lines.append(f"### {tHead}\n\n")
132
+
133
+ elif tType == BlockTyp.HEAD4:
134
+ tHead = tText.replace("\n", " - ")
135
+ lines.append(f"#### {tHead}\n\n")
136
+
137
+ elif tType == BlockTyp.SEP:
138
+ lines.append(f"{tText}\n\n")
139
+
140
+ elif tType == BlockTyp.SKIP:
141
+ lines.append(f"{cSkip}\n\n")
142
+
143
+ elif tType == BlockTyp.COMMENT:
144
+ lines.append(f"{self._formatText(tText, tFormat, mTags)}\n\n")
145
+
146
+ elif tType == BlockTyp.KEYWORD:
147
+ end = " \n" if tStyle & BlockFmt.Z_BTM else "\n\n"
148
+ lines.append(f"{self._formatText(tText, tFormat, mTags)}{end}")
149
+
150
+ self._pages.append("".join(lines))
151
+
152
+ return
153
+
154
+ def closeDocument(self) -> None:
155
+ """Run close document tasks."""
156
+ # Replace fields if there are stats available
157
+ if self._usedFields and self._counts:
158
+ pages = len(self._pages)
159
+ for doc, field in self._usedFields:
160
+ if doc >= 0 and doc < pages and (value := self._counts.get(field)) is not None:
161
+ self._pages[doc] = self._pages[doc].replace(
162
+ f"{{{{{field}}}}}", self._formatInt(value)
163
+ )
164
+
165
+ # Add footnotes
166
+ if self._usedNotes:
167
+ tags = EXT_MD if self._extended else STD_MD
168
+ footnotes = self._localLookup("Footnotes")
169
+
170
+ lines = []
171
+ lines.append(f"### {footnotes}\n\n")
172
+ for key, index in self._usedNotes.items():
173
+ if content := self._footnotes.get(key):
174
+ marker = f"{index}. "
175
+ text = self._formatText(content[0], content[1], tags)
176
+ lines.append(f"{marker}{text}\n")
177
+ lines.append("\n")
178
+ self._pages.append("".join(lines))
179
+
180
+ return
181
+
182
+ def saveDocument(self, path: Path) -> None:
183
+ """Save the data to a plain text file."""
184
+ with open(path, mode="w", encoding="utf-8") as outFile:
185
+ outFile.write("".join(self._pages))
186
+ logger.info("Wrote file: %s", path)
187
+ return
188
+
189
+ def replaceTabs(self, nSpaces: int = 8, spaceChar: str = " ") -> None:
190
+ """Replace tabs with spaces."""
191
+ spaces = spaceChar*nSpaces
192
+ self._pages = [p.replace("\t", spaces) for p in self._pages]
193
+ return
194
+
195
+ ##
196
+ # Internal Functions
197
+ ##
198
+
199
+ def _formatText(self, text: str, tFmt: T_Formats, tags: dict[TextFmt, str]) -> str:
200
+ """Apply formatting tags to text."""
201
+ temp = text
202
+ for pos, fmt, data in reversed(tFmt):
203
+ md = ""
204
+ if fmt == TextFmt.FNOTE:
205
+ if data in self._footnotes:
206
+ index = len(self._usedNotes) + 1
207
+ self._usedNotes[data] = index
208
+ md = f"[{index}]"
209
+ else:
210
+ md = "[ERR]"
211
+ elif fmt == TextFmt.FIELD:
212
+ if field := data.partition(":")[2]:
213
+ self._usedFields.append((len(self._pages), field))
214
+ md = f"{{{{{field}}}}}"
215
+ else:
216
+ md = tags.get(fmt, "")
217
+ temp = f"{temp[:pos]}{md}{temp[pos:]}"
218
+ return temp