From 148fc685902d524cc0be0c3960511fc28103382e Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Mon, 16 Jun 2025 18:46:37 +0200 Subject: [PATCH] Add markdown highlight format --- novelwriter/constants.py | 1 + novelwriter/formats/shared.py | 10 +++++++++- novelwriter/formats/tokenizer.py | 1 + novelwriter/gui/dochighlight.py | 19 ++++++++++++++++--- novelwriter/text/patterns.py | 6 ++++++ sample/content/636b6aa9b697b.nwd | 6 +++--- sample/nwProject.nwx | 8 ++++---- tests/test_formats/test_fmt_tokenizer.py | 5 +++++ 8 files changed, 45 insertions(+), 11 deletions(-) diff --git a/novelwriter/constants.py b/novelwriter/constants.py index 701ac5a1..e47455d8 100644 --- a/novelwriter/constants.py +++ b/novelwriter/constants.py @@ -77,6 +77,7 @@ class nwRegEx: FMT_EI = r"(? re.Pattern: + """Markdown highlight style.""" + return self._rxMark + @property def shortcodePlain(self) -> re.Pattern: """Plain shortcode style.""" diff --git a/sample/content/636b6aa9b697b.nwd b/sample/content/636b6aa9b697b.nwd index e3d4bfde..12f0d4e0 100644 --- a/sample/content/636b6aa9b697b.nwd +++ b/sample/content/636b6aa9b697b.nwd @@ -1,8 +1,8 @@ %%~name: Making a Scene %%~path: 6a2d6d5f4f401/636b6aa9b697b %%~kind: NOVEL/DOCUMENT -%%~hash: 1f3d98a6a27b4f9a7f2239fcd78f9e2263cd3b97 -%%~date: Unknown/2025-05-18 22:36:59 +%%~hash: b85f815702763f58926edd72a2eeed1df5e1cbc9 +%%~date: Unknown/2025-06-16 12:49:10 ### Making a Scene @pov: Jane @@ -15,7 +15,7 @@ A scene is defined by a level three heading, like the one at the top of this page. The scene will be assigned to the chapter preceding it in the project tree. The scene document can be sorted after the chapter document, or as a child of the chapter. Both result in the same output in the end, so it is a matter of preference. -Each paragraph in the scene is separated by a blank line. The text supports minimal formatting, like **bold**, _italic_ and **_bold italic_**. You can also ~~strike through~~ text. There is **some support for _nested_ emphasis**, but there are some known limitations. If the syntax highlighter doesn’t show it correctly, the export tool will not either. +Each paragraph in the scene is separated by a blank line. The text supports minimal formatting, like **bold**, _italic_ and **_bold italic_**. You can also ~~strike through~~ text. There is **some support for _nested_ emphasis**, but there are some known limitations. If the ==syntax highlighter== doesn’t show it correctly, the export tool will not either. For special formatting aside from standard emphasis, you can use “shortcodes”. Here we have super[sup]script[/sup] and sub[sub]script[/sub], and [b]part[/b]ial bold too, which ends in the middle of a word. The shortcodes also support [u]underline[/u], and you can [m]highlight text as well[/m]. diff --git a/sample/nwProject.nwx b/sample/nwProject.nwx index 32ed2662..587802ef 100644 --- a/sample/nwProject.nwx +++ b/sample/nwProject.nwx @@ -1,6 +1,6 @@ - - + + Sample Project Jane Smith @@ -36,7 +36,7 @@ Main - + Novel @@ -58,7 +58,7 @@ Chapter One - + Making a Scene diff --git a/tests/test_formats/test_fmt_tokenizer.py b/tests/test_formats/test_fmt_tokenizer.py index d141b6ef..2b053e1b 100644 --- a/tests/test_formats/test_fmt_tokenizer.py +++ b/tests/test_formats/test_fmt_tokenizer.py @@ -919,6 +919,11 @@ def testFmtToken_ExtractFormats(mockGUI): assert text == "Text with strikethrough in it." assert fmt == [(10, TextFmt.D_B, ""), (23, TextFmt.D_E, "")] + # Plain mark + text, fmt = tokens._extractFormats("Text with ==a highlight== in it.") + assert text == "Text with a highlight in it." + assert fmt == [(10, TextFmt.M_B, ""), (21, TextFmt.M_E, "")] + # Nested bold/italics text, fmt = tokens._extractFormats("Text with **bold and _italics_** in it.") assert text == "Text with bold and italics in it."