Docbook writer: Use sect1, sect2, etc. instead of section.
This commit is contained in:
parent
259dda2c56
commit
663cfc2fbd
2 changed files with 73 additions and 71 deletions
|
@ -69,11 +69,12 @@ writeDocbook opts (Pandoc (Meta tit auths dat) blocks) =
|
||||||
then Just $ writerColumns opts
|
then Just $ writerColumns opts
|
||||||
else Nothing
|
else Nothing
|
||||||
render' = render colwidth
|
render' = render colwidth
|
||||||
opts' = if "</book>" `isSuffixOf`
|
opts' = if "/book>" `isSuffixOf`
|
||||||
(removeTrailingSpace $ writerTemplate opts)
|
(removeTrailingSpace $ writerTemplate opts)
|
||||||
then opts{ writerChapters = True }
|
then opts{ writerChapters = True }
|
||||||
else opts
|
else opts
|
||||||
main = render' $ vcat (map (elementToDocbook opts') elements)
|
startLvl = if writerChapters opts' then 0 else 1
|
||||||
|
main = render' $ vcat (map (elementToDocbook opts' startLvl) elements)
|
||||||
context = writerVariables opts ++
|
context = writerVariables opts ++
|
||||||
[ ("body", main)
|
[ ("body", main)
|
||||||
, ("title", render' title)
|
, ("title", render' title)
|
||||||
|
@ -84,19 +85,20 @@ writeDocbook opts (Pandoc (Meta tit auths dat) blocks) =
|
||||||
else main
|
else main
|
||||||
|
|
||||||
-- | Convert an Element to Docbook.
|
-- | Convert an Element to Docbook.
|
||||||
elementToDocbook :: WriterOptions -> Element -> Doc
|
elementToDocbook :: WriterOptions -> Int -> Element -> Doc
|
||||||
elementToDocbook opts (Blk block) = blockToDocbook opts block
|
elementToDocbook opts _ (Blk block) = blockToDocbook opts block
|
||||||
elementToDocbook opts (Sec _ _num id' title elements) =
|
elementToDocbook opts lvl (Sec _ _num id' title elements) =
|
||||||
-- Docbook doesn't allow sections with no content, so insert some if needed
|
-- Docbook doesn't allow sections with no content, so insert some if needed
|
||||||
let elements' = if null elements
|
let elements' = if null elements
|
||||||
then [Blk (Para [])]
|
then [Blk (Para [])]
|
||||||
else elements
|
else elements
|
||||||
tag = if writerChapters opts
|
tag = case lvl of
|
||||||
then "chapter"
|
n | n == 0 -> "chapter"
|
||||||
else "section"
|
| n >= 1 && n <= 5 -> "sect" ++ show n
|
||||||
|
| otherwise -> "simplesect"
|
||||||
in inTags True tag [("id",id')] $
|
in inTags True tag [("id",id')] $
|
||||||
inTagsSimple "title" (inlinesToDocbook opts title) $$
|
inTagsSimple "title" (inlinesToDocbook opts title) $$
|
||||||
vcat (map (elementToDocbook opts{ writerChapters = False }) elements')
|
vcat (map (elementToDocbook opts (lvl + 1)) elements')
|
||||||
|
|
||||||
-- | Convert a list of Pandoc blocks to Docbook.
|
-- | Convert a list of Pandoc blocks to Docbook.
|
||||||
blocksToDocbook :: WriterOptions -> [Block] -> Doc
|
blocksToDocbook :: WriterOptions -> [Block] -> Doc
|
||||||
|
|
|
@ -18,42 +18,42 @@
|
||||||
This is a set of tests for pandoc. Most of them are adapted from John
|
This is a set of tests for pandoc. Most of them are adapted from John
|
||||||
Gruber’s markdown test suite.
|
Gruber’s markdown test suite.
|
||||||
</para>
|
</para>
|
||||||
<section id="headers">
|
<sect1 id="headers">
|
||||||
<title>Headers</title>
|
<title>Headers</title>
|
||||||
<section id="level-2-with-an-embedded-link">
|
<sect2 id="level-2-with-an-embedded-link">
|
||||||
<title>Level 2 with an <ulink url="/url">embedded link</ulink></title>
|
<title>Level 2 with an <ulink url="/url">embedded link</ulink></title>
|
||||||
<section id="level-3-with-emphasis">
|
<sect3 id="level-3-with-emphasis">
|
||||||
<title>Level 3 with <emphasis>emphasis</emphasis></title>
|
<title>Level 3 with <emphasis>emphasis</emphasis></title>
|
||||||
<section id="level-4">
|
<sect4 id="level-4">
|
||||||
<title>Level 4</title>
|
<title>Level 4</title>
|
||||||
<section id="level-5">
|
<sect5 id="level-5">
|
||||||
<title>Level 5</title>
|
<title>Level 5</title>
|
||||||
<para>
|
<para>
|
||||||
</para>
|
</para>
|
||||||
</section>
|
</sect5>
|
||||||
</section>
|
</sect4>
|
||||||
</section>
|
</sect3>
|
||||||
</section>
|
</sect2>
|
||||||
</section>
|
</sect1>
|
||||||
<section id="level-1">
|
<sect1 id="level-1">
|
||||||
<title>Level 1</title>
|
<title>Level 1</title>
|
||||||
<section id="level-2-with-emphasis">
|
<sect2 id="level-2-with-emphasis">
|
||||||
<title>Level 2 with <emphasis>emphasis</emphasis></title>
|
<title>Level 2 with <emphasis>emphasis</emphasis></title>
|
||||||
<section id="level-3">
|
<sect3 id="level-3">
|
||||||
<title>Level 3</title>
|
<title>Level 3</title>
|
||||||
<para>
|
<para>
|
||||||
with no blank line
|
with no blank line
|
||||||
</para>
|
</para>
|
||||||
</section>
|
</sect3>
|
||||||
</section>
|
</sect2>
|
||||||
<section id="level-2">
|
<sect2 id="level-2">
|
||||||
<title>Level 2</title>
|
<title>Level 2</title>
|
||||||
<para>
|
<para>
|
||||||
with no blank line
|
with no blank line
|
||||||
</para>
|
</para>
|
||||||
</section>
|
</sect2>
|
||||||
</section>
|
</sect1>
|
||||||
<section id="paragraphs">
|
<sect1 id="paragraphs">
|
||||||
<title>Paragraphs</title>
|
<title>Paragraphs</title>
|
||||||
<para>
|
<para>
|
||||||
Here’s a regular paragraph.
|
Here’s a regular paragraph.
|
||||||
|
@ -69,8 +69,8 @@
|
||||||
<para>
|
<para>
|
||||||
There should be a hard line break<literallayout></literallayout>here.
|
There should be a hard line break<literallayout></literallayout>here.
|
||||||
</para>
|
</para>
|
||||||
</section>
|
</sect1>
|
||||||
<section id="block-quotes">
|
<sect1 id="block-quotes">
|
||||||
<title>Block Quotes</title>
|
<title>Block Quotes</title>
|
||||||
<para>
|
<para>
|
||||||
E-mail style:
|
E-mail style:
|
||||||
|
@ -124,8 +124,8 @@ sub status {
|
||||||
<para>
|
<para>
|
||||||
And a following paragraph.
|
And a following paragraph.
|
||||||
</para>
|
</para>
|
||||||
</section>
|
</sect1>
|
||||||
<section id="code-blocks">
|
<sect1 id="code-blocks">
|
||||||
<title>Code Blocks</title>
|
<title>Code Blocks</title>
|
||||||
<para>
|
<para>
|
||||||
Code:
|
Code:
|
||||||
|
@ -147,10 +147,10 @@ this code block is indented by one tab
|
||||||
|
|
||||||
These should not be escaped: \$ \\ \> \[ \{
|
These should not be escaped: \$ \\ \> \[ \{
|
||||||
</programlisting>
|
</programlisting>
|
||||||
</section>
|
</sect1>
|
||||||
<section id="lists">
|
<sect1 id="lists">
|
||||||
<title>Lists</title>
|
<title>Lists</title>
|
||||||
<section id="unordered">
|
<sect2 id="unordered">
|
||||||
<title>Unordered</title>
|
<title>Unordered</title>
|
||||||
<para>
|
<para>
|
||||||
Asterisks tight:
|
Asterisks tight:
|
||||||
|
@ -272,8 +272,8 @@ These should not be escaped: \$ \\ \> \[ \{
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</itemizedlist>
|
</itemizedlist>
|
||||||
</section>
|
</sect2>
|
||||||
<section id="ordered">
|
<sect2 id="ordered">
|
||||||
<title>Ordered</title>
|
<title>Ordered</title>
|
||||||
<para>
|
<para>
|
||||||
Tight:
|
Tight:
|
||||||
|
@ -379,8 +379,8 @@ These should not be escaped: \$ \\ \> \[ \{
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</orderedlist>
|
</orderedlist>
|
||||||
</section>
|
</sect2>
|
||||||
<section id="nested">
|
<sect2 id="nested">
|
||||||
<title>Nested</title>
|
<title>Nested</title>
|
||||||
<itemizedlist>
|
<itemizedlist>
|
||||||
<listitem>
|
<listitem>
|
||||||
|
@ -477,8 +477,8 @@ These should not be escaped: \$ \\ \> \[ \{
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</orderedlist>
|
</orderedlist>
|
||||||
</section>
|
</sect2>
|
||||||
<section id="tabs-and-spaces">
|
<sect2 id="tabs-and-spaces">
|
||||||
<title>Tabs and spaces</title>
|
<title>Tabs and spaces</title>
|
||||||
<itemizedlist>
|
<itemizedlist>
|
||||||
<listitem>
|
<listitem>
|
||||||
|
@ -504,8 +504,8 @@ These should not be escaped: \$ \\ \> \[ \{
|
||||||
</itemizedlist>
|
</itemizedlist>
|
||||||
</listitem>
|
</listitem>
|
||||||
</itemizedlist>
|
</itemizedlist>
|
||||||
</section>
|
</sect2>
|
||||||
<section id="fancy-list-markers">
|
<sect2 id="fancy-list-markers">
|
||||||
<title>Fancy list markers</title>
|
<title>Fancy list markers</title>
|
||||||
<orderedlist numeration="arabic">
|
<orderedlist numeration="arabic">
|
||||||
<listitem override="2">
|
<listitem override="2">
|
||||||
|
@ -608,9 +608,9 @@ These should not be escaped: \$ \\ \> \[ \{
|
||||||
<para>
|
<para>
|
||||||
B. Williams
|
B. Williams
|
||||||
</para>
|
</para>
|
||||||
</section>
|
</sect2>
|
||||||
</section>
|
</sect1>
|
||||||
<section id="definition-lists">
|
<sect1 id="definition-lists">
|
||||||
<title>Definition Lists</title>
|
<title>Definition Lists</title>
|
||||||
<para>
|
<para>
|
||||||
Tight using spaces:
|
Tight using spaces:
|
||||||
|
@ -855,8 +855,8 @@ These should not be escaped: \$ \\ \> \[ \{
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
</variablelist>
|
</variablelist>
|
||||||
</section>
|
</sect1>
|
||||||
<section id="html-blocks">
|
<sect1 id="html-blocks">
|
||||||
<title>HTML Blocks</title>
|
<title>HTML Blocks</title>
|
||||||
<para>
|
<para>
|
||||||
Simple block on one line:
|
Simple block on one line:
|
||||||
|
@ -975,8 +975,8 @@ These should not be escaped: \$ \\ \> \[ \{
|
||||||
<hr class="foo" id="bar" />
|
<hr class="foo" id="bar" />
|
||||||
|
|
||||||
<hr class="foo" id="bar">
|
<hr class="foo" id="bar">
|
||||||
</section>
|
</sect1>
|
||||||
<section id="inline-markup">
|
<sect1 id="inline-markup">
|
||||||
<title>Inline Markup</title>
|
<title>Inline Markup</title>
|
||||||
<para>
|
<para>
|
||||||
This is <emphasis>emphasized</emphasis>, and so <emphasis>is
|
This is <emphasis>emphasized</emphasis>, and so <emphasis>is
|
||||||
|
@ -1025,8 +1025,8 @@ These should not be escaped: \$ \\ \> \[ \{
|
||||||
These should not be superscripts or subscripts, because of the unescaped
|
These should not be superscripts or subscripts, because of the unescaped
|
||||||
spaces: a^b c^d, a~b c~d.
|
spaces: a^b c^d, a~b c~d.
|
||||||
</para>
|
</para>
|
||||||
</section>
|
</sect1>
|
||||||
<section id="smart-quotes-ellipses-dashes">
|
<sect1 id="smart-quotes-ellipses-dashes">
|
||||||
<title>Smart quotes, ellipses, dashes</title>
|
<title>Smart quotes, ellipses, dashes</title>
|
||||||
<para>
|
<para>
|
||||||
<quote>Hello,</quote> said the spider. <quote><quote>Shelob</quote> is my
|
<quote>Hello,</quote> said the spider. <quote><quote>Shelob</quote> is my
|
||||||
|
@ -1057,8 +1057,8 @@ These should not be escaped: \$ \\ \> \[ \{
|
||||||
<para>
|
<para>
|
||||||
Ellipses…and…and….
|
Ellipses…and…and….
|
||||||
</para>
|
</para>
|
||||||
</section>
|
</sect1>
|
||||||
<section id="latex">
|
<sect1 id="latex">
|
||||||
<title>LaTeX</title>
|
<title>LaTeX</title>
|
||||||
<itemizedlist>
|
<itemizedlist>
|
||||||
<listitem>
|
<listitem>
|
||||||
|
@ -1133,8 +1133,8 @@ These should not be escaped: \$ \\ \> \[ \{
|
||||||
<para>
|
<para>
|
||||||
Here’s a LaTeX table:
|
Here’s a LaTeX table:
|
||||||
</para>
|
</para>
|
||||||
</section>
|
</sect1>
|
||||||
<section id="special-characters">
|
<sect1 id="special-characters">
|
||||||
<title>Special Characters</title>
|
<title>Special Characters</title>
|
||||||
<para>
|
<para>
|
||||||
Here is some unicode:
|
Here is some unicode:
|
||||||
|
@ -1229,10 +1229,10 @@ These should not be escaped: \$ \\ \> \[ \{
|
||||||
<para>
|
<para>
|
||||||
Minus: -
|
Minus: -
|
||||||
</para>
|
</para>
|
||||||
</section>
|
</sect1>
|
||||||
<section id="links">
|
<sect1 id="links">
|
||||||
<title>Links</title>
|
<title>Links</title>
|
||||||
<section id="explicit">
|
<sect2 id="explicit">
|
||||||
<title>Explicit</title>
|
<title>Explicit</title>
|
||||||
<para>
|
<para>
|
||||||
Just a <ulink url="/url/">URL</ulink>.
|
Just a <ulink url="/url/">URL</ulink>.
|
||||||
|
@ -1261,8 +1261,8 @@ These should not be escaped: \$ \\ \> \[ \{
|
||||||
<para>
|
<para>
|
||||||
<ulink url="">Empty</ulink>.
|
<ulink url="">Empty</ulink>.
|
||||||
</para>
|
</para>
|
||||||
</section>
|
</sect2>
|
||||||
<section id="reference">
|
<sect2 id="reference">
|
||||||
<title>Reference</title>
|
<title>Reference</title>
|
||||||
<para>
|
<para>
|
||||||
Foo <ulink url="/url/">bar</ulink>.
|
Foo <ulink url="/url/">bar</ulink>.
|
||||||
|
@ -1300,8 +1300,8 @@ These should not be escaped: \$ \\ \> \[ \{
|
||||||
<para>
|
<para>
|
||||||
Foo <ulink url="/url/">biz</ulink>.
|
Foo <ulink url="/url/">biz</ulink>.
|
||||||
</para>
|
</para>
|
||||||
</section>
|
</sect2>
|
||||||
<section id="with-ampersands">
|
<sect2 id="with-ampersands">
|
||||||
<title>With ampersands</title>
|
<title>With ampersands</title>
|
||||||
<para>
|
<para>
|
||||||
Here’s a <ulink url="http://example.com/?foo=1&bar=2">link with an
|
Here’s a <ulink url="http://example.com/?foo=1&bar=2">link with an
|
||||||
|
@ -1318,8 +1318,8 @@ These should not be escaped: \$ \\ \> \[ \{
|
||||||
Here’s an <ulink url="/script?foo=1&bar=2">inline link in pointy
|
Here’s an <ulink url="/script?foo=1&bar=2">inline link in pointy
|
||||||
braces</ulink>.
|
braces</ulink>.
|
||||||
</para>
|
</para>
|
||||||
</section>
|
</sect2>
|
||||||
<section id="autolinks">
|
<sect2 id="autolinks">
|
||||||
<title>Autolinks</title>
|
<title>Autolinks</title>
|
||||||
<para>
|
<para>
|
||||||
With an ampersand:
|
With an ampersand:
|
||||||
|
@ -1358,9 +1358,9 @@ These should not be escaped: \$ \\ \> \[ \{
|
||||||
<programlisting>
|
<programlisting>
|
||||||
or here: <http://example.com/>
|
or here: <http://example.com/>
|
||||||
</programlisting>
|
</programlisting>
|
||||||
</section>
|
</sect2>
|
||||||
</section>
|
</sect1>
|
||||||
<section id="images">
|
<sect1 id="images">
|
||||||
<title>Images</title>
|
<title>Images</title>
|
||||||
<para>
|
<para>
|
||||||
From <quote>Voyage dans la Lune</quote> by Georges Melies (1902):
|
From <quote>Voyage dans la Lune</quote> by Georges Melies (1902):
|
||||||
|
@ -1381,8 +1381,8 @@ or here: <http://example.com/>
|
||||||
</imageobject>
|
</imageobject>
|
||||||
</inlinemediaobject> icon.
|
</inlinemediaobject> icon.
|
||||||
</para>
|
</para>
|
||||||
</section>
|
</sect1>
|
||||||
<section id="footnotes">
|
<sect1 id="footnotes">
|
||||||
<title>Footnotes</title>
|
<title>Footnotes</title>
|
||||||
<para>
|
<para>
|
||||||
Here is a footnote reference,<footnote>
|
Here is a footnote reference,<footnote>
|
||||||
|
@ -1437,5 +1437,5 @@ or here: <http://example.com/>
|
||||||
<para>
|
<para>
|
||||||
This paragraph should not be part of the note, as it is not indented.
|
This paragraph should not be part of the note, as it is not indented.
|
||||||
</para>
|
</para>
|
||||||
</section>
|
</sect1>
|
||||||
</article>
|
</article>
|
||||||
|
|
Loading…
Add table
Reference in a new issue