"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/Text/Pandoc/Writers/Docx/Table.hs" between
pandoc-2.14.0.3.tar.gz and pandoc-2.14.1.tar.gz

About: Pandoc converts files from one markup format into another.

Table.hs  (pandoc-2.14.0.3):Table.hs  (pandoc-2.14.1)
skipping to change at line 20 skipping to change at line 20
Conversion of table blocks to docx. Conversion of table blocks to docx.
-} -}
module Text.Pandoc.Writers.Docx.Table module Text.Pandoc.Writers.Docx.Table
( tableToOpenXML ( tableToOpenXML
) where ) where
import Control.Monad.State.Strict import Control.Monad.State.Strict
import Data.Array import Data.Array
import Data.Text (Text) import Data.Text (Text)
import Text.Pandoc.Definition import Text.Pandoc.Definition
import Text.Pandoc.Class.PandocMonad (PandocMonad) import Text.Pandoc.Class.PandocMonad (PandocMonad, translateTerm)
import Text.Pandoc.Writers.Docx.Types import Text.Pandoc.Writers.Docx.Types
import Text.Pandoc.Shared import Text.Pandoc.Shared
import Text.Printf (printf) import Text.Printf (printf)
import Text.Pandoc.Writers.GridTable hiding (Table) import Text.Pandoc.Writers.GridTable hiding (Table)
import Text.Pandoc.Writers.OOXML import Text.Pandoc.Writers.OOXML
import Text.Pandoc.XML.Light as XML hiding (Attr) import Text.Pandoc.XML.Light as XML hiding (Attr)
import qualified Data.Text as T import qualified Data.Text as T
import qualified Text.Pandoc.Translations as Term
import qualified Text.Pandoc.Writers.GridTable as Grid import qualified Text.Pandoc.Writers.GridTable as Grid
tableToOpenXML :: PandocMonad m tableToOpenXML :: PandocMonad m
=> ([Block] -> WS m [Content]) => ([Block] -> WS m [Content])
-> Grid.Table -> Grid.Table
-> WS m [Content] -> WS m [Content]
tableToOpenXML blocksToOpenXML gridTable = do tableToOpenXML blocksToOpenXML gridTable = do
setFirstPara setFirstPara
let (Grid.Table _attr caption colspecs _rowheads thead tbodies tfoot) = let (Grid.Table (ident,_,_) caption colspecs _rowheads thead tbodies tfoot) =
gridTable gridTable
let (Caption _maybeShortCaption captionBlocks) = caption let (Caption _maybeShortCaption captionBlocks) = caption
tablenum <- gets stNextTableNum
unless (null captionBlocks) $
modify $ \st -> st{ stNextTableNum = tablenum + 1 }
let tableid = if T.null ident
then "table" <> tshow tablenum
else ident
tablename <- translateTerm Term.Table
let captionStr = stringify captionBlocks let captionStr = stringify captionBlocks
let aligns = map fst $ elems colspecs let aligns = map fst $ elems colspecs
captionXml <- if null captionBlocks captionXml <- if null captionBlocks
then return [] then return []
else withParaPropM (pStyleM "Table Caption") else withParaPropM (pStyleM "Table Caption")
$ blocksToOpenXML captionBlocks $ blocksToOpenXML
$ addLabel tableid tablename tablenum captionBlocks
-- We set "in table" after processing the caption, because we don't -- We set "in table" after processing the caption, because we don't
-- want the "Table Caption" style to be overwritten with "Compact". -- want the "Table Caption" style to be overwritten with "Compact".
modify $ \s -> s { stInTable = True } modify $ \s -> s { stInTable = True }
head' <- cellGridToOpenXML blocksToOpenXML HeadRow aligns thead head' <- cellGridToOpenXML blocksToOpenXML HeadRow aligns thead
bodies <- mapM (cellGridToOpenXML blocksToOpenXML BodyRow aligns) tbodies bodies <- mapM (cellGridToOpenXML blocksToOpenXML BodyRow aligns) tbodies
foot' <- cellGridToOpenXML blocksToOpenXML FootRow aligns tfoot foot' <- cellGridToOpenXML blocksToOpenXML FootRow aligns tfoot
let hasHeader = not . null . indices . partRowAttrs $ thead let hasHeader = not . null . indices . partRowAttrs $ thead
let hasFooter = not . null . indices . partRowAttrs $ tfoot let hasFooter = not . null . indices . partRowAttrs $ tfoot
-- for compatibility with Word <= 2007, we include a val with a bitmask -- for compatibility with Word <= 2007, we include a val with a bitmask
skipping to change at line 84 skipping to change at line 93
] () : ] () :
[ mknode "w:tblCaption" [("w:val", captionStr)] () [ mknode "w:tblCaption" [("w:val", captionStr)] ()
| not (T.null captionStr) ] | not (T.null captionStr) ]
) )
: mknode "w:tblGrid" [] gridCols : mknode "w:tblGrid" [] gridCols
: head' ++ mconcat bodies ++ foot' : head' ++ mconcat bodies ++ foot'
) )
modify $ \s -> s { stInTable = False } modify $ \s -> s { stInTable = False }
return $ captionXml ++ [Elem tbl] return $ captionXml ++ [Elem tbl]
addLabel :: Text -> Text -> Int -> [Block] -> [Block]
addLabel tableid tablename tablenum bs =
case bs of
(Para ils : rest) -> Para (label : Space : ils) : rest
(Plain ils : rest) -> Plain (label : Space : ils) : rest
_ -> Para [label] : bs
where
label = Span (tableid,[],[])
[Str (tablename <> "\160"),
RawInline (Format "openxml")
("<w:fldSimple w:instr=\"SEQ Table"
<> " \\* ARABIC \"><w:r><w:t>"
<> tshow tablenum
<> "</w:t></w:r></w:fldSimple>"),
Str ":"]
-- | Parts of a table -- | Parts of a table
data RowType = HeadRow | BodyRow | FootRow data RowType = HeadRow | BodyRow | FootRow
alignmentToString :: Alignment -> Text alignmentToString :: Alignment -> Text
alignmentToString = \case alignmentToString = \case
AlignLeft -> "left" AlignLeft -> "left"
AlignRight -> "right" AlignRight -> "right"
AlignCenter -> "center" AlignCenter -> "center"
AlignDefault -> "left" AlignDefault -> "left"
 End of changes. 6 change blocks. 
3 lines changed or deleted 28 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)