Skip to content

Commit 7168fe3

Browse files
committed
Use simpleFigureWith in ODT reader
1 parent 46da81a commit 7168fe3

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

src/Text/Pandoc/Readers/Odt.hs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import System.FilePath
2222

2323
import Control.Monad.Except (throwError)
2424

25+
import Data.Text (Text)
2526
import qualified Data.Text as T
2627

2728
import Text.Pandoc.Class.PandocMonad (PandocMonad)
@@ -85,9 +86,22 @@ archiveToOdt archive = do
8586
in (dir == "Pictures/") || (dir /= "./" && name == "content.xml")
8687
let media = filteredFilesFromArchive archive filePathIsOdtMedia
8788
let startState = readerState styles media
88-
either (\_ -> Left $ PandocParseError "Could not convert opendocument") Right
89+
either
90+
(\_ -> Left $ PandocParseError "Could not convert opendocument")
91+
(\(Pandoc meta blocks, mediabag) -> Right (Pandoc meta (fmap floatFigures blocks), mediabag))
8992
(runConverter' read_body startState contentElem)
9093

94+
where
95+
-- Capture all images as floating figures
96+
floatFigures :: Block -> Block
97+
floatFigures (Para [Image attr figureCaption (url, title)]) =
98+
simpleFigureBlockWith attr figureCaption url title
99+
floatFigures x = x
100+
101+
simpleFigureBlockWith :: Text.Pandoc.Definition.Attr -> [Inline] -> Text -> Text -> Block
102+
simpleFigureBlockWith attr figureCaption url title =
103+
Para [Image attr figureCaption (url, "fig:" <> title)]
104+
91105

92106
--
93107
entryToXmlElem :: Entry -> Either PandocError Element

src/Text/Pandoc/Readers/Odt/ContentReader.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -819,13 +819,13 @@ read_frame_mathml =
819819
read_frame_text_box :: OdtReaderSafe XML.Element (FirstMatch Inlines)
820820
read_frame_text_box = proc box -> do
821821
paragraphs <- executeIn (matchChildContent' [ read_paragraph ]) -< box
822-
arr read_img_with_caption -< toList paragraphs
822+
arr read_img_with_caption -< toList paragraphs
823823

824824
read_img_with_caption :: [Block] -> FirstMatch Inlines
825825
read_img_with_caption (Para [Image attr alt (src,title)] : _) =
826-
firstMatch $ singleton (Image attr alt (src, "fig:" <> title)) -- no text, default caption
826+
firstMatch $ singleton (Image attr alt (src, title)) -- no text, default caption
827827
read_img_with_caption (Para (Image attr _ (src,title) : txt) : _) =
828-
firstMatch $ singleton (Image attr txt (src, "fig:" <> title) ) -- override caption with the text that follows
828+
firstMatch $ singleton (Image attr txt (src, title) ) -- override caption with the text that follows
829829
read_img_with_caption ( Para (_ : xs) : ys) =
830830
read_img_with_caption (Para xs : ys)
831831
read_img_with_caption _ =

test/odt/native/image.native

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[Para [Image ("",[],[("width","5.292cm"),("height","5.292cm")]) [] ("Pictures/10000000000000FA000000FAD6A15225.jpg","")]]
1+
[Para [Image ("",[],[("width","5.292cm"),("height","5.292cm")]) [] ("Pictures/10000000000000FA000000FAD6A15225.jpg","fig:")]]

0 commit comments

Comments
 (0)