Merge pull request #2890 from bcdevices/docbook5-writer

Docbook5 write support
This commit is contained in:
John MacFarlane 2016-05-01 22:43:38 -07:00
commit ee4e863225
6 changed files with 1849 additions and 6 deletions

View file

@ -291,6 +291,8 @@ writers = [
writeHtmlString o{ writerSlideVariant = RevealJsSlides
, writerHtml5 = True })
,("docbook" , PureStringWriter writeDocbook)
,("docbook5" , PureStringWriter $ \o ->
writeDocbook o{ writerDocbook5 = True })
,("opml" , PureStringWriter writeOPML)
,("opendocument" , PureStringWriter writeOpenDocument)
,("latex" , PureStringWriter writeLaTeX)

View file

@ -357,6 +357,7 @@ data WriterOptions = WriterOptions
, writerSourceURL :: Maybe String -- ^ Absolute URL + directory of 1st source file
, writerUserDataDir :: Maybe FilePath -- ^ Path of user data directory
, writerCiteMethod :: CiteMethod -- ^ How to print cites
, writerDocbook5 :: Bool -- ^ Produce DocBook5
, writerHtml5 :: Bool -- ^ Produce HTML5
, writerHtmlQTags :: Bool -- ^ Use @<q>@ tags for quotes in HTML
, writerBeamer :: Bool -- ^ Produce beamer LaTeX slide show
@ -403,6 +404,7 @@ instance Default WriterOptions where
, writerSourceURL = Nothing
, writerUserDataDir = Nothing
, writerCiteMethod = Citeproc
, writerDocbook5 = False
, writerHtml5 = False
, writerHtmlQTags = False
, writerBeamer = False

View file

