From 5a4b7b726471e41a1f4925df3bc57055310564c8 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Mon, 17 Oct 2022 20:08:19 +0200 Subject: [PATCH] Add a main heading variable to the NWItem class --- novelwriter/core/item.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/novelwriter/core/item.py b/novelwriter/core/item.py index 9901f39e..185d84fa 100644 --- a/novelwriter/core/item.py +++ b/novelwriter/core/item.py @@ -31,7 +31,7 @@ from novelwriter.enum import nwItemType, nwItemClass, nwItemLayout from novelwriter.common import ( checkInt, isHandle, isItemClass, isItemLayout, isItemType, simplified ) -from novelwriter.constants import nwLabels, trConst +from novelwriter.constants import nwHeaders, nwLabels, trConst logger = logging.getLogger(__name__) @@ -56,11 +56,12 @@ class NWItem: self._exported = True # Document Meta Data - self._charCount = 0 # Current character count - self._wordCount = 0 # Current word count - self._paraCount = 0 # Current paragraph count - self._cursorPos = 0 # Last cursor position - self._initCount = 0 # Initial word count + self._heading = "H0" # The main heading + self._charCount = 0 # Current character count + self._wordCount = 0 # Current word count + self._paraCount = 0 # Current paragraph count + self._cursorPos = 0 # Last cursor position + self._initCount = 0 # Initial word count return @@ -122,6 +123,10 @@ class NWItem: def isExported(self): return self._exported + @property + def mainHeading(self): + return self._heading + @property def charCount(self): return self._charCount @@ -162,6 +167,7 @@ class NWItem: metaAttrib = {} metaAttrib["expanded"] = str(self._expanded) if self._type == nwItemType.FILE: + metaAttrib["mainHeading"] = str(self._heading) metaAttrib["charCount"] = str(self._charCount) metaAttrib["wordCount"] = str(self._wordCount) metaAttrib["paraCount"] = str(self._paraCount) @@ -202,6 +208,7 @@ class NWItem: for xValue in xItem: if xValue.tag == "meta": self.setExpanded(xValue.attrib.get("expanded", False)) + self.setMainHeading(xValue.attrib.get("mainHeading", "H0")) self.setCharCount(xValue.attrib.get("charCount", 0)) self.setWordCount(xValue.attrib.get("wordCount", 0)) self.setParaCount(xValue.attrib.get("paraCount", 0)) @@ -511,6 +518,13 @@ class NWItem: # Set Document Meta Data ## + def setMainHeading(self, value): + """Set the main heading level. + """ + if value in nwHeaders.H_LEVEL: + self._heading = value + return + def setCharCount(self, count): """Set the character count, and ensure that it is an integer. """