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.
Files changed (64) hide show
  1. {novelWriter-2.5.1.dist-info → novelWriter-2.6b1.dist-info}/METADATA +2 -1
  2. {novelWriter-2.5.1.dist-info → novelWriter-2.6b1.dist-info}/RECORD +61 -56
  3. {novelWriter-2.5.1.dist-info → novelWriter-2.6b1.dist-info}/WHEEL +1 -1
  4. novelwriter/__init__.py +3 -3
  5. novelwriter/assets/i18n/project_en_GB.json +1 -0
  6. novelwriter/assets/icons/typicons_dark/icons.conf +1 -0
  7. novelwriter/assets/icons/typicons_dark/mixed_copy.svg +4 -0
  8. novelwriter/assets/icons/typicons_light/icons.conf +1 -0
  9. novelwriter/assets/icons/typicons_light/mixed_copy.svg +4 -0
  10. novelwriter/assets/manual.pdf +0 -0
  11. novelwriter/assets/sample.zip +0 -0
  12. novelwriter/assets/themes/default_light.conf +2 -2
  13. novelwriter/common.py +63 -0
  14. novelwriter/config.py +10 -3
  15. novelwriter/constants.py +153 -60
  16. novelwriter/core/buildsettings.py +66 -39
  17. novelwriter/core/coretools.py +34 -22
  18. novelwriter/core/docbuild.py +130 -169
  19. novelwriter/core/index.py +29 -18
  20. novelwriter/core/item.py +2 -2
  21. novelwriter/core/options.py +4 -1
  22. novelwriter/core/spellcheck.py +9 -14
  23. novelwriter/dialogs/preferences.py +45 -32
  24. novelwriter/dialogs/projectsettings.py +3 -3
  25. novelwriter/enum.py +29 -23
  26. novelwriter/extensions/configlayout.py +24 -11
  27. novelwriter/extensions/modified.py +13 -1
  28. novelwriter/extensions/pagedsidebar.py +5 -5
  29. novelwriter/formats/shared.py +155 -0
  30. novelwriter/formats/todocx.py +1195 -0
  31. novelwriter/formats/tohtml.py +452 -0
  32. novelwriter/{core → formats}/tokenizer.py +483 -485
  33. novelwriter/formats/tomarkdown.py +217 -0
  34. novelwriter/{core → formats}/toodt.py +270 -320
  35. novelwriter/formats/toqdoc.py +436 -0
  36. novelwriter/formats/toraw.py +91 -0
  37. novelwriter/gui/doceditor.py +240 -193
  38. novelwriter/gui/dochighlight.py +96 -84
  39. novelwriter/gui/docviewer.py +56 -30
  40. novelwriter/gui/docviewerpanel.py +3 -3
  41. novelwriter/gui/editordocument.py +17 -2
  42. novelwriter/gui/itemdetails.py +8 -4
  43. novelwriter/gui/mainmenu.py +121 -60
  44. novelwriter/gui/noveltree.py +35 -37
  45. novelwriter/gui/outline.py +186 -238
  46. novelwriter/gui/projtree.py +142 -131
  47. novelwriter/gui/sidebar.py +7 -6
  48. novelwriter/gui/theme.py +5 -4
  49. novelwriter/guimain.py +43 -155
  50. novelwriter/shared.py +14 -4
  51. novelwriter/text/counting.py +2 -0
  52. novelwriter/text/patterns.py +155 -59
  53. novelwriter/tools/manusbuild.py +1 -1
  54. novelwriter/tools/manuscript.py +121 -78
  55. novelwriter/tools/manussettings.py +403 -260
  56. novelwriter/tools/welcome.py +4 -4
  57. novelwriter/tools/writingstats.py +3 -3
  58. novelwriter/types.py +16 -6
  59. novelwriter/core/tohtml.py +0 -530
  60. novelwriter/core/tomarkdown.py +0 -252
  61. novelwriter/core/toqdoc.py +0 -419
  62. {novelWriter-2.5.1.dist-info → novelWriter-2.6b1.dist-info}/LICENSE.md +0 -0
  63. {novelWriter-2.5.1.dist-info → novelWriter-2.6b1.dist-info}/entry_points.txt +0 -0
  64. {novelWriter-2.5.1.dist-info → novelWriter-2.6b1.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,452 @@
1
+ """
2
+ novelWriter – HTML Text Converter
3
+ =================================
4
+
5
+ File History:
6
+ Created: 2019-05-07 [0.0.1] ToHtml
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 json
27
+ import logging
28
+
29
+ from pathlib import Path
30
+ from time import time
31
+
32
+ from novelwriter.common import formatTimeStamp
33
+ from novelwriter.constants import nwHtmlUnicode
34
+ from novelwriter.core.project import NWProject
35
+ from novelwriter.formats.shared import BlockFmt, BlockTyp, T_Formats, TextFmt, stripEscape
36
+ from novelwriter.formats.tokenizer import Tokenizer
37
+ from novelwriter.types import FONT_STYLE, FONT_WEIGHTS, QtHexRgb
38
+
39
+ logger = logging.getLogger(__name__)
40
+
41
+ # Each opener tag, with the id of its corresponding closer and tag format
42
+ HTML_OPENER: dict[int, tuple[int, str]] = {
43
+ TextFmt.B_B: (TextFmt.B_E, "<strong>"),
44
+ TextFmt.I_B: (TextFmt.I_E, "<em>"),
45
+ TextFmt.D_B: (TextFmt.D_E, "<del>"),
46
+ TextFmt.U_B: (TextFmt.U_E, "<span style='text-decoration: underline;'>"),
47
+ TextFmt.M_B: (TextFmt.M_E, "<mark>"),
48
+ TextFmt.SUP_B: (TextFmt.SUP_E, "<sup>"),
49
+ TextFmt.SUB_B: (TextFmt.SUB_E, "<sub>"),
50
+ TextFmt.COL_B: (TextFmt.COL_E, "<span style='color: {0}'>"),
51
+ TextFmt.ANM_B: (TextFmt.ANM_E, "<a name='{0}'>"),
52
+ TextFmt.ARF_B: (TextFmt.ARF_E, "<a href='{0}'>"),
53
+ TextFmt.HRF_B: (TextFmt.HRF_E, "<a href='{0}'>"),
54
+ }
55
+
56
+ # Each closer tag, with the id of its corresponding opener and tag format
57
+ HTML_CLOSER: dict[int, tuple[int, str]] = {
58
+ TextFmt.B_E: (TextFmt.B_B, "</strong>"),
59
+ TextFmt.I_E: (TextFmt.I_B, "</em>"),
60
+ TextFmt.D_E: (TextFmt.D_B, "</del>"),
61
+ TextFmt.U_E: (TextFmt.U_B, "</span>"),
62
+ TextFmt.M_E: (TextFmt.M_B, "</mark>"),
63
+ TextFmt.SUP_E: (TextFmt.SUP_B, "</sup>"),
64
+ TextFmt.SUB_E: (TextFmt.SUB_B, "</sub>"),
65
+ TextFmt.COL_E: (TextFmt.COL_B, "</span>"),
66
+ TextFmt.ANM_E: (TextFmt.ANM_B, "</a>"),
67
+ TextFmt.ARF_E: (TextFmt.ARF_B, "</a>"),
68
+ TextFmt.HRF_E: (TextFmt.HRF_B, "</a>"),
69
+ }
70
+
71
+ # Empty HTML tag record
72
+ HTML_NONE = (0, "")
73
+
74
+
75
+ class ToHtml(Tokenizer):
76
+ """Core: HTML Document Writer
77
+
78
+ Extend the Tokenizer class to writer HTML output. This class is
79
+ also used by the Document Viewer, and Manuscript Build Preview.
80
+ """
81
+
82
+ def __init__(self, project: NWProject) -> None:
83
+ super().__init__(project)
84
+ self._trMap = {}
85
+ self._cssStyles = True
86
+ self._usedNotes: dict[str, int] = {}
87
+ self._usedFields: list[tuple[int, str]] = []
88
+ self.setReplaceUnicode(False)
89
+ return
90
+
91
+ ##
92
+ # Setters
93
+ ##
94
+
95
+ def setStyles(self, cssStyles: bool) -> None:
96
+ """Enable or disable CSS styling. Some elements may still have
97
+ class tags.
98
+ """
99
+ self._cssStyles = cssStyles
100
+ return
101
+
102
+ def setReplaceUnicode(self, doReplace: bool) -> None:
103
+ """Set the translation map to either minimal or full unicode for
104
+ html entities replacement.
105
+ """
106
+ # Control characters must always be replaced
107
+ # Angle brackets are replaced later as they are also used in
108
+ # formatting codes
109
+ self._trMap = str.maketrans({"&": "&amp;"})
110
+ if doReplace:
111
+ # Extend to all relevant Unicode characters
112
+ self._trMap.update(str.maketrans(nwHtmlUnicode.U_TO_H))
113
+ return
114
+
115
+ ##
116
+ # Class Methods
117
+ ##
118
+
119
+ def getFullResultSize(self) -> int:
120
+ """Return the size of the full HTML result."""
121
+ return sum(len(x) for x in self._pages)
122
+
123
+ def doPreProcessing(self) -> None:
124
+ """Extend the auto-replace to also properly encode some unicode
125
+ characters into their respective HTML entities.
126
+ """
127
+ super().doPreProcessing()
128
+ self._text = self._text.translate(self._trMap)
129
+ return
130
+
131
+ def doConvert(self) -> None:
132
+ """Convert the list of text tokens into an HTML document."""
133
+ if self._isNovel:
134
+ # For story files, we bump the titles one level up
135
+ h1Cl = " class='title'"
136
+ h1 = "h1"
137
+ h2 = "h1"
138
+ h3 = "h2"
139
+ h4 = "h3"
140
+ else:
141
+ h1Cl = ""
142
+ h1 = "h1"
143
+ h2 = "h2"
144
+ h3 = "h3"
145
+ h4 = "h4"
146
+
147
+ lines = []
148
+ for tType, tMeta, tText, tFmt, tStyle in self._blocks:
149
+
150
+ # Replace < and > with HTML entities
151
+ if tFmt:
152
+ # If we have formatting, we must recompute the locations
153
+ cText = []
154
+ i = 0
155
+ for c in tText:
156
+ if c == "<":
157
+ cText.append("&lt;")
158
+ tFmt = [(p + 3 if p > i else p, f, k) for p, f, k in tFmt]
159
+ i += 4
160
+ elif c == ">":
161
+ cText.append("&gt;")
162
+ tFmt = [(p + 3 if p > i else p, f, k) for p, f, k in tFmt]
163
+ i += 4
164
+ else:
165
+ cText.append(c)
166
+ i += 1
167
+ tText = "".join(cText)
168
+ else:
169
+ # If we don't have formatting, we can do a plain replace
170
+ tText = tText.replace("<", "&lt;").replace(">", "&gt;")
171
+
172
+ # Styles
173
+ aStyle = []
174
+ if self._cssStyles:
175
+ if tStyle & BlockFmt.LEFT:
176
+ aStyle.append("text-align: left;")
177
+ elif tStyle & BlockFmt.RIGHT:
178
+ aStyle.append("text-align: right;")
179
+ elif tStyle & BlockFmt.CENTRE:
180
+ aStyle.append("text-align: center;")
181
+ elif tStyle & BlockFmt.JUSTIFY:
182
+ aStyle.append("text-align: justify;")
183
+
184
+ if tStyle & BlockFmt.PBB:
185
+ aStyle.append("page-break-before: always;")
186
+ if tStyle & BlockFmt.PBA:
187
+ aStyle.append("page-break-after: always;")
188
+
189
+ if tStyle & BlockFmt.Z_BTM:
190
+ aStyle.append("margin-bottom: 0;")
191
+ if tStyle & BlockFmt.Z_TOP:
192
+ aStyle.append("margin-top: 0;")
193
+
194
+ if tStyle & BlockFmt.IND_L:
195
+ aStyle.append(f"margin-left: {self._blockIndent:.2f}em;")
196
+ if tStyle & BlockFmt.IND_R:
197
+ aStyle.append(f"margin-right: {self._blockIndent:.2f}em;")
198
+ if tStyle & BlockFmt.IND_T:
199
+ aStyle.append(f"text-indent: {self._firstWidth:.2f}em;")
200
+
201
+ if aStyle:
202
+ stVals = " ".join(aStyle)
203
+ hStyle = f" style='{stVals}'"
204
+ else:
205
+ hStyle = ""
206
+
207
+ if self._linkHeadings and tMeta:
208
+ aNm = f"<a name='{tMeta}'></a>"
209
+ else:
210
+ aNm = ""
211
+
212
+ # Process Text Type
213
+ if tType == BlockTyp.TEXT:
214
+ lines.append(f"<p{hStyle}>{self._formatText(tText, tFmt)}</p>\n")
215
+
216
+ elif tType == BlockTyp.TITLE:
217
+ tHead = tText.replace("\n", "<br>")
218
+ lines.append(f"<h1 class='title'{hStyle}>{aNm}{tHead}</h1>\n")
219
+
220
+ elif tType == BlockTyp.HEAD1:
221
+ tHead = tText.replace("\n", "<br>")
222
+ lines.append(f"<{h1}{h1Cl}{hStyle}>{aNm}{tHead}</{h1}>\n")
223
+
224
+ elif tType == BlockTyp.HEAD2:
225
+ tHead = tText.replace("\n", "<br>")
226
+ lines.append(f"<{h2}{hStyle}>{aNm}{tHead}</{h2}>\n")
227
+
228
+ elif tType == BlockTyp.HEAD3:
229
+ tHead = tText.replace("\n", "<br>")
230
+ lines.append(f"<{h3}{hStyle}>{aNm}{tHead}</{h3}>\n")
231
+
232
+ elif tType == BlockTyp.HEAD4:
233
+ tHead = tText.replace("\n", "<br>")
234
+ lines.append(f"<{h4}{hStyle}>{aNm}{tHead}</{h4}>\n")
235
+
236
+ elif tType == BlockTyp.SEP:
237
+ lines.append(f"<p class='sep'{hStyle}>{tText}</p>\n")
238
+
239
+ elif tType == BlockTyp.SKIP:
240
+ lines.append(f"<p{hStyle}>&nbsp;</p>\n")
241
+
242
+ elif tType == BlockTyp.COMMENT:
243
+ lines.append(f"<p class='comment'{hStyle}>{self._formatText(tText, tFmt)}</p>\n")
244
+
245
+ elif tType == BlockTyp.KEYWORD:
246
+ tClass = f"meta meta-{tMeta}"
247
+ lines.append(f"<p class='{tClass}'{hStyle}>{self._formatText(tText, tFmt)}</p>\n")
248
+
249
+ self._pages.append("".join(lines))
250
+
251
+ return
252
+
253
+ def closeDocument(self) -> None:
254
+ """Run close document tasks."""
255
+ # Replace fields if there are stats available
256
+ if self._usedFields and self._counts:
257
+ pages = len(self._pages)
258
+ for doc, field in self._usedFields:
259
+ if doc >= 0 and doc < pages and (value := self._counts.get(field)) is not None:
260
+ self._pages[doc] = self._pages[doc].replace(
261
+ f"{{{{{field}}}}}", self._formatInt(value)
262
+ )
263
+
264
+ # Add footnotes
265
+ if self._usedNotes:
266
+ footnotes = self._localLookup("Footnotes")
267
+
268
+ lines = []
269
+ lines.append(f"<h3>{footnotes}</h3>\n")
270
+ lines.append("<ol>\n")
271
+ for key, index in self._usedNotes.items():
272
+ if content := self._footnotes.get(key):
273
+ text = self._formatText(*content)
274
+ lines.append(f"<li id='footnote_{index}'><p>{text}</p></li>\n")
275
+ lines.append("</ol>\n")
276
+
277
+ self._pages.append("".join(lines))
278
+
279
+ return
280
+
281
+ def saveDocument(self, path: Path) -> None:
282
+ """Save the data to an HTML file."""
283
+ if path.suffix.lower() == ".json":
284
+ ts = time()
285
+ data = {
286
+ "meta": {
287
+ "projectName": self._project.data.name,
288
+ "novelAuthor": self._project.data.author,
289
+ "buildTime": int(ts),
290
+ "buildTimeStr": formatTimeStamp(ts),
291
+ },
292
+ "text": {
293
+ "css": self.getStyleSheet(),
294
+ "html": [t.replace("\t", "&#09;").rstrip().split("\n") for t in self._pages],
295
+ }
296
+ }
297
+ with open(path, mode="w", encoding="utf-8") as fObj:
298
+ json.dump(data, fObj, indent=2)
299
+
300
+ else:
301
+ with open(path, mode="w", encoding="utf-8") as fObj:
302
+ fObj.write((
303
+ "<!DOCTYPE html>\n"
304
+ "<html>\n"
305
+ "<head>\n"
306
+ "<meta charset='utf-8'>\n"
307
+ "<title>{title:s}</title>\n"
308
+ "<style>\n"
309
+ "{style:s}\n"
310
+ "</style>\n"
311
+ "</head>\n"
312
+ "<body>\n"
313
+ "<article>\n"
314
+ "{body:s}\n"
315
+ "</article>\n"
316
+ "</body>\n"
317
+ "</html>\n"
318
+ ).format(
319
+ title=self._project.data.name,
320
+ style="\n".join(self.getStyleSheet()),
321
+ body=("".join(self._pages)).replace("\t", "&#09;").rstrip(),
322
+ ))
323
+
324
+ logger.info("Wrote file: %s", path)
325
+
326
+ return
327
+
328
+ def replaceTabs(self, nSpaces: int = 8, spaceChar: str = "&nbsp;") -> None:
329
+ """Replace tabs with spaces in the html."""
330
+ pages = []
331
+ tabSpace = spaceChar*nSpaces
332
+ for aLine in self._pages:
333
+ pages.append(aLine.replace("\t", tabSpace))
334
+ self._pages = pages
335
+ return
336
+
337
+ def getStyleSheet(self) -> list[str]:
338
+ """Generate a stylesheet for the current settings."""
339
+ if not self._cssStyles:
340
+ return []
341
+
342
+ mScale = self._lineHeight/1.15
343
+ tColor = self._theme.text.name(QtHexRgb)
344
+ hColor = self._theme.head.name(QtHexRgb) if self._colorHeads else tColor
345
+ lColor = self._theme.head.name(QtHexRgb)
346
+ mColor = self._theme.highlight.name(QtHexRgb)
347
+
348
+ mtH0 = mScale * self._marginTitle[0]
349
+ mbH0 = mScale * self._marginTitle[1]
350
+ mtH1 = mScale * self._marginHead1[0]
351
+ mbH1 = mScale * self._marginHead1[1]
352
+ mtH2 = mScale * self._marginHead2[0]
353
+ mbH2 = mScale * self._marginHead2[1]
354
+ mtH3 = mScale * self._marginHead3[0]
355
+ mbH3 = mScale * self._marginHead3[1]
356
+ mtH4 = mScale * self._marginHead4[0]
357
+ mbH4 = mScale * self._marginHead4[1]
358
+ mtTT = mScale * self._marginText[0]
359
+ mbTT = mScale * self._marginText[1]
360
+ mtSP = mScale * self._marginSep[0]
361
+ mbSP = mScale * self._marginSep[1]
362
+
363
+ font = self._textFont
364
+ fFam = font.family()
365
+ fSz = font.pointSize()
366
+ fW = FONT_WEIGHTS.get(font.weight(), 400)
367
+ fS = FONT_STYLE.get(font.style(), "normal")
368
+
369
+ lHeight = round(100 * self._lineHeight)
370
+
371
+ styles = []
372
+ styles.append(
373
+ f"body {{color: {tColor}; font-family: '{fFam}'; font-size: {fSz}pt; "
374
+ f"font-weight: {fW}; font-style: {fS};}}"
375
+ )
376
+ styles.append(
377
+ f"p {{text-align: {self._defaultAlign}; line-height: {lHeight}%; "
378
+ f"margin-top: {mtTT:.2f}em; margin-bottom: {mbTT:.2f}em;}}"
379
+ )
380
+ styles.append(f"a {{color: {lColor};}}")
381
+ styles.append(f"mark {{background: {mColor};}}")
382
+ styles.append(f"h1, h2, h3, h4 {{color: {hColor}; page-break-after: avoid;}}")
383
+ styles.append(f"h1 {{margin-top: {mtH1:.2f}em; margin-bottom: {mbH1:.2f}em;}}")
384
+ styles.append(f"h2 {{margin-top: {mtH2:.2f}em; margin-bottom: {mbH2:.2f}em;}}")
385
+ styles.append(f"h3 {{margin-top: {mtH3:.2f}em; margin-bottom: {mbH3:.2f}em;}}")
386
+ styles.append(f"h4 {{margin-top: {mtH4:.2f}em; margin-bottom: {mbH4:.2f}em;}}")
387
+ styles.append(
388
+ f".title {{font-size: 2.5em; margin-top: {mtH0:.2f}em; margin-bottom: {mbH0:.2f}em;}}"
389
+ )
390
+ styles.append(
391
+ f".sep {{text-align: center; margin-top: {mtSP:.2f}em; margin-bottom: {mbSP:.2f}em;}}"
392
+ )
393
+
394
+ return styles
395
+
396
+ ##
397
+ # Internal Functions
398
+ ##
399
+
400
+ def _formatText(self, text: str, tFmt: T_Formats) -> str:
401
+ """Apply formatting tags to text."""
402
+ temp = text
403
+
404
+ # Build a list of all html tags that need to be inserted in the text.
405
+ # This is done in the forward direction, and a tag is only opened if it
406
+ # isn't already open, and only closed if it has previously been opened.
407
+ tags: list[tuple[int, str]] = []
408
+ state = dict.fromkeys(HTML_OPENER, False)
409
+ for pos, fmt, data in tFmt:
410
+ if m := HTML_OPENER.get(fmt):
411
+ if not state.get(fmt, True):
412
+ if fmt == TextFmt.COL_B and (color := self._classes.get(data)):
413
+ tags.append((pos, m[1].format(color.name(QtHexRgb))))
414
+ elif fmt in (TextFmt.ANM_B, TextFmt.ARF_B, TextFmt.HRF_B):
415
+ tags.append((pos, m[1].format(data or "#")))
416
+ else:
417
+ tags.append((pos, m[1]))
418
+ state[fmt] = True
419
+ elif m := HTML_CLOSER.get(fmt):
420
+ if state.get(m[0], False):
421
+ tags.append((pos, m[1]))
422
+ state[m[0]] = False
423
+ elif fmt == TextFmt.FNOTE:
424
+ if data in self._footnotes:
425
+ index = len(self._usedNotes) + 1
426
+ self._usedNotes[data] = index
427
+ tags.append((pos, f"<sup><a href='#footnote_{index}'>{index}</a></sup>"))
428
+ else:
429
+ tags.append((pos, "<sup>ERR</sup>"))
430
+ elif fmt == TextFmt.FIELD:
431
+ if field := data.partition(":")[2]:
432
+ self._usedFields.append((len(self._pages), field))
433
+ tags.append((pos, f"{{{{{field}}}}}"))
434
+
435
+ # Check all format types and close any tag that is still open. This
436
+ # ensures that unclosed tags don't spill over to the next paragraph.
437
+ end = len(text)
438
+ for opener, active in state.items():
439
+ if active:
440
+ closer = HTML_OPENER.get(opener, HTML_NONE)[0]
441
+ tags.append((end, HTML_CLOSER.get(closer, HTML_NONE)[1]))
442
+
443
+ # Insert all tags at their correct position, starting from the back.
444
+ # The reverse order ensures that the positions are not shifted while we
445
+ # insert tags.
446
+ for pos, tag in reversed(tags):
447
+ temp = f"{temp[:pos]}{tag}{temp[pos:]}"
448
+
449
+ # Replace all line breaks with proper HTML break tags
450
+ temp = temp.replace("\n", "<br>")
451
+
452
+ return stripEscape(temp)