novelWriter 2.5.1__py3-none-any.whl → 2.6b1__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.
- {novelWriter-2.5.1.dist-info → novelWriter-2.6b1.dist-info}/METADATA +2 -1
- {novelWriter-2.5.1.dist-info → novelWriter-2.6b1.dist-info}/RECORD +61 -56
- {novelWriter-2.5.1.dist-info → novelWriter-2.6b1.dist-info}/WHEEL +1 -1
- novelwriter/__init__.py +3 -3
- novelwriter/assets/i18n/project_en_GB.json +1 -0
- novelwriter/assets/icons/typicons_dark/icons.conf +1 -0
- novelwriter/assets/icons/typicons_dark/mixed_copy.svg +4 -0
- novelwriter/assets/icons/typicons_light/icons.conf +1 -0
- novelwriter/assets/icons/typicons_light/mixed_copy.svg +4 -0
- novelwriter/assets/manual.pdf +0 -0
- novelwriter/assets/sample.zip +0 -0
- novelwriter/assets/themes/default_light.conf +2 -2
- novelwriter/common.py +63 -0
- novelwriter/config.py +10 -3
- novelwriter/constants.py +153 -60
- novelwriter/core/buildsettings.py +66 -39
- novelwriter/core/coretools.py +34 -22
- novelwriter/core/docbuild.py +130 -169
- novelwriter/core/index.py +29 -18
- novelwriter/core/item.py +2 -2
- novelwriter/core/options.py +4 -1
- novelwriter/core/spellcheck.py +9 -14
- novelwriter/dialogs/preferences.py +45 -32
- novelwriter/dialogs/projectsettings.py +3 -3
- novelwriter/enum.py +29 -23
- novelwriter/extensions/configlayout.py +24 -11
- novelwriter/extensions/modified.py +13 -1
- novelwriter/extensions/pagedsidebar.py +5 -5
- novelwriter/formats/shared.py +155 -0
- novelwriter/formats/todocx.py +1195 -0
- novelwriter/formats/tohtml.py +452 -0
- novelwriter/{core → formats}/tokenizer.py +483 -485
- novelwriter/formats/tomarkdown.py +217 -0
- novelwriter/{core → formats}/toodt.py +270 -320
- novelwriter/formats/toqdoc.py +436 -0
- novelwriter/formats/toraw.py +91 -0
- novelwriter/gui/doceditor.py +240 -193
- novelwriter/gui/dochighlight.py +96 -84
- novelwriter/gui/docviewer.py +56 -30
- novelwriter/gui/docviewerpanel.py +3 -3
- novelwriter/gui/editordocument.py +17 -2
- novelwriter/gui/itemdetails.py +8 -4
- novelwriter/gui/mainmenu.py +121 -60
- novelwriter/gui/noveltree.py +35 -37
- novelwriter/gui/outline.py +186 -238
- novelwriter/gui/projtree.py +142 -131
- novelwriter/gui/sidebar.py +7 -6
- novelwriter/gui/theme.py +5 -4
- novelwriter/guimain.py +43 -155
- novelwriter/shared.py +14 -4
- novelwriter/text/counting.py +2 -0
- novelwriter/text/patterns.py +155 -59
- novelwriter/tools/manusbuild.py +1 -1
- novelwriter/tools/manuscript.py +121 -78
- novelwriter/tools/manussettings.py +403 -260
- novelwriter/tools/welcome.py +4 -4
- novelwriter/tools/writingstats.py +3 -3
- novelwriter/types.py +16 -6
- novelwriter/core/tohtml.py +0 -530
- novelwriter/core/tomarkdown.py +0 -252
- novelwriter/core/toqdoc.py +0 -419
- {novelWriter-2.5.1.dist-info → novelWriter-2.6b1.dist-info}/LICENSE.md +0 -0
- {novelWriter-2.5.1.dist-info → novelWriter-2.6b1.dist-info}/entry_points.txt +0 -0
- {novelWriter-2.5.1.dist-info → novelWriter-2.6b1.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
|