Generalise heading comments

This commit is contained in:
Veronica Berglyd Olsen
2025-04-06 19:13:37 +02:00
parent c5afeda726
commit edc19187f0
5 changed files with 24 additions and 16 deletions
+9 -6
View File
@@ -386,10 +386,10 @@ class Index:
elif line.startswith("%"):
cStyle, cKey, cText, _, _ = processComment(line)
if cStyle in (nwComment.SYNOPSIS, nwComment.SHORT):
self._itemIndex.setHeadingSynopsis(tHandle, cTitle, cText)
elif cStyle == nwComment.FOOTNOTE:
if cStyle == nwComment.FOOTNOTE:
self._itemIndex.addNoteKey(tHandle, "footnotes", cKey)
else:
self._itemIndex.setHeadingComment(tHandle, cTitle, cStyle, cKey, cText)
# Count words for remaining text after last heading
if pTitle != TT_NONE:
@@ -1007,10 +1007,13 @@ class ItemIndex:
self._items[tHandle].setHeadingCounts(sTitle, cC, wC, pC)
return
def setHeadingSynopsis(self, tHandle: str, sTitle: str, text: str) -> None:
"""Set the synopsis text for a heading on a given item."""
def setHeadingComment(
self, tHandle: str, sTitle: str,
comment: nwComment, key: str, text: str,
) -> None:
"""Set a story comment for a heading on a given item."""
if tHandle in self._items:
self._items[tHandle].setHeadingSynopsis(sTitle, text)
self._items[tHandle].setHeadingComment(sTitle, comment, key, text)
return
def setHeadingTag(self, tHandle: str, sTitle: str, tagKey: str) -> None:
+8 -6
View File
@@ -34,6 +34,7 @@ from typing import TYPE_CHECKING, Literal
from novelwriter import CONFIG
from novelwriter.common import checkInt, isListInstance, isTitleTag
from novelwriter.constants import nwKeyWords, nwStyles
from novelwriter.enum import nwComment
if TYPE_CHECKING: # pragma: no cover
from novelwriter.core.index import TagsIndex
@@ -113,10 +114,10 @@ class IndexNode:
self._headings[sTitle].setCounts([cCount, wCount, pCount])
return
def setHeadingSynopsis(self, sTitle: str, text: str) -> None:
"""Set the synopsis text of a heading."""
def setHeadingComment(self, sTitle: str, comment: nwComment, key: str, text: str) -> None:
"""Set the comment text of a heading."""
if sTitle in self._headings:
self._headings[sTitle].setSynopsis(text)
self._headings[sTitle].setComment(comment, key, text)
return
def setHeadingTag(self, sTitle: str, tag: str) -> None:
@@ -302,9 +303,10 @@ class IndexHeading:
)
return
def setSynopsis(self, text: str) -> None:
"""Set the synopsis text and make sure it is a string."""
self._comments["summary"] = str(text)
def setComment(self, comment: nwComment, key: str, text: str) -> None:
"""Set the text for a comment and make sure it is a string."""
if comment in (nwComment.SHORT, nwComment.SYNOPSIS):
self._comments["summary"] = str(text)
return
def setTag(self, tag: str) -> None:
+2
View File
@@ -31,12 +31,14 @@ MODIFIERS = {
"short": nwComment.SHORT,
"note": nwComment.NOTE,
"footnote": nwComment.FOOTNOTE,
"story": nwComment.STORY,
}
KEY_REQ = {
"synopsis": 0, # Key not allowed
"short": 0, # Key not allowed
"note": 1, # Key optional
"footnote": 2, # Key required
"story": 2, # Key required
}