git.iko.soy/typeable/pandoc
on master help sign in
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.

commitff4dd2b1dd162d55de697b5a64cd73c8b2dd2ebc authorJohn MacFarlane <jgm@berkeley.edu> dateSun 19 Jan 2020, 18:24 (7 years ago) parent5028278
1 file changed+9−1
src/Text/Pandoc/Writers/Docx.hs+9−1
src/Text/Pandoc/Writers/Docx.hs+9−1
@@ -137,6 +137,7 @@ data WriterState = WriterState{
137137 , stStyleMaps :: StyleMaps
138138 , stFirstPara :: Bool
139139 , stInTable :: Bool
140+ , stInList :: Bool
140141 , stTocTitle :: [Inline]
141142 , stDynamicParaProps :: Set.Set ParaStyleName
142143 , stDynamicTextProps :: Set.Set CharStyleName
@@ -156,6 +157,7 @@ defaultWriterState = WriterState{
156157 , stStyleMaps = StyleMaps M.empty M.empty
157158 , stFirstPara = False
158159 , stInTable = False
160+ , stInList = False
159161 , stTocTitle = [Str "Table of Contents"]
160162 , stDynamicParaProps = Set.empty
161163 , stDynamicTextProps = Set.empty
@@ -925,9 +927,12 @@ blockToOpenXML' opts (Header lev (ident,_,_) lst) = do
925927 return [mknode "w:p" [] (paraProps ++ bookmarkedContents)]
926928blockToOpenXML' opts (Plain lst) = do
927929 isInTable <- gets stInTable
930+ isInList <- gets stInList
928931 let block = blockToOpenXML opts (Para lst)
929932 prop <- pStyleM "Compact"
930− if isInTable then withParaProp prop block else block
933+ if isInTable || isInList
934+ then withParaProp prop block
935+ else block
931936-- title beginning with fig: indicates that the image is a figure
932937blockToOpenXML' opts (Para [Image attr alt (src,T.stripPrefix "fig:" -> Just tit)]) = do
933938 setFirstPara
@@ -1067,9 +1072,12 @@ addList marker = do
10671072listItemToOpenXML :: (PandocMonad m) => WriterOptions -> Int -> [Block] -> WS m [Element]
10681073listItemToOpenXML _ _ [] = return []
10691074listItemToOpenXML opts numid (first:rest) = do
1075+ oldInList <- gets stInList
1076+ modify $ \st -> st{ stInList = True }
10701077 first' <- withNumId numid $ blockToOpenXML opts first
10711078 -- baseListId is the code for no list marker:
10721079 rest' <- withNumId baseListId $ blocksToOpenXML opts rest
1080+ modify $ \st -> st{ stInList = oldInList }
10731081 return $ first' ++ rest'
10741082
10751083alignmentToString :: Alignment -> [Char]