aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2020-01-19 18:24:32 -0800
committerGitHub <noreply@github.com>2020-01-19 18:24:32 -0800
commitff4dd2b1dd162d55de697b5a64cd73c8b2dd2ebc (patch)
treea87fe523df9cd6ad9170d3818d865363b83c453b /src
parent5028278569bdc06ced5b8151393e2d12602f1b7e (diff)
downloadpandoc-ff4dd2b1dd162d55de697b5a64cd73c8b2dd2ebc.tar.gz
Docx writer: fix regression with Compact style on tight lists. (#6073)
Starting in 2.8, the docx writer no longer distinguishes between tight and loose lists, since the Compact style is omitted. This is a side-effect of the fix to #5670, as explained in the changelog: + Preserve built-in styles in DOCX with custom style (Ben Steinberg, #5670). This change prevents custom styles on divs and spans from overriding styles on certain elements inside them, like headings, blockquotes, and links. On those elements, the "native" style is required for the element to display correctly. This change also allows nesting of custom styles; in order to do so, it removes the default "Compact" style applied to Plain blocks, except when inside a table. This patch fixes the problem by extending the exception currently offered to Plain blocks inside tables to Plain blocks inside list items. Closes #6072.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Writers/Docx.hs10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/Text/Pandoc/Writers/Docx.hs b/src/Text/Pandoc/Writers/Docx.hs
index 3c387d9d9..8959e8210 100644
--- a/src/Text/Pandoc/Writers/Docx.hs
+++ b/src/Text/Pandoc/Writers/Docx.hs
@@ -137,6 +137,7 @@ data WriterState = WriterState{
, stStyleMaps :: StyleMaps
, stFirstPara :: Bool
, stInTable :: Bool
+ , stInList :: Bool
, stTocTitle :: [Inline]
, stDynamicParaProps :: Set.Set ParaStyleName
, stDynamicTextProps :: Set.Set CharStyleName
@@ -156,6 +157,7 @@ defaultWriterState = WriterState{
, stStyleMaps = StyleMaps M.empty M.empty
, stFirstPara = False
, stInTable = False
+ , stInList = False
, stTocTitle = [Str "Table of Contents"]
, stDynamicParaProps = Set.empty
, stDynamicTextProps = Set.empty
@@ -925,9 +927,12 @@ blockToOpenXML' opts (Header lev (ident,_,_) lst) = do
return [mknode "w:p" [] (paraProps ++ bookmarkedContents)]
blockToOpenXML' opts (Plain lst) = do
isInTable <- gets stInTable
+ isInList <- gets stInList
let block = blockToOpenXML opts (Para lst)
prop <- pStyleM "Compact"
- if isInTable then withParaProp prop block else block
+ if isInTable || isInList
+ then withParaProp prop block
+ else block
-- title beginning with fig: indicates that the image is a figure
blockToOpenXML' opts (Para [Image attr alt (src,T.stripPrefix "fig:" -> Just tit)]) = do
setFirstPara
@@ -1067,9 +1072,12 @@ addList marker = do
listItemToOpenXML :: (PandocMonad m) => WriterOptions -> Int -> [Block] -> WS m [Element]
listItemToOpenXML _ _ [] = return []
listItemToOpenXML opts numid (first:rest) = do
+ oldInList <- gets stInList
+ modify $ \st -> st{ stInList = True }
first' <- withNumId numid $ blockToOpenXML opts first
-- baseListId is the code for no list marker:
rest' <- withNumId baseListId $ blocksToOpenXML opts rest
+ modify $ \st -> st{ stInList = oldInList }
return $ first' ++ rest'
alignmentToString :: Alignment -> [Char]