Update ODT and DocX to work with new chapter headers

This commit is contained in:
Veronica Berglyd Olsen
2025-01-25 16:17:19 +01:00
parent 9ac1692e2a
commit 9f1274f953
7 changed files with 41 additions and 42 deletions
+15 -15
View File
@@ -58,8 +58,8 @@ def testFmtToDocX_HeadingStyles(mockGUI):
'<w:r><w:rPr /><w:t>Hello World</w:t></w:r></w:p></w:body>'
)
# Heading Level 1
# ===============
# Partition
# =========
doc._text = "# Hello World"
# Plain
@@ -68,7 +68,7 @@ def testFmtToDocX_HeadingStyles(mockGUI):
doc.doConvert()
doc._pars[-1].toXml(xTest)
assert xmlToText(xTest) == (
'<w:body><w:p><w:pPr><w:pStyle w:val="Heading1" /><w:jc w:val="center" /></w:pPr>'
'<w:body><w:p><w:pPr><w:pStyle w:val="Title" /><w:jc w:val="center" /></w:pPr>'
'<w:r><w:br w:type="page" /></w:r>'
'<w:r><w:rPr /><w:t>Hello World</w:t></w:r></w:p></w:body>'
)
@@ -80,13 +80,13 @@ def testFmtToDocX_HeadingStyles(mockGUI):
doc.doConvert()
doc._pars[-1].toXml(xTest)
assert xmlToText(xTest) == (
'<w:body><w:p><w:pPr><w:pStyle w:val="Heading1" /><w:jc w:val="center" /></w:pPr>'
'<w:body><w:p><w:pPr><w:pStyle w:val="Title" /><w:jc w:val="center" /></w:pPr>'
'<w:r><w:br w:type="page" /></w:r>'
'<w:r><w:rPr /><w:t>Part</w:t><w:br /><w:t>Hello World</w:t></w:r></w:p></w:body>'
)
# Heading Level 2
# ===============
# Chapter
# =======
doc._text = "## Hello World"
# Plain
@@ -95,7 +95,7 @@ def testFmtToDocX_HeadingStyles(mockGUI):
doc.doConvert()
doc._pars[-1].toXml(xTest)
assert xmlToText(xTest) == (
'<w:body><w:p><w:pPr><w:pStyle w:val="Heading2" /></w:pPr>'
'<w:body><w:p><w:pPr><w:pStyle w:val="Heading1" /></w:pPr>'
'<w:r><w:br w:type="page" /></w:r>'
'<w:r><w:rPr /><w:t>Hello World</w:t></w:r></w:p></w:body>'
)
@@ -107,13 +107,13 @@ def testFmtToDocX_HeadingStyles(mockGUI):
doc.doConvert()
doc._pars[-1].toXml(xTest)
assert xmlToText(xTest) == (
'<w:body><w:p><w:pPr><w:pStyle w:val="Heading2" /></w:pPr>'
'<w:body><w:p><w:pPr><w:pStyle w:val="Heading1" /></w:pPr>'
'<w:r><w:br w:type="page" /></w:r>'
'<w:r><w:rPr /><w:t>Chapter 2</w:t><w:br /><w:t>Hello World</w:t></w:r></w:p></w:body>'
)
# Heading Level 3
# ===============
# Scene
# =====
doc._text = "### Hello World"
# Plain
@@ -122,7 +122,7 @@ def testFmtToDocX_HeadingStyles(mockGUI):
doc.doConvert()
doc._pars[-1].toXml(xTest)
assert xmlToText(xTest) == (
'<w:body><w:p><w:pPr><w:pStyle w:val="Heading3" /></w:pPr><w:r><w:rPr />'
'<w:body><w:p><w:pPr><w:pStyle w:val="Heading2" /></w:pPr><w:r><w:rPr />'
'<w:t>Hello World</w:t></w:r></w:p></w:body>'
)
@@ -133,12 +133,12 @@ def testFmtToDocX_HeadingStyles(mockGUI):
doc.doConvert()
doc._pars[-1].toXml(xTest)
assert xmlToText(xTest) == (
'<w:body><w:p><w:pPr><w:pStyle w:val="Heading3" /></w:pPr>'
'<w:body><w:p><w:pPr><w:pStyle w:val="Heading2" /></w:pPr>'
'<w:r><w:rPr /><w:t>Scene 2</w:t><w:br /><w:t>Hello World</w:t></w:r></w:p></w:body>'
)
# Heading Level 4
# ===============
# Section
# =======
doc._text = "#### Hello World"
xTest = ET.Element(_wTag("body"))
@@ -146,7 +146,7 @@ def testFmtToDocX_HeadingStyles(mockGUI):
doc.doConvert()
doc._pars[-1].toXml(xTest)
assert xmlToText(xTest) == (
'<w:body><w:p><w:pPr><w:pStyle w:val="Heading4" /></w:pPr><w:r><w:rPr />'
'<w:body><w:p><w:pPr><w:pStyle w:val="Heading3" /></w:pPr><w:r><w:rPr />'
'<w:t>Hello World</w:t></w:r></w:p></w:body>'
)
+11 -12
View File
@@ -311,8 +311,7 @@ def testFmtToOdt_ConvertHeaders(mockGUI):
assert odt.errData == []
assert xmlToText(odt._xText) == (
'<office:text>'
'<text:h text:style-name="P1" text:outline-level="1">Part'
'<text:line-break />Title</text:h>'
'<text:p text:style-name="Title">Part<text:line-break />Title</text:p>'
'</office:text>'
)
@@ -326,7 +325,7 @@ def testFmtToOdt_ConvertHeaders(mockGUI):
assert odt.errData == []
assert xmlToText(odt._xText) == (
'<office:text>'
'<text:h text:style-name="P2" text:outline-level="2">Chapter 1'
'<text:h text:style-name="P1" text:outline-level="1">Chapter 1'
'<text:line-break />Title</text:h>'
'</office:text>'
)
@@ -341,7 +340,7 @@ def testFmtToOdt_ConvertHeaders(mockGUI):
assert odt.errData == []
assert xmlToText(odt._xText) == (
'<office:text>'
'<text:h text:style-name="Heading_20_3" text:outline-level="3">Scene 1'
'<text:h text:style-name="Heading_20_2" text:outline-level="2">Scene 1'
'<text:line-break />Title</text:h>'
'</office:text>'
)
@@ -355,7 +354,7 @@ def testFmtToOdt_ConvertHeaders(mockGUI):
assert odt.errData == []
assert xmlToText(odt._xText) == (
'<office:text>'
'<text:h text:style-name="Heading_20_4" text:outline-level="4">Title</text:h>'
'<text:h text:style-name="Heading_20_3" text:outline-level="3">Title</text:h>'
'</office:text>'
)
@@ -382,7 +381,7 @@ def testFmtToOdt_ConvertHeaders(mockGUI):
assert odt.errData == []
assert xmlToText(odt._xText) == (
'<office:text>'
'<text:h text:style-name="P2" text:outline-level="2">Prologue</text:h>'
'<text:h text:style-name="P1" text:outline-level="1">Prologue</text:h>'
'</office:text>'
)
@@ -522,7 +521,7 @@ def testFmtToOdt_ConvertParagraphs(mockGUI):
assert odt.errData == []
assert xmlToText(odt._xText) == (
'<office:text>'
'<text:h text:style-name="Heading_20_3" text:outline-level="3">Scene</text:h>'
'<text:h text:style-name="Heading_20_2" text:outline-level="2">Scene</text:h>'
'<text:p text:style-name="Text_20_body">Hello World</text:p>'
'<text:p text:style-name="Text_20_body">Hello <text:s />World</text:p>'
'<text:p text:style-name="Text_20_body">Hello <text:s text:c="2" />World</text:p>'
@@ -547,7 +546,7 @@ def testFmtToOdt_ConvertParagraphs(mockGUI):
assert odt.errData == []
assert xmlToText(odt._xText) == (
'<office:text>'
'<text:h text:style-name="Heading_20_3" text:outline-level="3">Scene</text:h>'
'<text:h text:style-name="Heading_20_2" text:outline-level="2">Scene</text:h>'
'<text:p text:style-name="Text_20_Meta"><text:span text:style-name="T10">'
'Point of View:</text:span> <text:span text:style-name="T11">Jane</text:span></text:p>'
'<text:p text:style-name="Text_20_Meta"><text:span text:style-name="T12">'
@@ -617,7 +616,7 @@ def testFmtToOdt_ConvertParagraphs(mockGUI):
assert odt.errData == []
assert xmlToText(odt._xText) == (
'<office:text>'
'<text:h text:style-name="Heading_20_3" text:outline-level="3">Scene</text:h>'
'<text:h text:style-name="Heading_20_2" text:outline-level="2">Scene</text:h>'
'<text:p text:style-name="P1"><text:span text:style-name="T10">'
'Point of View:</text:span> <text:span text:style-name="T11">Jane</text:span></text:p>'
'<text:p text:style-name="P2"><text:span text:style-name="T10">'
@@ -655,7 +654,7 @@ def testFmtToOdt_ConvertParagraphs(mockGUI):
assert odt.errData == []
assert xmlToText(odt._xText) == (
'<office:text>'
'<text:h text:style-name="Heading_20_3" text:outline-level="3">Scene</text:h>'
'<text:h text:style-name="Heading_20_2" text:outline-level="2">Scene</text:h>'
'<text:p text:style-name="P7">Regular paragraph</text:p>'
'<text:p text:style-name="Text_20_body">with<text:line-break />break</text:p>'
'<text:p text:style-name="Text_20_body">Left Align</text:p>'
@@ -677,9 +676,9 @@ def testFmtToOdt_ConvertParagraphs(mockGUI):
assert odt.errData == []
assert xmlToText(odt._xText) == (
'<office:text>'
'<text:h text:style-name="P8" text:outline-level="2">Chapter One</text:h>'
'<text:h text:style-name="P8" text:outline-level="1">Chapter One</text:h>'
'<text:p text:style-name="Text_20_body">Text</text:p>'
'<text:h text:style-name="P8" text:outline-level="2">Chapter Two</text:h>'
'<text:h text:style-name="P8" text:outline-level="1">Chapter Two</text:h>'
'<text:p text:style-name="Text_20_body">Text</text:p>'
'</office:text>'
)