git.iko.soy/typeable/pandoc
on master help sign in
Infer caption from the text following the img
a02f276Hubert Plociniczak
src/Text/Pandoc/Readers/Odt/ContentReader.hs+47−20
@@ -543,6 +543,10 @@ read_plain_text = fst ^&&& read_plain_text' >>% recover
543 extractText (XML.Text cData) = succeedWith (XML.cdData cData)
543 extractText (XML.Text cData) = succeedWith (XML.cdData cData)
544 extractText _ = failEmpty
544 extractText _ = failEmpty
545
545
546+read_text_seq :: InlineMatcher
547+read_text_seq = matchingElement NsText "sequence"
548+ $ matchChildContent [] read_plain_text
549+
546
550
547-- specifically. I honor that, although the current implementation of '(<>)'
551-- specifically. I honor that, although the current implementation of '(<>)'
548-- for 'Inlines' in "Text.Pandoc.Builder" will collaps them agein.
552-- for 'Inlines' in "Text.Pandoc.Builder" will collaps them agein.
@@ -591,7 +595,8 @@ read_paragraph = matchingElement NsText "p"
591 , read_reference_start
595 , read_reference_start
592 , read_bookmark_ref
596 , read_bookmark_ref
593 , read_reference_ref
597 , read_reference_ref
594− , read_frame
598+ , read_maybe_nested_img_frame
599+ , read_text_seq
595 ] read_plain_text
600 ] read_plain_text
596
601
597
602
@@ -616,7 +621,7 @@ read_header = matchingElement NsText "h"
616 , read_reference_start
621 , read_reference_start
617 , read_bookmark_ref
622 , read_bookmark_ref
618 , read_reference_ref
623 , read_reference_ref
619− , read_frame
624+ , read_maybe_nested_img_frame
620 ] read_plain_text
625 ] read_plain_text
621 ) -< blocks
626 ) -< blocks
622 anchor <- getHeaderAnchor -< children
627 anchor <- getHeaderAnchor -< children
@@ -726,18 +731,26 @@ read_table_cell = matchingElement NsTable "table-cell"
726----------------------
731----------------------
727
732
728--
733--
729−read_frame :: InlineMatcher
734+read_maybe_nested_img_frame :: InlineMatcher
730−read_frame = matchingElement NsDraw "frame"
735+read_maybe_nested_img_frame = matchingElement NsDraw "frame"
731− $ proc blocks -> do
736+ $ proc blocks -> do
737+ img <- (findChild' NsDraw "image") -< ()
738+ case img of
739+ Just _ -> read_frame -< blocks
740+ Nothing -> matchChildContent' [ read_frame_text_box ] -< blocks
741+
742+read_frame :: OdtReaderSafe Inlines Inlines
743+read_frame =
744+ proc blocks -> do
732− w <- ( findAttr' NsSVG "width" ) -< ()
745+ w <- ( findAttr' NsSVG "width" ) -< ()
733− h <- ( findAttr' NsSVG "height" ) -< ()
746+ h <- ( findAttr' NsSVG "height" ) -< ()
734− attr <- arr (uncurry image_attributes) -< (w, h)
735− titleNodes <- ( matchChildContent' [ read_frame_title ] ) -< blocks
747+ titleNodes <- ( matchChildContent' [ read_frame_title ] ) -< blocks
736− title <- arr inlineListToIdentifier -< (toList titleNodes)
737− src <- matchChildContent' [ read_image_src ] -< blocks
748+ src <- matchChildContent' [ read_image_src ] -< blocks
738− resource <- lookupResource -< src
749+ resource <- lookupResource -< src
739− _ <- updateMediaWithResource -< resource
750+ _ <- updateMediaWithResource -< resource
751+ alt <- (matchChildContent [] read_plain_text) -< blocks
740− arr (uncurry4 imageWith ) -< (attr, src, title, mempty)
752+ arr (uncurry4 imageWith ) -<
753+ (image_attributes w h, src, inlineListToIdentifier (toList titleNodes), alt)
741
754
742image_attributes :: Maybe String -> Maybe String -> Attr
755image_attributes :: Maybe String -> Maybe String -> Attr
743image_attributes x y =
756image_attributes x y =
@@ -749,17 +762,31 @@ image_attributes x y =
749
762
750read_image_src :: (Namespace, ElementName, OdtReader Anchor Anchor)
763read_image_src :: (Namespace, ElementName, OdtReader Anchor Anchor)
751read_image_src = matchingElement NsDraw "image"
764read_image_src = matchingElement NsDraw "image"
752− $ proc _ -> do
765+ $ proc _ -> do
753− imgSrc <- findAttr NsXLink "href" -< ()
766+ imgSrc <- findAttr NsXLink "href" -< ()
754− case imgSrc of
767+ case imgSrc of
755− Right src -> returnV src -<< ()
768+ Right src -> returnV src -<< ()
756− Left _ -> returnV "" -< ()
769+ Left _ -> returnV "" -< ()
757
770
758read_frame_title :: InlineMatcher
771read_frame_title :: InlineMatcher
759read_frame_title = matchingElement NsSVG "title"
772read_frame_title = matchingElement NsSVG "title"
760 $ (matchChildContent [] read_plain_text)
773 $ (matchChildContent [] read_plain_text)
761
774
762−
775+read_frame_text_box :: InlineMatcher
776+read_frame_text_box = matchingElement NsDraw "text-box"
777+ $ proc blocks -> do
778+ paragraphs <- (matchChildContent' [ read_paragraph ]) -< blocks
779+ case toList paragraphs of
780+ (p : []) -> -- require only a single paragraph
781+ arr read_img_with_caption -< p
782+ _ ->
783+ arr fromList -< []
784+
785+read_img_with_caption :: Block -> Inlines
786+read_img_with_caption (Para ((Image attr _ target) : txt)) =
787+ singleton (Image attr txt target) -- override caption with the text that follows
788+read_img_with_caption _ =
789+ fromList []
763
790
764----------------------
791----------------------
765-- Internal links
792-- Internal links
tests/Tests/Readers/Odt.hs+4−2
@@ -141,7 +141,6 @@ namesOfTestsComparingToMarkdown = [ "bold"
141 , "footnote"
141 , "footnote"
142 , "headers"
142 , "headers"
143-- , "horizontalRule"
143-- , "horizontalRule"
144−-- , "image"
145 , "italic"
144 , "italic"
146-- , "listBlocks"
145-- , "listBlocks"
147 , "paragraph"
146 , "paragraph"
@@ -152,6 +151,9 @@ namesOfTestsComparingToMarkdown = [ "bold"
152
151
153namesOfTestsComparingToNative :: [ String ]
152namesOfTestsComparingToNative :: [ String ]
154namesOfTestsComparingToNative = [ "blockquote"
153namesOfTestsComparingToNative = [ "blockquote"
154+ , "image"
155+ , "imageIndex"
156+ , "imageWithCaption"
155 , "orderedListMixed"
157 , "orderedListMixed"
156 , "orderedListRoman"
158 , "orderedListRoman"
157 , "orderedListSimple"
159 , "orderedListSimple"
@@ -162,4 +164,4 @@ namesOfTestsComparingToNative = [ "blockquote"
162-- , "table"
164-- , "table"
163 , "unicode"
165 , "unicode"
164 , "unorderedList"
166 , "unorderedList"
165− ]
167+ ]
tests/odt/native/image.nativenew file+1
@@ -0,0 +1 @@
1+[Para [Image ("",[],[("width","5.292cm"),("height","5.292cm")]) [] ("Pictures/10000000000000FA000000FAD6A15225.jpg","")]]
tests/odt/native/imageIndex.nativenew file+1
@@ -0,0 +1 @@
1+[Para [Image ("",[],[("width","5.292cm"),("height","5.292cm")]) [Str "Abbildung",Space,Str "1:",Space,Str "Image",Space,Str "caption"] ("Pictures/10000000000000FA000000FAD6A15225.jpg","")]]
tests/odt/native/imageWithCaption.nativenew file+1
@@ -0,0 +1 @@
1+[Para [Image ("",[],[("width","5.292cm"),("height","5.292cm")]) [Str "Abbildung",Space,Str "1:",Space,Str "Image",Space,Str "caption"] ("Pictures/10000000000000FA000000FAD6A15225.jpg","")]]