From 663cfc2fbd0ff83f74dcde53e3cc98130fb645e0 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Fri, 27 Jan 2012 11:30:50 -0800 Subject: Docbook writer: Use sect1, sect2, etc. instead of section. --- src/Text/Pandoc/Writers/Docbook.hs | 20 +++--- tests/writer.docbook | 124 ++++++++++++++++++------------------- 2 files changed, 73 insertions(+), 71 deletions(-) diff --git a/src/Text/Pandoc/Writers/Docbook.hs b/src/Text/Pandoc/Writers/Docbook.hs index f3ac726a9..878d2face 100644 --- a/src/Text/Pandoc/Writers/Docbook.hs +++ b/src/Text/Pandoc/Writers/Docbook.hs @@ -69,11 +69,12 @@ writeDocbook opts (Pandoc (Meta tit auths dat) blocks) = then Just $ writerColumns opts else Nothing render' = render colwidth - opts' = if "" `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 diff --git a/tests/writer.docbook b/tests/writer.docbook index d767b6e20..0eeaebbfd 100644 --- a/tests/writer.docbook +++ b/tests/writer.docbook @@ -18,42 +18,42 @@ This is a set of tests for pandoc. Most of them are adapted from John Gruber’s markdown test suite. -
+ Headers - -
-
+ + + + + + Level 1 -
+ Level 2 with <emphasis>emphasis</emphasis> -
+ Level 3 with no blank line -
-
-
+ + + Level 2 with no blank line -
-
-
+ + + Paragraphs Here’s a regular paragraph. @@ -69,8 +69,8 @@ There should be a hard line breakhere. -
-
+ + Block Quotes E-mail style: @@ -124,8 +124,8 @@ sub status { And a following paragraph. -
-
+ + Code Blocks Code: @@ -147,10 +147,10 @@ this code block is indented by one tab These should not be escaped: \$ \\ \> \[ \{ -
-
+ + Lists -
+ Unordered Asterisks tight: @@ -272,8 +272,8 @@ These should not be escaped: \$ \\ \> \[ \{ -
-
+ + Ordered Tight: @@ -379,8 +379,8 @@ These should not be escaped: \$ \\ \> \[ \{ -
-
+ + Nested @@ -477,8 +477,8 @@ These should not be escaped: \$ \\ \> \[ \{ -
-
+ + Tabs and spaces @@ -504,8 +504,8 @@ These should not be escaped: \$ \\ \> \[ \{ -
-
+ + Fancy list markers @@ -608,9 +608,9 @@ These should not be escaped: \$ \\ \> \[ \{ B. Williams -
-
-
+ + + Definition Lists Tight using spaces: @@ -855,8 +855,8 @@ These should not be escaped: \$ \\ \> \[ \{ -
-
+ + HTML Blocks Simple block on one line: @@ -975,8 +975,8 @@ These should not be escaped: \$ \\ \> \[ \{

-
-
+ + Inline Markup This is emphasized, and so 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. -
-
+ + Smart quotes, ellipses, dashes Hello, said the spider. Shelob is my @@ -1057,8 +1057,8 @@ These should not be escaped: \$ \\ \> \[ \{ Ellipses…and…and…. -
-
+ + LaTeX @@ -1133,8 +1133,8 @@ These should not be escaped: \$ \\ \> \[ \{ Here’s a LaTeX table: -
-
+ + Special Characters Here is some unicode: @@ -1229,10 +1229,10 @@ These should not be escaped: \$ \\ \> \[ \{ Minus: - -
- -
+ + + Images From Voyage dans la Lune by Georges Melies (1902): @@ -1381,8 +1381,8 @@ or here: <http://example.com/> icon. -
-
+ + Footnotes Here is a footnote reference, @@ -1437,5 +1437,5 @@ or here: <http://example.com/> This paragraph should not be part of the note, as it is not indented. -
+ -- cgit v1.2.3