git.iko.soy/typeable/pandoc
on master help sign in
DocBook: Support equations with mathml.

equation, informalequation, inlineequation and mml:math elements.

commitf16dd1bfdf0e7c4ed34700a11adc2b4c594a536c authorJohn MacFarlane <jgm@berkeley.edu> dateTue 12 Aug 2014, 14:00 (12 years ago) parent22cf620
1 file changed+16−4
src/Text/Pandoc/Readers/DocBook.hs+16−4
src/Text/Pandoc/Readers/DocBook.hs+16−4
@@ -6,6 +6,7 @@ import Text.Pandoc.Definition
66import Text.Pandoc.Builder
77import Text.XML.Light
88import Text.Pandoc.Compat.TagSoupEntity (lookupEntity)
9+import Data.Either (rights)
910import Data.Generics
1011import Data.Monoid
1112import Data.Char (isSpace)
@@ -13,6 +14,7 @@ import Control.Monad.State
1314import Control.Applicative ((<$>))
1415import Data.List (intersperse)
1516import Data.Maybe (fromMaybe)
17+import Text.TeXMath (readMathML, writeTeX)
1618
1719{-
1820
@@ -126,7 +128,7 @@ List of all DocBook tags, with [x] indicating implemented,
126128[ ] envar - A software environment variable
127129[x] epigraph - A short inscription at the beginning of a document or component
128130 note: also handle embedded attribution tag
129−[ ] equation - A displayed mathematical equation
131+[x] equation - A displayed mathematical equation
130132[ ] errorcode - An error code
131133[ ] errorname - An error name
132134[ ] errortext - An error message.
@@ -185,12 +187,12 @@ List of all DocBook tags, with [x] indicating implemented,
185187[x] indexinfo - Meta-information for an Index
186188[x] indexterm - A wrapper for terms to be indexed
187189[x] info - A wrapper for information about a component or other block. (DocBook v5)
188−[ ] informalequation - A displayed mathematical equation without a title
190+[x] informalequation - A displayed mathematical equation without a title
189191[ ] informalexample - A displayed example without a title
190192[ ] informalfigure - A untitled figure
191193[ ] informaltable - A table without a title
192194[ ] initializer - The initializer for a FieldSynopsis
193−[ ] inlineequation - A mathematical equation or expression occurring inline
195+[x] inlineequation - A mathematical equation or expression occurring inline
194196[ ] inlinegraphic - An object containing or pointing to graphical data
195197 that will be rendered inline
196198[x] inlinemediaobject - An inline media object (video, audio, image, and so on)
@@ -239,7 +241,7 @@ List of all DocBook tags, with [x] indicating implemented,
239241[ ] methodname - The name of a method
240242[ ] methodparam - Parameters to a method
241243[ ] methodsynopsis - A syntax summary for a method
242−[ ] mml:math - A MathML equation
244+[x] mml:math - A MathML equation
243245[ ] modespec - Application-specific information necessary for the
244246 completion of an OLink
245247[ ] modifier - Modifiers in a synopsis
@@ -882,6 +884,9 @@ parseInline (CRef ref) =
882884 return $ maybe (text $ map toUpper ref) (text . (:[])) $ lookupEntity ref
883885parseInline (Elem e) =
884886 case qName (elName e) of
887+ "equation" -> equation displayMath
888+ "informalequation" -> equation displayMath
889+ "inlineequation" -> equation math
885890 "subscript" -> subscript <$> innerInlines
886891 "superscript" -> superscript <$> innerInlines
887892 "inlinemediaobject" -> getImage e
@@ -943,6 +948,13 @@ parseInline (Elem e) =
943948 _ -> innerInlines
944949 where innerInlines = (trimInlines . mconcat) <$>
945950 (mapM parseInline $ elContent e)
951+ equation constructor = return $ mconcat $
952+ map (constructor . writeTeX)
953+ $ rights
954+ $ map (readMathML . showElement . everywhere (mkT removePrefix))
955+ $ filterChildren (\x -> qName (elName x) == "math" &&
956+ qPrefix (elName x) == Just "mml") e
957+ removePrefix elname = elname { qPrefix = Nothing }
946958 codeWithLang = do
947959 let classes' = case attrValue "language" e of
948960 "" -> []