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.
This commit is contained in:
John MacFarlane
2020-01-19 18:24:32 -08:00
committed by GitHub
parent 5028278569
commit ff4dd2b1dd
+9 -1
View File
@@ -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]