@ -112,10 +112,15 @@ elementToDocbook opts lvl (Sec _ _num (id',_,_) title elements) =
else elements
tag = case lvl of
n | n == 0 -> "chapter"
| n >= 1 && n <= 5 -> "sect" ++ show n
| n >= 1 && n <= 5 -> if writerDocbook5 opts
then "section"
else "sect" ++ show n
| otherwise -> "simplesect"
in inTags True tag [("id", writerIdentifierPrefix opts ++ id') |
not (null id')] $
idAttr = [("id", writerIdentifierPrefix opts ++ id') | not (null id')]
nsAttr = if writerDocbook5 opts && lvl == 0 then [("xmlns", "http://docbook.org/ns/docbook")]
else []
attribs = nsAttr ++ idAttr
in inTags True tag attribs $
inTagsSimple "title" (inlinesToDocbook opts title) $$
vcat (map (elementToDocbook opts (lvl + 1)) elements')
@ -227,9 +232,11 @@ blockToDocbook opts (OrderedList (start, numstyle, _) (first:rest)) =
blockToDocbook opts (DefinitionList lst) =
let attribs = [("spacing", "compact") | isTightList $ concatMap snd lst]
in inTags True "variablelist" attribs $ deflistItemsToDocbook opts lst
blockToDocbook _ (RawBlock f str)
blockToDocbook opts (RawBlock f str)
| f == "docbook" = text str -- raw XML block
| f == "html" = text str -- allow html for backwards compatibility
| f == "html" = if writerDocbook5 opts
then empty -- No html in Docbook5
else text str -- allow html for backwards compatibility
| otherwise = empty
blockToDocbook _ HorizontalRule = empty -- not semantic
blockToDocbook opts (Table caption aligns widths headers rows) =
@ -344,7 +351,9 @@ inlineToDocbook opts (Link attr txt (src, _))
| otherwise =
(if isPrefixOf "#" src
then inTags False "link" $ ("linkend", drop 1 src) : idAndRole attr
else inTags False "ulink" $ ("url", src) : idAndRole attr ) $
else if writerDocbook5 opts
then inTags False "link" $ ("xlink:href", src) : idAndRole attr
else inTags False "ulink" $ ("url", src) : idAndRole attr ) $
inlinesToDocbook opts txt
inlineToDocbook opts (Image attr _ (src, tit)) =
let titleDoc = if null tit

View file

@ -108,6 +108,9 @@ tests = [ testGroup "markdown"
, test "reader" ["-r", "docbook", "-w", "native", "-s"]
"docbook-xref.docbook" "docbook-xref.native"
]
, testGroup "docbook5"
[ testGroup "writer" $ writerTests "docbook5"
]
, testGroup "native"
[ testGroup "writer" $ writerTests "native"
, test "reader" ["-r", "native", "-w", "native", "-s"]

432
tests/tables.docbook5 Normal file
View file

@ -0,0 +1,432 @@
<para>
Simple table with caption:
</para>
<table>
<title>
Demonstration of simple table syntax.
</title>
<tgroup cols="4">
<colspec align="right" />
<colspec align="left" />
<colspec align="center" />
<colspec align="left" />
<thead>
<row>
<entry>
Right
</entry>
<entry>
Left
</entry>
<entry>
Center
</entry>
<entry>
Default
</entry>
</row>
</thead>
<tbody>
<row>
<entry>
12
</entry>
<entry>
12
</entry>
<entry>
12
</entry>
<entry>
12
</entry>
</row>
<row>
<entry>
123
</entry>
<entry>
123
</entry>
<entry>
123
</entry>
<entry>
123
</entry>
</row>
<row>
<entry>
1
</entry>
<entry>
1
</entry>
<entry>
1
</entry>
<entry>
1
</entry>
</row>
</tbody>
</tgroup>
</table>
<para>
Simple table without caption:
</para>
<informaltable>
<tgroup cols="4">
<colspec align="right" />
<colspec align="left" />
<colspec align="center" />
<colspec align="left" />
<thead>
<row>
<entry>
Right
</entry>
<entry>
Left
</entry>
<entry>
Center
</entry>
<entry>
Default
</entry>
</row>
</thead>
<tbody>
<row>
<entry>
12
</entry>
<entry>
12
</entry>
<entry>
12
</entry>
<entry>
12
</entry>
</row>
<row>
<entry>
123
</entry>
<entry>
123
</entry>
<entry>
123
</entry>
<entry>
123
</entry>
</row>
<row>
<entry>
1
</entry>
<entry>
1
</entry>
<entry>
1
</entry>
<entry>
1
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
<para>
Simple table indented two spaces:
</para>
<table>
<title>
Demonstration of simple table syntax.
</title>
<tgroup cols="4">
<colspec align="right" />
<colspec align="left" />
<colspec align="center" />
<colspec align="left" />
<thead>
<row>
<entry>
Right
</entry>
<entry>
Left
</entry>
<entry>
Center
</entry>
<entry>
Default
</entry>
</row>
</thead>
<tbody>
<row>
<entry>
12
</entry>
<entry>
12
</entry>
<entry>
12
</entry>
<entry>
12
</entry>
</row>
<row>
<entry>
123
</entry>
<entry>
123
</entry>
<entry>
123
</entry>
<entry>
123
</entry>
</row>
<row>
<entry>
1
</entry>
<entry>
1
</entry>
<entry>
1
</entry>
<entry>
1
</entry>
</row>
</tbody>
</tgroup>
</table>
<para>
Multiline table with caption:
</para>
<table>
<title>
Here's the caption. It may span multiple lines.
</title>
<tgroup cols="4">
<colspec colwidth="15*" align="center" />
<colspec colwidth="13*" align="left" />
<colspec colwidth="16*" align="right" />
<colspec colwidth="33*" align="left" />
<thead>
<row>
<entry>
Centered Header
</entry>
<entry>
Left Aligned
</entry>
<entry>
Right Aligned
</entry>
<entry>
Default aligned
</entry>
</row>
</thead>
<tbody>
<row>
<entry>
First
</entry>
<entry>
row
</entry>
<entry>
12.0
</entry>
<entry>
Example of a row that spans multiple lines.
</entry>
</row>
<row>
<entry>
Second
</entry>
<entry>
row
</entry>
<entry>
5.0
</entry>
<entry>
Here's another one. Note the blank line between rows.
</entry>
</row>
</tbody>
</tgroup>
</table>
<para>
Multiline table without caption:
</para>
<informaltable>
<tgroup cols="4">
<colspec colwidth="15*" align="center" />
<colspec colwidth="13*" align="left" />
<colspec colwidth="16*" align="right" />
<colspec colwidth="33*" align="left" />
<thead>
<row>
<entry>
Centered Header
</entry>
<entry>
Left Aligned
</entry>
<entry>
Right Aligned
</entry>
<entry>
Default aligned
</entry>
</row>
</thead>
<tbody>
<row>
<entry>
First
</entry>
<entry>
row
</entry>
<entry>
12.0
</entry>
<entry>
Example of a row that spans multiple lines.
</entry>
</row>
<row>
<entry>
Second
</entry>
<entry>
row
</entry>
<entry>
5.0
</entry>
<entry>
Here's another one. Note the blank line between rows.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
<para>
Table without column headers:
</para>
<informaltable>
<tgroup cols="4">
<colspec align="right" />
<colspec align="left" />
<colspec align="center" />
<colspec align="right" />
<tbody>
<row>
<entry>
12
</entry>
<entry>
12
</entry>
<entry>
12
</entry>
<entry>
12
</entry>
</row>
<row>
<entry>
123
</entry>
<entry>
123
</entry>
<entry>
123
</entry>
<entry>
123
</entry>
</row>
<row>
<entry>
1
</entry>
<entry>
1
</entry>
<entry>
1
</entry>
<entry>
1
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
<para>
Multiline table without column headers:
</para>
<informaltable>
<tgroup cols="4">
<colspec colwidth="15*" align="center" />
<colspec colwidth="13*" align="left" />
<colspec colwidth="16*" align="right" />
<colspec colwidth="33*" align="left" />
<tbody>
<row>
<entry>
First
</entry>
<entry>
row
</entry>
<entry>
12.0
</entry>
<entry>
Example of a row that spans multiple lines.
</entry>
</row>
<row>
<entry>
Second
</entry>
<entry>
row
</entry>
<entry>
5.0
</entry>
<entry>
Here's another one. Note the blank line between rows.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>

1395
tests/writer.docbook5 Normal file

File diff suppressed because it is too large Load diff