git.iko.soy/typeable/pandoc
on master help sign in
Support `--mathml` flag in docbook.
commit38808284155ea83b7287a622759f566ccf884421 authorJohn MacFarlane <fiddlosopher@gmail.com> dateTue 31 Jan 2012, 10:32 (15 years ago) parentccd61a5
3 files changed+39−7
README+10−4 src/Text/Pandoc/Writers/Docbook.hs+28−2 templates+1−1
README+10−4
@@ -544,9 +544,10 @@ Math rendering in HTML
544544 so it can be cached.
545545
546546`--mathml`[=*URL*]
547−: Convert TeX math to MathML. In standalone mode, a small javascript
548− (or a link to such a script if a *URL* is supplied) will be inserted that
549− allows the MathML to be viewed on some browsers.
547+: Convert TeX math to MathML (works with `docbook` as well as `html`).
548+ In standalone mode, a small javascript (or a link to such a script if a
549+ *URL* is supplied) will be inserted that allows the MathML to be viewed on
550+ some browsers.
550551
551552`--jsmath`[=*URL*]
552553: Use [jsMath] to display embedded TeX math in HTML output.
@@ -1652,10 +1653,15 @@ MediaWiki
16521653Textile
16531654 ~ It will be rendered inside `<span class="math">` tags.
16541655
1655−RTF, DocBook, OpenDocument, ODT
1656+RTF, OpenDocument, ODT
16561657 ~ It will be rendered, if possible, using unicode characters,
16571658 and will otherwise appear verbatim.
16581659
1660+Docbook
1661+ ~ If the `--mathml` flag is used, it will be rendered using mathml
1662+ in an `inlineequation` or `informalequation` tag. Otherwise it
1663+ will be rendered, if possible, using unicode characters.
1664+
16591665Docx
16601666 ~ It will be rendered using OMML math markup.
16611667
src/Text/Pandoc/Writers/Docbook.hs+28−2
@@ -37,6 +37,9 @@ import Data.List ( isPrefixOf, intercalate, isSuffixOf )
3737import Data.Char ( toLower )
3838import Text.Pandoc.Highlighting ( languages, languagesByExtension )
3939import Text.Pandoc.Pretty
40+import Text.TeXMath
41+import qualified Text.XML.Light as Xml
42+import Data.Generics (everywhere, mkT)
4043
4144-- | Convert list of authors to a docbook <author> section
4245authorToDocbook :: WriterOptions -> [Inline] -> Doc
@@ -79,7 +82,10 @@ writeDocbook opts (Pandoc (Meta tit auths dat) blocks) =
7982 [ ("body", main)
8083 , ("title", render' title)
8184 , ("date", render' date) ] ++
82− [ ("author", render' a) | a <- authors ]
85+ [ ("author", render' a) | a <- authors ] ++
86+ [ ("mathml", "yes") | case writerHTMLMathMethod opts of
87+ MathML _ -> True
88+ _ -> False ]
8389 in if writerStandalone opts
8490 then renderTemplate context $ writerTemplate opts
8591 else main
@@ -252,7 +258,23 @@ inlineToDocbook opts (Cite _ lst) =
252258 inlinesToDocbook opts lst
253259inlineToDocbook _ (Code _ str) =
254260 inTagsSimple "literal" $ text (escapeStringForXML str)
255−inlineToDocbook opts (Math _ str) = inlinesToDocbook opts $ readTeXMath str
261+inlineToDocbook opts (Math t str)
262+ | isMathML (writerHTMLMathMethod opts) =
263+ case texMathToMathML dt str of
264+ Right r -> inTagsSimple tagtype
265+ $ text $ Xml.ppcElement conf
266+ $ fixNS
267+ $ removeAttr r
268+ Left _ -> inlinesToDocbook opts
269+ $ readTeXMath str
270+ | otherwise = inlinesToDocbook opts $ readTeXMath str
271+ where (dt, tagtype) = case t of
272+ InlineMath -> (DisplayInline,"inlineequation")
273+ DisplayMath -> (DisplayBlock,"informalequation")
274+ conf = Xml.useShortEmptyTags (const False) Xml.defaultConfigPP
275+ removeAttr e = e{ Xml.elAttribs = [] }
276+ fixNS' qname = qname{ Xml.qPrefix = Just "mml" }
277+ fixNS = everywhere (mkT fixNS')
256278inlineToDocbook _ (RawInline f x) | f == "html" || f == "docbook" = text x
257279 | otherwise = empty
258280inlineToDocbook _ LineBreak = inTagsSimple "literallayout" empty
@@ -279,3 +301,7 @@ inlineToDocbook _ (Image _ (src, tit)) =
279301 titleDoc $$ selfClosingTag "imagedata" [("fileref", src)]
280302inlineToDocbook opts (Note contents) =
281303 inTagsIndented "footnote" $ blocksToDocbook opts contents
304+
305+isMathML :: HTMLMathMethod -> Bool
306+isMathML (MathML _) = True
307+isMathML _ = False
templates+1−1

Submodule changed.