summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorhubertp-lshift <hubertp@lshift.de>2016-11-26 21:45:56 +0100
committerJohn MacFarlane <jgm@berkeley.edu>2016-11-26 21:45:56 +0100
commit015dead0bb2bb5cea06a0fa366fdd651c8e07889 (patch)
treeab88036f84b91ddd4009f63a1bd4f9e52ffafae0 /src
parentbaa25362a40fe905368f60222ebd8a533bcfe0f9 (diff)
[odt] Infer table's caption from the paragraph (#3224)
ODT's reader always put empty captions for the parsed tables. This commit 1) checks paragraphs that follow the table definition 2) treats specially a paragraph with a style named 'Table' 3) does some postprocessing of the paragraphs that combines tables followed immediately by captions The ODT writer used 'TableCaption' style name for the caption paragraph. This commit follows the open office approach which allows for appending captions to table but uses a built-in style named 'Table' instead of 'TableCaption'. Any users of odt format (both writer and reader) are therefore required to change the style's name to 'Table', if necessary.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Readers/Odt/ContentReader.hs27
-rw-r--r--src/Text/Pandoc/Writers/OpenDocument.hs2
2 files changed, 22 insertions, 7 deletions
diff --git a/src/Text/Pandoc/Readers/Odt/ContentReader.hs b/src/Text/Pandoc/Readers/Odt/ContentReader.hs
index 3a6a99237..2672b01ef 100644
--- a/src/Text/Pandoc/Readers/Odt/ContentReader.hs
+++ b/src/Text/Pandoc/Readers/Odt/ContentReader.hs
@@ -312,7 +312,7 @@ withNewStyle a = proc x -> do
where
isCodeStyle :: StyleName -> Bool
isCodeStyle "Source_Text" = True
- isCodeStyle _ = False
+ isCodeStyle _ = False
inlineCode :: Inlines -> Inlines
inlineCode = code . intercalate "" . map stringify . toList
@@ -415,12 +415,18 @@ constructPara reader = proc blocks -> do
fStyle <- readStyleByName -< blocks
case fStyle of
Left _ -> reader -< blocks
+ Right (styleName, _) | isTableCaptionStyle styleName -> do
+ blocks' <- reader -< blocks
+ arr tableCaptionP -< blocks'
Right (_, style) -> do
let modifier = getParaModifier style
- blocks' <- reader -< blocks
- arr modifier -<< blocks'
-
-
+ blocks' <- reader -< blocks
+ arr modifier -<< blocks'
+ where
+ isTableCaptionStyle :: StyleName -> Bool
+ isTableCaptionStyle "Table" = True
+ isTableCaptionStyle _ = False
+ tableCaptionP b = divWith ("", ["caption"], []) b
type ListConstructor = [Blocks] -> Blocks
@@ -904,6 +910,15 @@ read_text = matchChildContent' [ read_header
]
>>^ doc
+post_process :: Pandoc -> Pandoc
+post_process (Pandoc m blocks) =
+ Pandoc m (post_process' blocks)
+
+post_process' :: [Block] -> [Block]
+post_process' ((Table _ a w h r) : (Div ("", ["caption"], _) [Para inlines] ) : xs) =
+ (Table inlines a w h r) : ( post_process' xs )
+post_process' bs = bs
+
read_body :: OdtReader _x (Pandoc, MediaBag)
read_body = executeIn NsOffice "body"
$ executeIn NsOffice "text"
@@ -911,4 +926,4 @@ read_body = executeIn NsOffice "body"
$ proc inlines -> do
txt <- read_text -< inlines
state <- getExtraState -< ()
- returnA -< (txt, getMediaBag state)
+ returnA -< (post_process txt, getMediaBag state)
diff --git a/src/Text/Pandoc/Writers/OpenDocument.hs b/src/Text/Pandoc/Writers/OpenDocument.hs
index 42c151780..8bd0f469e 100644
--- a/src/Text/Pandoc/Writers/OpenDocument.hs
+++ b/src/Text/Pandoc/Writers/OpenDocument.hs
@@ -336,7 +336,7 @@ blockToOpenDocument o bs
mapM_ addParaStyle . newPara $ paraHStyles ++ paraStyles
captionDoc <- if null c
then return empty
- else withParagraphStyle o "TableCaption" [Para c]
+ else withParagraphStyle o "Table" [Para c]
th <- if all null h
then return empty
else colHeadsToOpenDocument o name (map fst paraHStyles) h