git.iko.soy/typeable/pandoc
on master help sign in
ICML writer: added figure handling, closes #2590
commitf3a9bdafef45ef0990d302207410f014d75d9860 authormb21 <mb21@users.noreply.github.com> dateWed 16 Dec 2015, 10:18 (11 years ago) parent7c22959
2 files changed+28−4
src/Text/Pandoc/Writers/ICML.hs+12−3 tests/writer.icml+16−1
src/Text/Pandoc/Writers/ICML.hs+12−3
@@ -71,6 +71,8 @@ linkName = "Link"
7171
7272-- block element names (appear in InDesign's paragraph styles pane)
7373paragraphName :: String
74+figureName :: String
75+imgCaptionName :: String
7476codeBlockName :: String
7577blockQuoteName :: String
7678orderedListName :: String
@@ -94,6 +96,8 @@ subListParName :: String
9496footnoteName :: String
9597citeName :: String
9698paragraphName = "Paragraph"
99+figureName = "Figure"
100+imgCaptionName = "Caption"
97101codeBlockName = "CodeBlock"
98102blockQuoteName = "Blockquote"
99103orderedListName = "NumList"
@@ -285,6 +289,11 @@ blocksToICML opts style lst = vcat `fmap` mapM (blockToICML opts style) lst
285289-- | Convert a Pandoc block element to ICML.
286290blockToICML :: WriterOptions -> Style -> Block -> WS Doc
287291blockToICML opts style (Plain lst) = parStyle opts style lst
292+-- title beginning with fig: indicates that the image is a figure
293+blockToICML opts style (Para img@[Image _ txt (_,'f':'i':'g':':':_)]) = do
294+ figure <- parStyle opts (figureName:style) img
295+ caption <- parStyle opts (imgCaptionName:style) txt
296+ return $ figure $$ caption
288297blockToICML opts style (Para lst) = parStyle opts (paragraphName:style) lst
289298blockToICML opts style (CodeBlock _ str) = parStyle opts (codeBlockName:style) $ [Str str]
290299blockToICML _ _ (RawBlock f str)
@@ -434,7 +443,7 @@ inlineToICML opts style (Link _ lst (url, title)) = do
434443 cont = inTags True "HyperlinkTextSource"
435444 [("Self","htss-"++show ident), ("Name",title), ("Hidden","false")] content
436445 in (cont, newst)
437−inlineToICML opts style (Image attr alt target) = imageICML opts style attr alt target
446+inlineToICML opts style (Image attr _ target) = imageICML opts style attr target
438447inlineToICML opts style (Note lst) = footnoteToICML opts style lst
439448inlineToICML opts style (Span _ lst) = inlinesToICML opts style lst
440449
@@ -513,8 +522,8 @@ styleToStrAttr style =
513522 in (stlStr, attrs)
514523
515524-- | Assemble an ICML Image.
516−imageICML :: WriterOptions -> Style -> Attr -> [Inline] -> Target -> WS Doc
517−imageICML opts style attr _ (src, _) = do
525+imageICML :: WriterOptions -> Style -> Attr -> Target -> WS Doc
526+imageICML opts style attr (src, _) = do
518527 res <- liftIO $ fetchItem (writerSourceURL opts) src
519528 imgS <- case res of
520529 Left (_) -> do
tests/writer.icml+16−1
@@ -215,6 +215,11 @@
215215 </TabList>
216216 </Properties>
217217 </ParagraphStyle>
218+ <ParagraphStyle Self="ParagraphStyle/Caption" Name="Caption" LeftIndent="0">
219+ <Properties>
220+ <BasedOn type="object">$ID/NormalParagraphStyle</BasedOn>
221+ </Properties>
222+ </ParagraphStyle>
218223 <ParagraphStyle Self="ParagraphStyle/CodeBlock" Name="CodeBlock" LeftIndent="0">
219224 <Properties>
220225 <BasedOn type="object">$ID/NormalParagraphStyle</BasedOn>
@@ -257,6 +262,11 @@
257262 <BasedOn type="object">$ID/NormalParagraphStyle</BasedOn>
258263 </Properties>
259264 </ParagraphStyle>
265+ <ParagraphStyle Self="ParagraphStyle/Figure" Name="Figure" LeftIndent="0">
266+ <Properties>
267+ <BasedOn type="object">$ID/NormalParagraphStyle</BasedOn>
268+ </Properties>
269+ </ParagraphStyle>
260270 <ParagraphStyle Self="ParagraphStyle/Footnote &gt; CodeBlock" Name="Footnote &gt; CodeBlock" LeftIndent="0">
261271 <Properties>
262272 <BasedOn type="object">$ID/NormalParagraphStyle</BasedOn>
@@ -2542,7 +2552,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{</Content>
25422552 <Content> by Georges Melies (1902):</Content>
25432553 </CharacterStyleRange><Br />
25442554</ParagraphStyleRange>
2545−<ParagraphStyleRange AppliedParagraphStyle="ParagraphStyle/Paragraph">
2555+<ParagraphStyleRange AppliedParagraphStyle="ParagraphStyle/Figure">
25462556 <CharacterStyleRange AppliedCharacterStyle="$ID/NormalCharacterStyle">
25472557 <Rectangle Self="uec" StrokeWeight="0" ItemTransform="1.00000 0 0 1.00000 75.00000 -75.00000">
25482558 <Properties>
@@ -2568,6 +2578,11 @@ These should not be escaped: \$ \\ \&gt; \[ \{</Content>
25682578 </Rectangle>
25692579 </CharacterStyleRange><Br />
25702580</ParagraphStyleRange>
2581+<ParagraphStyleRange AppliedParagraphStyle="ParagraphStyle/Caption">
2582+ <CharacterStyleRange AppliedCharacterStyle="$ID/NormalCharacterStyle">
2583+ <Content>lalune</Content>
2584+ </CharacterStyleRange><Br />
2585+</ParagraphStyleRange>
25712586<ParagraphStyleRange AppliedParagraphStyle="ParagraphStyle/Paragraph">
25722587 <CharacterStyleRange AppliedCharacterStyle="$ID/NormalCharacterStyle">
25732588 <Content>Here is a movie </Content>