git.iko.soy/typeable/pandoc
on master help sign in
docbook reader: fix nesting of chapters and sections (#5864)

* Set dbBook to true when traversing a chapter too. Currently, a `<title/>` in a chapter and in a `<section/>` below that chapter have the same level if they're not inside a `<book/>`. This can happen in a multi-file book project. Also see the example at https://tdg.docbook.org/tdg/4.5/chapter.html Co-authored-by: Félix Baylac-Jacqué <felix@alternativebit.fr> * Add docbook-chapter test This tests nested `<section/>` and makes sure `<title/>` in the first `<section/>` below `<chapter/>` is one level deeper than the `<chapter/>`'s `<title/>`, also when not inside a `<book/>`. Co-authored-by: Félix Baylac-Jacqué <felix@alternativebit.fr>

commitc6e936dec2fc0f0e4d15b7c6f7c4ed6934dd233a authorFlorian Klink <flokli@flokli.de> dateWed 30 Oct 2019, 16:51 (7 years ago) parent080a3cd
5 files changed+51−1
pandoc.cabal+1 src/Text/Pandoc/Readers/DocBook.hs+1−1 test/Tests/Old.hs+2 test/docbook-chapter.docbook+30 test/docbook-chapter.native+17
pandoc.cabal+1
@@ -215,6 +215,7 @@ extra-source-files:
215215 test/command/3510-export.latex
216216 test/command/3510-src.hs
217217 test/command/3971b.tex
218+ test/docbook-chapter.docbook
218219 test/docbook-reader.docbook
219220 test/docbook-xref.docbook
220221 test/html-reader.html
src/Text/Pandoc/Readers/DocBook.hs+1−1
@@ -726,7 +726,7 @@ parseBlock (Elem e) =
726726 mapM parseGlossEntry (filterChildren (named "glossentry") e)
727727 "glosslist" -> definitionList <$>
728728 mapM parseGlossEntry (filterChildren (named "glossentry") e)
729− "chapter" -> sect 0
729+ "chapter" -> modify (\st -> st{ dbBook = True}) >> sect 0
730730 "appendix" -> sect 0
731731 "preface" -> sect 0
732732 "bridgehead" -> para . strong <$> getInlines e
test/Tests/Old.hs+2
@@ -85,6 +85,8 @@ tests pandocPath =
8585 [ testGroup "writer" $ writerTests' "docbook4"
8686 , test' "reader" ["-r", "docbook", "-w", "native", "-s"]
8787 "docbook-reader.docbook" "docbook-reader.native"
88+ , test' "reader" ["-r", "docbook", "-w", "native", "-s"]
89+ "docbook-chapter.docbook" "docbook-chapter.native"
8890 , test' "reader" ["-r", "docbook", "-w", "native", "-s"]
8991 "docbook-xref.docbook" "docbook-xref.native"
9092 ]
test/docbook-chapter.docbooknew file+30
@@ -0,0 +1,30 @@
1+<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
2+ "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">
3+<!-- This matches the example from
4+https://tdg.docbook.org/tdg/4.5/section.html, sans sectioninfo and subtitle, as
5+they're currently not supported -->
6+<chapter><title>Test Chapter</title>
7+<para>This chapter uses recursive sections.</para>
8+<section>
9+<title>Like a Sect1</title>
10+<para>This section is like a Sect1.</para>
11+<section><title>Like a Sect2</title>
12+<para>This section is like a Sect2.</para>
13+<section><title>Like a Sect3</title>
14+<para>This section is like a Sect3.</para>
15+<section><title>Like a Sect4</title>
16+<para>This section is like a Sect4.</para>
17+<section><title>Like a Sect5</title>
18+<para>This section is like a Sect5.</para>
19+<section><title>Would be like a Sect6</title>
20+<para>This section would be like a Sect6, if there was one.</para>
21+<section><title>Would be like a Sect7</title>
22+<para>This section would be like a Sect7, if there was one.</para>
23+</section>
24+</section>
25+</section>
26+</section>
27+</section>
28+</section>
29+</section>
30+</chapter>
test/docbook-chapter.nativenew file+17
@@ -0,0 +1,17 @@
1+Pandoc (Meta {unMeta = fromList []})
2+[Header 1 ("",[],[]) [Str "Test",Space,Str "Chapter"]
3+,Para [Str "This",Space,Str "chapter",Space,Str "uses",Space,Str "recursive",Space,Str "sections."]
4+,Header 2 ("",[],[]) [Str "Like",Space,Str "a",Space,Str "Sect1"]
5+,Para [Str "This",Space,Str "section",Space,Str "is",Space,Str "like",Space,Str "a",Space,Str "Sect1."]
6+,Header 3 ("",[],[]) [Str "Like",Space,Str "a",Space,Str "Sect2"]
7+,Para [Str "This",Space,Str "section",Space,Str "is",Space,Str "like",Space,Str "a",Space,Str "Sect2."]
8+,Header 4 ("",[],[]) [Str "Like",Space,Str "a",Space,Str "Sect3"]
9+,Para [Str "This",Space,Str "section",Space,Str "is",Space,Str "like",Space,Str "a",Space,Str "Sect3."]
10+,Header 5 ("",[],[]) [Str "Like",Space,Str "a",Space,Str "Sect4"]
11+,Para [Str "This",Space,Str "section",Space,Str "is",Space,Str "like",Space,Str "a",Space,Str "Sect4."]
12+,Header 6 ("",[],[]) [Str "Like",Space,Str "a",Space,Str "Sect5"]
13+,Para [Str "This",Space,Str "section",Space,Str "is",Space,Str "like",Space,Str "a",Space,Str "Sect5."]
14+,Header 7 ("",[],[]) [Str "Would",Space,Str "be",Space,Str "like",Space,Str "a",Space,Str "Sect6"]
15+,Para [Str "This",Space,Str "section",Space,Str "would",Space,Str "be",Space,Str "like",Space,Str "a",Space,Str "Sect6,",Space,Str "if",Space,Str "there",Space,Str "was",Space,Str "one."]
16+,Header 8 ("",[],[]) [Str "Would",Space,Str "be",Space,Str "like",Space,Str "a",Space,Str "Sect7"]
17+,Para [Str "This",Space,Str "section",Space,Str "would",Space,Str "be",Space,Str "like",Space,Str "a",Space,Str "Sect7,",Space,Str "if",Space,Str "there",Space,Str "was",Space,Str "one."]]