diff --git a/novelwriter/formats/todocx.py b/novelwriter/formats/todocx.py index 366191ef..1c7a2a1f 100644 --- a/novelwriter/formats/todocx.py +++ b/novelwriter/formats/todocx.py @@ -38,7 +38,7 @@ from novelwriter import __version__ from novelwriter.common import firstFloat, xmlElement, xmlSubElem from novelwriter.constants import nwHeadFmt, nwStyles from novelwriter.formats.shared import BlockFmt, BlockTyp, T_Formats, TextFmt, stripEscape -from novelwriter.formats.tokenizer import Tokenizer +from novelwriter.formats.tokenizer import COMMENT_BLOCKS, Tokenizer from novelwriter.types import QtHexRgb if TYPE_CHECKING: @@ -296,7 +296,7 @@ class ToDocX(Tokenizer): elif tType == BlockTyp.SKIP: self._processFragments(par, S_NORM, "") - elif tType == BlockTyp.COMMENT: + elif tType in COMMENT_BLOCKS: self._processFragments(par, S_META, tText, tFormat) elif tType == BlockTyp.KEYWORD: diff --git a/novelwriter/formats/tohtml.py b/novelwriter/formats/tohtml.py index 404c6d09..4614050a 100644 --- a/novelwriter/formats/tohtml.py +++ b/novelwriter/formats/tohtml.py @@ -32,7 +32,7 @@ from typing import TYPE_CHECKING from novelwriter.common import formatTimeStamp from novelwriter.constants import nwHtmlUnicode, nwStyles from novelwriter.formats.shared import BlockFmt, BlockTyp, T_Formats, TextFmt, stripEscape -from novelwriter.formats.tokenizer import Tokenizer +from novelwriter.formats.tokenizer import COMMENT_BLOCKS, Tokenizer from novelwriter.types import FONT_STYLE, FONT_WEIGHTS, QtHexRgb if TYPE_CHECKING: @@ -228,7 +228,7 @@ class ToHtml(Tokenizer): elif tType == BlockTyp.SKIP: lines.append(f"
\n") - elif tType == BlockTyp.COMMENT: + elif tType in COMMENT_BLOCKS: lines.append(f"
{self._formatText(tText, tFmt)}
\n") elif tType == BlockTyp.KEYWORD: diff --git a/novelwriter/formats/tokenizer.py b/novelwriter/formats/tokenizer.py index ca1f20a8..984a3d71 100644 --- a/novelwriter/formats/tokenizer.py +++ b/novelwriter/formats/tokenizer.py @@ -71,11 +71,23 @@ COMMENT_STYLE = { nwComment.COMMENT: ComStyle(), nwComment.STORY: ComStyle("Story Structure", "modifier", "note"), } -HEADINGS = [ +COMMENT_TYPE = { + nwComment.PLAIN: BlockTyp.COMMENT, + nwComment.IGNORE: BlockTyp.COMMENT, + nwComment.SYNOPSIS: BlockTyp.SUMMARY, + nwComment.SHORT: BlockTyp.SUMMARY, + nwComment.NOTE: BlockTyp.NOTE, + nwComment.FOOTNOTE: BlockTyp.COMMENT, + nwComment.COMMENT: BlockTyp.COMMENT, + nwComment.STORY: BlockTyp.NOTE, +} +HEADING_BLOCKS = [ BlockTyp.TITLE, BlockTyp.PART, BlockTyp.HEAD1, BlockTyp.HEAD2, BlockTyp.HEAD3, BlockTyp.HEAD4, ] -SKIP_INDENT = [*HEADINGS, BlockTyp.SEP, BlockTyp.SKIP] +COMMENT_BLOCKS = (BlockTyp.COMMENT, BlockTyp.SUMMARY, BlockTyp.NOTE) +META_BLOCKS = (BlockTyp.COMMENT, BlockTyp.SUMMARY, BlockTyp.NOTE, BlockTyp.KEYWORD) +SKIP_INDENT = [*HEADING_BLOCKS, BlockTyp.SEP, BlockTyp.SKIP] B_EMPTY: T_Block = (BlockTyp.EMPTY, "", "", [], BlockFmt.NONE) @@ -619,7 +631,7 @@ class Tokenizer(ABC): bStyle = COMMENT_STYLE[cStyle] tLine, tFmt = self._formatComment(bStyle, cKey, cText) tBlocks.append(( - BlockTyp.COMMENT, "", tLine, tFmt, tStyle + COMMENT_TYPE[cStyle], "", tLine, tFmt, tStyle )) elif cStyle == nwComment.FOOTNOTE: @@ -990,7 +1002,7 @@ class Tokenizer(ABC): allWordChars += nPWChars textWordChars += nPWChars - elif tType in HEADINGS: + elif tType in HEADING_BLOCKS: titleCount += 1 allWords += nWords titleWords += nWords @@ -1004,7 +1016,7 @@ class Tokenizer(ABC): allChars += nChars allWordChars += nWChars - elif tType in (BlockTyp.COMMENT, BlockTyp.KEYWORD): + elif tType in META_BLOCKS: words = tText.split() allWords += len(words) allChars += len(tText) diff --git a/novelwriter/formats/tomarkdown.py b/novelwriter/formats/tomarkdown.py index b87d0325..0b477302 100644 --- a/novelwriter/formats/tomarkdown.py +++ b/novelwriter/formats/tomarkdown.py @@ -29,7 +29,7 @@ from typing import TYPE_CHECKING from novelwriter.constants import nwUnicode from novelwriter.formats.shared import BlockFmt, BlockTyp, T_Formats, TextFmt -from novelwriter.formats.tokenizer import Tokenizer +from novelwriter.formats.tokenizer import COMMENT_BLOCKS, Tokenizer if TYPE_CHECKING: from pathlib import Path @@ -144,7 +144,7 @@ class ToMarkdown(Tokenizer): elif tType == BlockTyp.SKIP: lines.append(f"{cSkip}\n\n") - elif tType == BlockTyp.COMMENT: + elif tType in COMMENT_BLOCKS: lines.append(f"{self._formatText(tText, tFormat, mTags)}\n\n") elif tType == BlockTyp.KEYWORD: diff --git a/novelwriter/formats/toodt.py b/novelwriter/formats/toodt.py index 15622845..ddd554ba 100644 --- a/novelwriter/formats/toodt.py +++ b/novelwriter/formats/toodt.py @@ -40,7 +40,7 @@ from novelwriter import __version__ from novelwriter.common import xmlElement, xmlIndent, xmlSubElem from novelwriter.constants import nwHeadFmt, nwStyles from novelwriter.formats.shared import BlockFmt, BlockTyp, TextFmt, stripEscape -from novelwriter.formats.tokenizer import Tokenizer +from novelwriter.formats.tokenizer import COMMENT_BLOCKS, Tokenizer from novelwriter.types import FONT_STYLE, QtHexRgb if TYPE_CHECKING: @@ -389,7 +389,7 @@ class ToOdt(Tokenizer): elif tType == BlockTyp.SKIP: self._addTextPar(xText, S_TEXT, oStyle, "") - elif tType == BlockTyp.COMMENT: + elif tType in COMMENT_BLOCKS: self._addTextPar(xText, S_META, oStyle, tText, tFmt=tFormat) elif tType == BlockTyp.KEYWORD: diff --git a/novelwriter/formats/toqdoc.py b/novelwriter/formats/toqdoc.py index 69c25fa4..28186b69 100644 --- a/novelwriter/formats/toqdoc.py +++ b/novelwriter/formats/toqdoc.py @@ -37,7 +37,7 @@ from PyQt6.QtPrintSupport import QPrinter from novelwriter import __version__ from novelwriter.constants import nwStyles, nwUnicode from novelwriter.formats.shared import BlockFmt, BlockTyp, T_Formats, TextFmt, stripEscape -from novelwriter.formats.tokenizer import HEADINGS, Tokenizer +from novelwriter.formats.tokenizer import HEADING_BLOCKS, META_BLOCKS, Tokenizer from novelwriter.types import ( QtAlignAbsolute, QtAlignCenter, QtAlignJustify, QtAlignLeft, QtAlignRight, QtKeepAnchor, QtMoveAnchor, QtPageBreakAfter, QtPageBreakAuto, @@ -214,7 +214,7 @@ class ToQTextDocument(Tokenizer): for tType, tMeta, tText, tFormat, tStyle in self._blocks: bFmt = QTextBlockFormat(self._blockFmt) - if tType in (BlockTyp.COMMENT, BlockTyp.KEYWORD): + if tType in META_BLOCKS: bFmt.setTopMargin(self._mMeta[0]) bFmt.setBottomMargin(self._mMeta[1]) elif tType == BlockTyp.SEP: @@ -248,17 +248,21 @@ class ToQTextDocument(Tokenizer): if tStyle & BlockFmt.IND_T: bFmt.setTextIndent(self._tIndent) - if tType in (BlockTyp.TEXT, BlockTyp.COMMENT, BlockTyp.KEYWORD): + if tType == BlockTyp.TEXT: newBlock(cursor, bFmt) self._insertFragments(tText, tFormat, cursor, self._charFmt) - elif tType in HEADINGS: + elif tType in HEADING_BLOCKS: bFmt, cFmt = self._genHeadStyle(tType, tMeta, bFmt) for tPart in tText.split("\n"): newBlock(cursor, bFmt) cursor.insertText(tPart, cFmt) bFmt.setPageBreakPolicy(QtPageBreakAuto) + elif tType in META_BLOCKS: + newBlock(cursor, bFmt) + self._insertFragments(tText, tFormat, cursor, self._charFmt) + elif tType == BlockTyp.SEP: newBlock(cursor, bFmt) cursor.insertText(tText, self._charFmt) diff --git a/tests/reference/baseConfig_novelwriter.conf b/tests/reference/baseConfig_novelwriter.conf index 859cca52..c3a45e6a 100644 --- a/tests/reference/baseConfig_novelwriter.conf +++ b/tests/reference/baseConfig_novelwriter.conf @@ -83,6 +83,7 @@ showedittoolbar = False showsessiontime = True viewcomments = True viewsynopsis = True +viewnotes = True searchcase = False searchword = False searchregex = False diff --git a/tests/test_formats/test_fmt_tokenizer.py b/tests/test_formats/test_fmt_tokenizer.py index 62fe24bd..2b589ccc 100644 --- a/tests/test_formats/test_fmt_tokenizer.py +++ b/tests/test_formats/test_fmt_tokenizer.py @@ -783,7 +783,7 @@ def testFmtToken_MetaFormat(mockGUI): tokens._text = "% synopsis: The synopsis\n" tokens.tokenizeText() assert tokens._blocks == [( - BlockTyp.COMMENT, "", "Synopsis: The synopsis", [ + BlockTyp.SUMMARY, "", "Synopsis: The synopsis", [ (0, TextFmt.B_B, ""), (0, TextFmt.COL_B, "modifier"), (9, TextFmt.COL_E, ""), (9, TextFmt.B_E, ""), (10, TextFmt.COL_B, "note"), (22, TextFmt.COL_E, "") @@ -800,7 +800,7 @@ def testFmtToken_MetaFormat(mockGUI): tokens._text = "% short: A short description\n" tokens.tokenizeText() assert tokens._blocks == [( - BlockTyp.COMMENT, "", "Short Description: A short description", [ + BlockTyp.SUMMARY, "", "Short Description: A short description", [ (0, TextFmt.B_B, ""), (0, TextFmt.COL_B, "modifier"), (18, TextFmt.COL_E, ""), (18, TextFmt.B_E, ""), (19, TextFmt.COL_B, "note"), (38, TextFmt.COL_E, ""), @@ -1563,7 +1563,7 @@ def testFmtToken_TextIndent(mockGUI): ] assert tokens._blocks == [ (BlockTyp.HEAD3, TM1, "Scene Two", [], BlockFmt.NONE), - (BlockTyp.COMMENT, "", "Synopsis: Stuff happens.", tFmt, BlockFmt.NONE), + (BlockTyp.SUMMARY, "", "Synopsis: Stuff happens.", tFmt, BlockFmt.NONE), ] assert tokens._noIndent is True