Docx writer: properly handle display math in spans.
Closes #4826. This isn't a complete solution, since other nestings of display math may still cause problems, but it should work for what is by far the most common case. Note that this also involves an API change: `isDisplayMath` is now exported from Text.Pandoc.Writers.Shared.
This commit is contained in:
parent
175da00295
commit
4ec02053bb
2 changed files with 10 additions and 6 deletions
|
@ -66,7 +66,8 @@ import Text.Pandoc.Readers.Docx.StyleMap
|
|||
import Text.Pandoc.Shared hiding (Element)
|
||||
import Text.Pandoc.Walk
|
||||
import Text.Pandoc.Writers.Math
|
||||
import Text.Pandoc.Writers.Shared (fixDisplayMath, metaValueToInlines)
|
||||
import Text.Pandoc.Writers.Shared (isDisplayMath, fixDisplayMath,
|
||||
metaValueToInlines)
|
||||
import Text.Printf (printf)
|
||||
import Text.TeXMath
|
||||
import Text.XML.Light as XML
|
||||
|
@ -915,9 +916,10 @@ blockToOpenXML' opts (Para lst)
|
|||
| null lst && not (isEnabled Ext_empty_paragraphs opts) = return []
|
||||
| otherwise = do
|
||||
isFirstPara <- gets stFirstPara
|
||||
paraProps <- getParaProps $ case lst of
|
||||
[Math DisplayMath _] -> True
|
||||
_ -> False
|
||||
let displayMathPara = case lst of
|
||||
[x] -> isDisplayMath x
|
||||
_ -> False
|
||||
paraProps <- getParaProps displayMathPara
|
||||
bodyTextStyle <- pStyleM "Body Text"
|
||||
let paraProps' = case paraProps of
|
||||
[] | isFirstPara -> [mknode "w:pPr" []
|
||||
|
|
|
@ -38,6 +38,7 @@ module Text.Pandoc.Writers.Shared (
|
|||
, resetField
|
||||
, defField
|
||||
, tagWithAttrs
|
||||
, isDisplayMath
|
||||
, fixDisplayMath
|
||||
, unsmartify
|
||||
, gridTable
|
||||
|
@ -187,8 +188,9 @@ tagWithAttrs tag (ident,classes,kvs) = hsep
|
|||
] <> ">"
|
||||
|
||||
isDisplayMath :: Inline -> Bool
|
||||
isDisplayMath (Math DisplayMath _) = True
|
||||
isDisplayMath _ = False
|
||||
isDisplayMath (Math DisplayMath _) = True
|
||||
isDisplayMath (Span _ [Math DisplayMath _]) = True
|
||||
isDisplayMath _ = False
|
||||
|
||||
stripLeadingTrailingSpace :: [Inline] -> [Inline]
|
||||
stripLeadingTrailingSpace = go . reverse . go . reverse
|
||||
|
|
Loading…
Add table
Reference in a new issue