@@ -32,12 +32,14 @@ module Text.Pandoc.Writers.Docbook ( writeDocbook) where
32import Text.Pandoc.Definition
32import Text.Pandoc.Definition
33import Text.Pandoc.XML
33import Text.Pandoc.XML
34import Text.Pandoc.Shared
34import Text.Pandoc.Shared
35+import Text.Pandoc.Walk
35import Text.Pandoc.Writers.Shared
36import Text.Pandoc.Writers.Shared
36import Text.Pandoc.Options
37import Text.Pandoc.Options
37import Text.Pandoc.Templates (renderTemplate')
38import Text.Pandoc.Templates (renderTemplate')
38import Text.Pandoc.Readers.TeXMath
39import Text.Pandoc.Readers.TeXMath
39import Data.List ( isPrefixOf, intercalate, isSuffixOf )
40import Data.List ( isPrefixOf, intercalate, isSuffixOf )
40import Data.Char ( toLower )
41import Data.Char ( toLower )
42+import Data.Monoid ( Any(..) )
41import Text.Pandoc.Highlighting ( languages, languagesByExtension )
43import Text.Pandoc.Highlighting ( languages, languagesByExtension )
42import Text.Pandoc.Pretty
44import Text.Pandoc.Pretty
43import qualified Text.Pandoc.Builder as B
45import qualified Text.Pandoc.Builder as B
@@ -165,8 +167,9 @@ blockToDocbook opts (Para [Image txt (src,'f':'i':'g':':':_)]) =
165 (inTagsIndented "imageobject"
167 (inTagsIndented "imageobject"
166 (selfClosingTag "imagedata" [("fileref",src)])) $$
168 (selfClosingTag "imagedata" [("fileref",src)])) $$
167 inTagsSimple "textobject" (inTagsSimple "phrase" alt))
169 inTagsSimple "textobject" (inTagsSimple "phrase" alt))
168−blockToDocbook opts (Para lst) =
170+blockToDocbook opts (Para lst)
171+ | hasLineBreaks lst = flush $ nowrap $ inTagsSimple "literallayout" $ inlinesToDocbook opts lst
169− inTagsIndented "para" $ inlinesToDocbook opts lst
172+ | otherwise = inTagsIndented "para" $ inlinesToDocbook opts lst
170blockToDocbook opts (BlockQuote blocks) =
173blockToDocbook opts (BlockQuote blocks) =
171 inTagsIndented "blockquote" $ blocksToDocbook opts blocks
174 inTagsIndented "blockquote" $ blocksToDocbook opts blocks
172blockToDocbook _ (CodeBlock (_,classes,_) str) =
175blockToDocbook _ (CodeBlock (_,classes,_) str) =
@@ -226,6 +229,16 @@ blockToDocbook opts (Table caption aligns widths headers rows) =
226 (inTags True "tgroup" [("cols", show (length headers))] $
229 (inTags True "tgroup" [("cols", show (length headers))] $
227 coltags $$ head' $$ body')
230 coltags $$ head' $$ body')
232+hasLineBreaks :: [Inline] -> Bool
233+hasLineBreaks = getAny . query isLineBreak . walk removeNote
235+ removeNote :: Inline -> Inline
236+ removeNote (Note _) = Str ""
238+ isLineBreak :: Inline -> Any
239+ isLineBreak LineBreak = Any True
240+ isLineBreak _ = Any False
229alignmentToString :: Alignment -> [Char]
242alignmentToString :: Alignment -> [Char]
230alignmentToString alignment = case alignment of
243alignmentToString alignment = case alignment of
231 AlignLeft -> "left"
244 AlignLeft -> "left"
@@ -293,7 +306,7 @@ inlineToDocbook opts (Math t str)
293 fixNS = everywhere (mkT fixNS')
306 fixNS = everywhere (mkT fixNS')
294inlineToDocbook _ (RawInline f x) | f == "html" || f == "docbook" = text x
307inlineToDocbook _ (RawInline f x) | f == "html" || f == "docbook" = text x
295 | otherwise = empty
308 | otherwise = empty
296−inlineToDocbook _ LineBreak = flush $ inTagsSimple "literallayout" (text "\n")
309+inlineToDocbook _ LineBreak = text "\n"
297inlineToDocbook _ Space = space
310inlineToDocbook _ Space = space
298inlineToDocbook opts (Link txt (src, _)) =
311inlineToDocbook opts (Link txt (src, _)) =
299 if isPrefixOf "mailto:" src
312 if isPrefixOf "mailto:" src