Merge Novel Layouts (#837)
* Merge novel layouts and simplify the Tokenizer class * Fix core tests * Delete auto-layout code * Remove no longer needed item layouts * Remove references to deleted item layouts in test * Make some minor changes to Tokenizer class and update tests * Update test reference files * Update sample project * Fix a few issues with the Tokenizer * Centre some text in the sample documents * Make some minor changes to how new projects are generated * Add support for New Page and VSpace commands to the Tokenizer * Remove Title and Page layouts and add codes for page break and vertical space * Add document layout and fix some issues in index class with new title formats * Update tests and reference files * Bump the project file version and fix a minor issue in items class * Update tests and test coverage * Clean up some warnings and issues in tests
This commit is contained in:
committed by
GitHub
parent
c6973043e6
commit
bb1a778277
+1
-48
@@ -33,34 +33,11 @@ from hashlib import sha256
|
||||
|
||||
from nw.enum import nwItemType, nwItemClass, nwItemLayout
|
||||
from nw.common import checkHandle
|
||||
from nw.constants import nwConst, nwLists, nwFiles
|
||||
from nw.constants import nwConst, nwFiles
|
||||
from nw.core.item import NWItem
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# Layout Translation Map
|
||||
LAYOUT_MAP = {
|
||||
nwItemLayout.SCENE: {
|
||||
"H1": nwItemLayout.BOOK,
|
||||
"H2": nwItemLayout.CHAPTER,
|
||||
},
|
||||
nwItemLayout.CHAPTER: {
|
||||
"H1": nwItemLayout.BOOK,
|
||||
"H3": nwItemLayout.SCENE,
|
||||
"H4": nwItemLayout.SCENE,
|
||||
},
|
||||
nwItemLayout.UNNUMBERED: {
|
||||
"H1": nwItemLayout.BOOK,
|
||||
"H3": nwItemLayout.SCENE,
|
||||
"H4": nwItemLayout.SCENE,
|
||||
},
|
||||
nwItemLayout.PARTITION: {
|
||||
"H2": nwItemLayout.CHAPTER,
|
||||
"H3": nwItemLayout.SCENE,
|
||||
"H4": nwItemLayout.SCENE,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
class NWTree():
|
||||
|
||||
@@ -229,30 +206,6 @@ class NWTree():
|
||||
novelWords += tItem.wordCount
|
||||
return novelWords, noteWords
|
||||
|
||||
def updateItemLayout(self, tHandle, hLevel):
|
||||
"""Check if the item layout needs updating based on the header
|
||||
given level.
|
||||
"""
|
||||
tItem = self.__getitem__(tHandle)
|
||||
if tItem is None:
|
||||
return False
|
||||
if tItem.itemClass not in nwLists.CLS_NOVEL:
|
||||
return False
|
||||
if hLevel not in ("H1", "H2", "H3", "H4"):
|
||||
return False
|
||||
|
||||
iLayout = tItem.itemLayout
|
||||
if iLayout in LAYOUT_MAP:
|
||||
if hLevel in LAYOUT_MAP[iLayout]:
|
||||
tItem.itemLayout = LAYOUT_MAP[iLayout][hLevel]
|
||||
logger.debug(
|
||||
"Changed layout for %s from %s to %s",
|
||||
tHandle, iLayout.name, tItem.itemLayout.name
|
||||
)
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
##
|
||||
# Tree Structure Methods
|
||||
##
|
||||
|
||||
Reference in New Issue
Block a user