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