Drop separate types for chapters, scenes and sections as they seem to not be needed

This commit is contained in:
Veronica Berglyd Olsen
2025-01-25 16:11:57 +01:00
parent 6f88357977
commit 9ac1692e2a
8 changed files with 74 additions and 78 deletions
+11 -14
View File
@@ -105,20 +105,17 @@ class BlockTyp(IntEnum):
EMPTY = 1 # Empty line (new paragraph)
TITLE = 2 # Title
PART = 3 # Partition
CHAPTER = 4 # Chapter
SCENE = 5 # Scene
SECTION = 6 # Section
HEAD1 = 7 # Heading 1
HEAD2 = 8 # Heading 2
HEAD3 = 9 # Heading 3
HEAD4 = 10 # Heading 4
TEXT = 11 # Text line
SEP = 12 # Scene separator
SKIP = 13 # Paragraph break
SUMMARY = 14 # Synopsis/short comment
NOTE = 15 # Note
COMMENT = 16 # Comment
KEYWORD = 17 # Tag/reference keywords
HEAD1 = 4 # Heading 1 or Chapter
HEAD2 = 5 # Heading 2 or Scene
HEAD3 = 6 # Heading 3 or Section
HEAD4 = 7 # Heading 4
TEXT = 8 # Text line
SEP = 9 # Scene separator
SKIP = 10 # Paragraph break
SUMMARY = 11 # Synopsis/short comment
NOTE = 12 # Note
COMMENT = 13 # Comment
KEYWORD = 14 # Tag/reference keywords
class BlockFmt(Flag):
+3 -3
View File
@@ -203,15 +203,15 @@ class ToHtml(Tokenizer):
tHead = tText.replace("\n", "<br>")
lines.append(f"<h1 class='title'{hStyle}>{aNm}{tHead}</h1>\n")
elif tType in (BlockTyp.HEAD1, BlockTyp.CHAPTER):
elif tType == BlockTyp.HEAD1:
tHead = tText.replace("\n", "<br>")
lines.append(f"<h1{hStyle}>{aNm}{tHead}</h1>\n")
elif tType in (BlockTyp.HEAD2, BlockTyp.SCENE):
elif tType == BlockTyp.HEAD2:
tHead = tText.replace("\n", "<br>")
lines.append(f"<h2{hStyle}>{aNm}{tHead}</h2>\n")
elif tType in (BlockTyp.HEAD3, BlockTyp.SECTION):
elif tType == BlockTyp.HEAD3:
tHead = tText.replace("\n", "<br>")
lines.append(f"<h3{hStyle}>{aNm}{tHead}</h3>\n")
+22 -17
View File
@@ -68,18 +68,9 @@ COMMENT_STYLE = {
nwComment.COMMENT: ComStyle(),
nwComment.STORY: ComStyle("", "modifier", "note"),
}
OUTLINE_CODE = {
BlockTyp.TITLE: "TT",
BlockTyp.PART: "PT",
BlockTyp.CHAPTER: "CH",
BlockTyp.SCENE: "SC",
BlockTyp.HEAD1: "H1",
BlockTyp.HEAD2: "H2",
BlockTyp.HEAD3: "H3",
}
HEADINGS = [
BlockTyp.TITLE, BlockTyp.PART, BlockTyp.CHAPTER, BlockTyp.SCENE, BlockTyp.SECTION,
BlockTyp.HEAD1, BlockTyp.HEAD2, BlockTyp.HEAD3, BlockTyp.HEAD4,
BlockTyp.TITLE, BlockTyp.PART, BlockTyp.HEAD1,
BlockTyp.HEAD2, BlockTyp.HEAD3, BlockTyp.HEAD4,
]
SKIP_INDENT = HEADINGS + [BlockTyp.SEP, BlockTyp.SKIP]
B_EMPTY: T_Block = (BlockTyp.EMPTY, "", "", [], BlockFmt.NONE)
@@ -697,7 +688,7 @@ class Tokenizer(ABC):
sHide = self._hideChapter if isPlain else self._hideUnNum
tFormat = self._fmtChapter if isPlain else self._fmtUnNum
if isNovel:
tType = BlockTyp.CHAPTER
tType = BlockTyp.HEAD1 # Promote
if isPlain:
self._hFormatter.incChapter()
if sHide:
@@ -732,7 +723,7 @@ class Tokenizer(ABC):
sHide = self._hideScene if isPlain else self._hideHScene
tFormat = self._fmtScene if isPlain else self._fmtHScene
if isNovel:
tType = BlockTyp.SCENE
tType = BlockTyp.HEAD2 # Promote
self._hFormatter.incScene()
if sHide:
tText = ""
@@ -764,7 +755,7 @@ class Tokenizer(ABC):
tText = aLine[5:].strip()
tType = BlockTyp.HEAD4
if isNovel:
tType = BlockTyp.SECTION
tType = BlockTyp.HEAD3 # Promote
if self._hideSection:
tText = ""
tType = BlockTyp.EMPTY
@@ -936,10 +927,24 @@ class Tokenizer(ABC):
def buildOutline(self) -> None:
"""Build an outline of the text up to level 3 headings."""
isNovel = self._isNovel
for tType, tKey, tText, _, _ in self._blocks:
if prefix := OUTLINE_CODE.get(tType):
text = tText.replace(nwHeadFmt.BR, " ").replace("&amp;", "&")
self._outline[tKey] = f"{prefix}|{text}"
if tType == BlockTyp.TITLE:
prefix = "TT"
elif tType == BlockTyp.PART:
prefix = "PT"
elif tType == BlockTyp.HEAD1:
prefix = "CH" if isNovel else "H1"
elif tType == BlockTyp.HEAD2:
prefix = "SC" if isNovel else "H2"
elif tType == BlockTyp.HEAD3 and not isNovel:
prefix = "H3"
else:
continue
text = tText.replace(nwHeadFmt.BR, " ").replace("&amp;", "&")
self._outline[tKey] = f"{prefix}|{text}"
return
def countStats(self) -> None:
+3 -3
View File
@@ -113,15 +113,15 @@ class ToMarkdown(Tokenizer):
tTemp = self._formatText(tText, tFormat, mTags).replace("\n", " \n")
lines.append(f"{tTemp}\n\n")
elif tType in (BlockTyp.TITLE, BlockTyp.HEAD1, BlockTyp.PART, BlockTyp.CHAPTER):
elif tType in (BlockTyp.TITLE, BlockTyp.PART, BlockTyp.HEAD1):
tHead = tText.replace("\n", " - ")
lines.append(f"# {tHead}\n\n")
elif tType in (BlockTyp.HEAD2, BlockTyp.SCENE):
elif tType == BlockTyp.HEAD2:
tHead = tText.replace("\n", " - ")
lines.append(f"## {tHead}\n\n")
elif tType in (BlockTyp.HEAD3, BlockTyp.SECTION):
elif tType == BlockTyp.HEAD3:
tHead = tText.replace("\n", " - ")
lines.append(f"### {tHead}\n\n")
+12 -18
View File
@@ -156,28 +156,22 @@ class ToQTextDocument(Tokenizer):
mPx = fPx * self._dpi/96.0
self._mHead = {
BlockTyp.TITLE: (fPx * self._marginTitle[0], fPx * self._marginTitle[1]),
BlockTyp.PART: (fPx * self._marginTitle[0], fPx * self._marginTitle[1]),
BlockTyp.HEAD1: (fPx * self._marginHead1[0], fPx * self._marginHead1[1]),
BlockTyp.CHAPTER: (fPx * self._marginHead1[0], fPx * self._marginHead1[1]),
BlockTyp.HEAD2: (fPx * self._marginHead2[0], fPx * self._marginHead2[1]),
BlockTyp.SCENE: (fPx * self._marginHead2[0], fPx * self._marginHead2[1]),
BlockTyp.HEAD3: (fPx * self._marginHead3[0], fPx * self._marginHead3[1]),
BlockTyp.SECTION: (fPx * self._marginHead3[0], fPx * self._marginHead3[1]),
BlockTyp.HEAD4: (fPx * self._marginHead4[0], fPx * self._marginHead4[1]),
BlockTyp.TITLE: (fPx * self._marginTitle[0], fPx * self._marginTitle[1]),
BlockTyp.PART: (fPx * self._marginTitle[0], fPx * self._marginTitle[1]),
BlockTyp.HEAD1: (fPx * self._marginHead1[0], fPx * self._marginHead1[1]),
BlockTyp.HEAD2: (fPx * self._marginHead2[0], fPx * self._marginHead2[1]),
BlockTyp.HEAD3: (fPx * self._marginHead3[0], fPx * self._marginHead3[1]),
BlockTyp.HEAD4: (fPx * self._marginHead4[0], fPx * self._marginHead4[1]),
}
hScale = self._scaleHeads
self._sHead = {
BlockTyp.TITLE: (nwStyles.H_SIZES.get(0, 1.0) * fPt) if hScale else fPt,
BlockTyp.PART: (nwStyles.H_SIZES.get(0, 1.0) * fPt) if hScale else fPt,
BlockTyp.HEAD1: (nwStyles.H_SIZES.get(1, 1.0) * fPt) if hScale else fPt,
BlockTyp.CHAPTER: (nwStyles.H_SIZES.get(1, 1.0) * fPt) if hScale else fPt,
BlockTyp.HEAD2: (nwStyles.H_SIZES.get(2, 1.0) * fPt) if hScale else fPt,
BlockTyp.SCENE: (nwStyles.H_SIZES.get(2, 1.0) * fPt) if hScale else fPt,
BlockTyp.HEAD3: (nwStyles.H_SIZES.get(3, 1.0) * fPt) if hScale else fPt,
BlockTyp.SECTION: (nwStyles.H_SIZES.get(3, 1.0) * fPt) if hScale else fPt,
BlockTyp.HEAD4: (nwStyles.H_SIZES.get(4, 1.0) * fPt) if hScale else fPt,
BlockTyp.TITLE: (nwStyles.H_SIZES.get(0, 1.0) * fPt) if hScale else fPt,
BlockTyp.PART: (nwStyles.H_SIZES.get(0, 1.0) * fPt) if hScale else fPt,
BlockTyp.HEAD1: (nwStyles.H_SIZES.get(1, 1.0) * fPt) if hScale else fPt,
BlockTyp.HEAD2: (nwStyles.H_SIZES.get(2, 1.0) * fPt) if hScale else fPt,
BlockTyp.HEAD3: (nwStyles.H_SIZES.get(3, 1.0) * fPt) if hScale else fPt,
BlockTyp.HEAD4: (nwStyles.H_SIZES.get(4, 1.0) * fPt) if hScale else fPt,
}
self._mText = (fPx * self._marginText[0], fPx * self._marginText[1])