git.iko.soy/typeable/pandoc
on master help sign in
Docbook writer: Use sect1, sect2, etc. instead of section.
commit663cfc2fbd0ff83f74dcde53e3cc98130fb645e0 authorJohn MacFarlane <fiddlosopher@gmail.com> dateFri 27 Jan 2012, 11:30 (15 years ago) parent259dda2
2 files changed+73−71
src/Text/Pandoc/Writers/Docbook.hs+11−9 tests/writer.docbook+62−62
src/Text/Pandoc/Writers/Docbook.hs+11−9
@@ -69,11 +69,12 @@ writeDocbook opts (Pandoc (Meta tit auths dat) blocks) =
6969 then Just $ writerColumns opts
7070 else Nothing
7171 render' = render colwidth
72− opts' = if "</book>" `isSuffixOf`
72+ opts' = if "/book>" `isSuffixOf`
7373 (removeTrailingSpace $ writerTemplate opts)
7474 then opts{ writerChapters = True }
7575 else opts
76− main = render' $ vcat (map (elementToDocbook opts') elements)
76+ startLvl = if writerChapters opts' then 0 else 1
77+ main = render' $ vcat (map (elementToDocbook opts' startLvl) elements)
7778 context = writerVariables opts ++
7879 [ ("body", main)
7980 , ("title", render' title)
@@ -84,19 +85,20 @@ writeDocbook opts (Pandoc (Meta tit auths dat) blocks) =
8485 else main
8586
8687-- | Convert an Element to Docbook.
87−elementToDocbook :: WriterOptions -> Element -> Doc
88−elementToDocbook opts (Blk block) = blockToDocbook opts block
89−elementToDocbook opts (Sec _ _num id' title elements) =
88+elementToDocbook :: WriterOptions -> Int -> Element -> Doc
89+elementToDocbook opts _ (Blk block) = blockToDocbook opts block
90+elementToDocbook opts lvl (Sec _ _num id' title elements) =
9091 -- Docbook doesn't allow sections with no content, so insert some if needed
9192 let elements' = if null elements
9293 then [Blk (Para [])]
9394 else elements
94− tag = if writerChapters opts
95− then "chapter"
96− else "section"
95+ tag = case lvl of
96+ n | n == 0 -> "chapter"
97+ | n >= 1 && n <= 5 -> "sect" ++ show n
98+ | otherwise -> "simplesect"
9799 in inTags True tag [("id",id')] $
98100 inTagsSimple "title" (inlinesToDocbook opts title) $$
99− vcat (map (elementToDocbook opts{ writerChapters = False }) elements')
101+ vcat (map (elementToDocbook opts (lvl + 1)) elements')
100102
101103-- | Convert a list of Pandoc blocks to Docbook.
102104blocksToDocbook :: WriterOptions -> [Block] -> Doc
tests/writer.docbook+62−62
@@ -18,42 +18,42 @@
1818 This is a set of tests for pandoc. Most of them are adapted from John
1919 Gruber’s markdown test suite.
2020</para>
21−<section id="headers">
21+<sect1 id="headers">
2222 <title>Headers</title>
23− <section id="level-2-with-an-embedded-link">
23+ <sect2 id="level-2-with-an-embedded-link">
2424 <title>Level 2 with an <ulink url="/url">embedded link</ulink></title>
25− <section id="level-3-with-emphasis">
25+ <sect3 id="level-3-with-emphasis">
2626 <title>Level 3 with <emphasis>emphasis</emphasis></title>
27− <section id="level-4">
27+ <sect4 id="level-4">
2828 <title>Level 4</title>
29− <section id="level-5">
29+ <sect5 id="level-5">
3030 <title>Level 5</title>
3131 <para>
3232 </para>
33− </section>
34− </section>
35− </section>
36− </section>
37−</section>
38−<section id="level-1">
33+ </sect5>
34+ </sect4>
35+ </sect3>
36+ </sect2>
37+</sect1>
38+<sect1 id="level-1">
3939 <title>Level 1</title>
40− <section id="level-2-with-emphasis">
40+ <sect2 id="level-2-with-emphasis">
4141 <title>Level 2 with <emphasis>emphasis</emphasis></title>
42− <section id="level-3">
42+ <sect3 id="level-3">
4343 <title>Level 3</title>
4444 <para>
4545 with no blank line
4646 </para>
47− </section>
48− </section>
49− <section id="level-2">
47+ </sect3>
48+ </sect2>
49+ <sect2 id="level-2">
5050 <title>Level 2</title>
5151 <para>
5252 with no blank line
5353 </para>
54− </section>
55−</section>
56−<section id="paragraphs">
54+ </sect2>
55+</sect1>
56+<sect1 id="paragraphs">
5757 <title>Paragraphs</title>
5858 <para>
5959 Here’s a regular paragraph.
@@ -69,8 +69,8 @@
6969 <para>
7070 There should be a hard line break<literallayout></literallayout>here.
7171 </para>
72−</section>
73−<section id="block-quotes">
72+</sect1>
73+<sect1 id="block-quotes">
7474 <title>Block Quotes</title>
7575 <para>
7676 E-mail style:
@@ -124,8 +124,8 @@ sub status {
124124 <para>
125125 And a following paragraph.
126126 </para>
127−</section>
128−<section id="code-blocks">
127+</sect1>
128+<sect1 id="code-blocks">
129129 <title>Code Blocks</title>
130130 <para>
131131 Code:
@@ -147,10 +147,10 @@ this code block is indented by one tab
147147
148148These should not be escaped: \$ \\ \&gt; \[ \{
149149</programlisting>
150−</section>
151−<section id="lists">
150+</sect1>
151+<sect1 id="lists">
152152 <title>Lists</title>
153− <section id="unordered">
153+ <sect2 id="unordered">
154154 <title>Unordered</title>
155155 <para>
156156 Asterisks tight:
@@ -272,8 +272,8 @@ These should not be escaped: \$ \\ \&gt; \[ \{
272272 </para>
273273 </listitem>
274274 </itemizedlist>
275− </section>
276− <section id="ordered">
275+ </sect2>
276+ <sect2 id="ordered">
277277 <title>Ordered</title>
278278 <para>
279279 Tight:
@@ -379,8 +379,8 @@ These should not be escaped: \$ \\ \&gt; \[ \{
379379 </para>
380380 </listitem>
381381 </orderedlist>
382− </section>
383− <section id="nested">
382+ </sect2>
383+ <sect2 id="nested">
384384 <title>Nested</title>
385385 <itemizedlist>
386386 <listitem>
@@ -477,8 +477,8 @@ These should not be escaped: \$ \\ \&gt; \[ \{
477477 </para>
478478 </listitem>
479479 </orderedlist>
480− </section>
481− <section id="tabs-and-spaces">
480+ </sect2>
481+ <sect2 id="tabs-and-spaces">
482482 <title>Tabs and spaces</title>
483483 <itemizedlist>
484484 <listitem>
@@ -504,8 +504,8 @@ These should not be escaped: \$ \\ \&gt; \[ \{
504504 </itemizedlist>
505505 </listitem>
506506 </itemizedlist>
507− </section>
508− <section id="fancy-list-markers">
507+ </sect2>
508+ <sect2 id="fancy-list-markers">
509509 <title>Fancy list markers</title>
510510 <orderedlist numeration="arabic">
511511 <listitem override="2">
@@ -608,9 +608,9 @@ These should not be escaped: \$ \\ \&gt; \[ \{
608608 <para>
609609 B. Williams
610610 </para>
611− </section>
612−</section>
613−<section id="definition-lists">
611+ </sect2>
612+</sect1>
613+<sect1 id="definition-lists">
614614 <title>Definition Lists</title>
615615 <para>
616616 Tight using spaces:
@@ -855,8 +855,8 @@ These should not be escaped: \$ \\ \&gt; \[ \{
855855 </listitem>
856856 </varlistentry>
857857 </variablelist>
858−</section>
859−<section id="html-blocks">
858+</sect1>
859+<sect1 id="html-blocks">
860860 <title>HTML Blocks</title>
861861 <para>
862862 Simple block on one line:
@@ -975,8 +975,8 @@ These should not be escaped: \$ \\ \&gt; \[ \{
975975 <hr class="foo" id="bar" />
976976
977977 <hr class="foo" id="bar">
978−</section>
979−<section id="inline-markup">
978+</sect1>
979+<sect1 id="inline-markup">
980980 <title>Inline Markup</title>
981981 <para>
982982 This is <emphasis>emphasized</emphasis>, and so <emphasis>is
@@ -1025,8 +1025,8 @@ These should not be escaped: \$ \\ \&gt; \[ \{
10251025 These should not be superscripts or subscripts, because of the unescaped
10261026 spaces: a^b c^d, a~b c~d.
10271027 </para>
1028−</section>
1029−<section id="smart-quotes-ellipses-dashes">
1028+</sect1>
1029+<sect1 id="smart-quotes-ellipses-dashes">
10301030 <title>Smart quotes, ellipses, dashes</title>
10311031 <para>
10321032 <quote>Hello,</quote> said the spider. <quote><quote>Shelob</quote> is my
@@ -1057,8 +1057,8 @@ These should not be escaped: \$ \\ \&gt; \[ \{
10571057 <para>
10581058 Ellipses…and…and….
10591059 </para>
1060−</section>
1061−<section id="latex">
1060+</sect1>
1061+<sect1 id="latex">
10621062 <title>LaTeX</title>
10631063 <itemizedlist>
10641064 <listitem>
@@ -1133,8 +1133,8 @@ These should not be escaped: \$ \\ \&gt; \[ \{
11331133 <para>
11341134 Here’s a LaTeX table:
11351135 </para>
1136−</section>
1137−<section id="special-characters">
1136+</sect1>
1137+<sect1 id="special-characters">
11381138 <title>Special Characters</title>
11391139 <para>
11401140 Here is some unicode:
@@ -1229,10 +1229,10 @@ These should not be escaped: \$ \\ \&gt; \[ \{
12291229 <para>
12301230 Minus: -
12311231 </para>
1232−</section>
1233−<section id="links">
1232+</sect1>
1233+<sect1 id="links">
12341234 <title>Links</title>
1235− <section id="explicit">
1235+ <sect2 id="explicit">
12361236 <title>Explicit</title>
12371237 <para>
12381238 Just a <ulink url="/url/">URL</ulink>.
@@ -1261,8 +1261,8 @@ These should not be escaped: \$ \\ \&gt; \[ \{
12611261 <para>
12621262 <ulink url="">Empty</ulink>.
12631263 </para>
1264− </section>
1265− <section id="reference">
1264+ </sect2>
1265+ <sect2 id="reference">
12661266 <title>Reference</title>
12671267 <para>
12681268 Foo <ulink url="/url/">bar</ulink>.
@@ -1300,8 +1300,8 @@ These should not be escaped: \$ \\ \&gt; \[ \{
13001300 <para>
13011301 Foo <ulink url="/url/">biz</ulink>.
13021302 </para>
1303− </section>
1304− <section id="with-ampersands">
1303+ </sect2>
1304+ <sect2 id="with-ampersands">
13051305 <title>With ampersands</title>
13061306 <para>
13071307 Here’s a <ulink url="http://example.com/?foo=1&amp;bar=2">link with an
@@ -1318,8 +1318,8 @@ These should not be escaped: \$ \\ \&gt; \[ \{
13181318 Here’s an <ulink url="/script?foo=1&amp;bar=2">inline link in pointy
13191319 braces</ulink>.
13201320 </para>
1321− </section>
1322− <section id="autolinks">
1321+ </sect2>
1322+ <sect2 id="autolinks">
13231323 <title>Autolinks</title>
13241324 <para>
13251325 With an ampersand:
@@ -1358,9 +1358,9 @@ These should not be escaped: \$ \\ \&gt; \[ \{
13581358 <programlisting>
13591359or here: &lt;http://example.com/&gt;
13601360</programlisting>
1361− </section>
1362−</section>
1363−<section id="images">
1361+ </sect2>
1362+</sect1>
1363+<sect1 id="images">
13641364 <title>Images</title>
13651365 <para>
13661366 From <quote>Voyage dans la Lune</quote> by Georges Melies (1902):
@@ -1381,8 +1381,8 @@ or here: &lt;http://example.com/&gt;
13811381 </imageobject>
13821382 </inlinemediaobject> icon.
13831383 </para>
1384−</section>
1385−<section id="footnotes">
1384+</sect1>
1385+<sect1 id="footnotes">
13861386 <title>Footnotes</title>
13871387 <para>
13881388 Here is a footnote reference,<footnote>
@@ -1437,5 +1437,5 @@ or here: &lt;http://example.com/&gt;
14371437 <para>
14381438 This paragraph should not be part of the note, as it is not indented.
14391439 </para>
1440−</section>
1440+</sect1>
14411441</article>