@@ -17,7 +17,7 @@ import Control.Monad.State.Strict
1717import Data.Array
1818import Data.Text (Text)
1919import Text.Pandoc.Definition
20−import Text.Pandoc.Class.PandocMonad (PandocMonad)
20+import Text.Pandoc.Class.PandocMonad (PandocMonad, translateTerm)
2121import Text.Pandoc.Writers.Docx.Types
2222import Text.Pandoc.Shared
2323import Text.Printf (printf)
@@ -25,6 +25,7 @@ import Text.Pandoc.Writers.GridTable hiding (Table)
2525import Text.Pandoc.Writers.OOXML
2626import Text.Pandoc.XML.Light as XML hiding (Attr)
2727import qualified Data.Text as T
28+import qualified Text.Pandoc.Translations as Term
2829import qualified Text.Pandoc.Writers.GridTable as Grid
2930
3031tableToOpenXML :: PandocMonad m
@@ -33,15 +34,23 @@ tableToOpenXML :: PandocMonad m
3334 -> WS m [Content]
3435tableToOpenXML blocksToOpenXML gridTable = do
3536 setFirstPara
36− let (Grid.Table _attr caption colspecs _rowheads thead tbodies tfoot) =
37+ let (Grid.Table (ident,_,_) caption colspecs _rowheads thead tbodies tfoot) =
3738 gridTable
3839 let (Caption _maybeShortCaption captionBlocks) = caption
40+ tablenum <- gets stNextTableNum
41+ unless (null captionBlocks) $
42+ modify $ \st -> st{ stNextTableNum = tablenum + 1 }
43+ let tableid = if T.null ident
44+ then "table" <> tshow tablenum
45+ else ident
46+ tablename <- translateTerm Term.Table
3947 let captionStr = stringify captionBlocks
4048 let aligns = map fst $ elems colspecs
4149 captionXml <- if null captionBlocks
4250 then return []
4351 else withParaPropM (pStyleM "Table Caption")
44− $ blocksToOpenXML captionBlocks
52+ $ blocksToOpenXML
53+ $ addLabel tableid tablename tablenum captionBlocks
4554 -- We set "in table" after processing the caption, because we don't
4655 -- want the "Table Caption" style to be overwritten with "Compact".
4756 modify $ \s -> s { stInTable = True }
@@ -81,6 +90,22 @@ tableToOpenXML blocksToOpenXML gridTable = do
8190 modify $ \s -> s { stInTable = False }
8291 return $ captionXml ++ [Elem tbl]
8392
93+addLabel :: Text -> Text -> Int -> [Block] -> [Block]
94+addLabel tableid tablename tablenum bs =
95+ case bs of
96+ (Para ils : rest) -> Para (label : Space : ils) : rest
97+ (Plain ils : rest) -> Plain (label : Space : ils) : rest
98+ _ -> Para [label] : bs
99+ where
100+ label = Span (tableid,[],[])
101+ [Str (tablename <> "\160"),
102+ RawInline (Format "openxml")
103+ ("<w:fldSimple w:instr=\"SEQ Table"
104+ <> " \\* ARABIC \"><w:r><w:t>"
105+ <> tshow tablenum
106+ <> "</w:t></w:r></w:fldSimple>"),
107+ Str ":"]
108+
84109-- | Parts of a table
85110data RowType = HeadRow | BodyRow | FootRow
86111