@@ -179,20 +179,16 @@ testWithSource tk =
179179 addDirectory tempDir $
180180 addCaption expected $
181181 codeBlock tk (trivialContent tk)
182- blockNoSource <- runPlotM Nothing defaultTestConfig $ make noSource
182+ blockNoSource <- runPlotM Nothing defaultTestConfig $ make noSource
183183 blockWithSource <- runPlotM Nothing defaultTestConfig $ make withSource
184184
185185 -- In the case where source=false, the caption is used verbatim.
186186 -- Otherwise, links will be appended to the caption; hence, the caption
187187 -- is no longer equal to the initial value
188- assertEqual " " ( B. toList $ fromString expected) (extractCaption blockNoSource)
189- assertNotEqual " " ( B. toList $ fromString expected) (extractCaption blockWithSource)
188+ assertEqual " " [ B. Plain $ B. toList ( fromString expected)] (extractCaption blockNoSource)
189+ assertNotEqual " " [ B. Plain $ B. toList ( fromString expected)] (extractCaption blockWithSource)
190190 where
191- extractCaption (B. Para blocks) = extractImageCaption . head $ blocks
192- extractCaption _ = mempty
193-
194- extractImageCaption (Image _ c _) = c
195- extractImageCaption _ = mempty
191+ extractCaption (B. Figure _ (Caption _ caption) _) = caption
196192
197193-------------------------------------------------------------------------------
198194-- Test that it is possible to change the source code label in captions
@@ -212,17 +208,12 @@ testSourceLabel tk =
212208 codeBlock tk (trivialContent tk)
213209 blockWithSource <- runPlotM Nothing defaultTestConfig {sourceCodeLabel = " Test label" } $ make withSource
214210
215- -- The caption will look like [Space, Str "(", Link ... ]. Hence, we skip the first elements with (!!)
216- let resultCaption = linkLabel $ (!! 2 ) . B. toList $ extractCaption blockWithSource
217- assertEqual " " (B. str " Test label" ) resultCaption
211+ let [Plain [Space , _, B. Link _ ils _, _]] = extractCaption blockWithSource
212+ assertEqual " " (B. toList $ B. str " Test label" ) ils
218213 where
219- extractCaption (B. Para blocks) = extractImageCaption . head $ blocks
220- extractCaption _ = mempty
221-
222- extractImageCaption (Image _ c _) = B. fromList c
223- extractImageCaption _ = mempty
214+ extractCaption (B. Figure _ (Caption _ caption) _) = caption
224215
225- linkLabel (B. Link _ ils _) = B. fromList ils
216+ linkLabel (B. Plain [ B. Link _ ils _] ) = B. fromList ils
226217 linkLabel _ = mempty
227218
228219-------------------------------------------------------------------------------
@@ -276,7 +267,7 @@ testMarkdownFormattingCaption1 tk =
276267
277268 -- Note that this test is fragile, in the sense that the expected result must be carefully
278269 -- constructed
279- let expected = [B. Strong [B. Str " caption" ]]
270+ let expected = [B. Plain [ B. Strong [B. Str " caption" ] ]]
280271 cb =
281272 addDirectory tempDir $
282273 addCaption " **caption**" $
@@ -285,11 +276,7 @@ testMarkdownFormattingCaption1 tk =
285276 result <- runPlotM Nothing (defaultTestConfig {captionFormat = fmt}) $ make cb
286277 assertIsInfix expected (extractCaption result)
287278 where
288- extractCaption (B. Para blocks) = extractImageCaption . head $ blocks
289- extractCaption _ = mempty
290-
291- extractImageCaption (Image _ c _) = c
292- extractImageCaption _ = mempty
279+ extractCaption (B. Figure _ (Caption _ caption) _) = caption
293280
294281-------------------------------------------------------------------------------
295282-- Test that Markdown bold formatting in captions is correctly rendered
@@ -302,7 +289,7 @@ testMarkdownFormattingCaption2 tk =
302289
303290 -- Note that this test is fragile, in the sense that the expected result must be carefully
304291 -- constructed
305- let expected = [Link (" " , [] , [] ) [Str " title" ] (" https://google.com" , " " )]
292+ let expected = [B. Plain [ Link (" " , [] , [] ) [Str " title" ] (" https://google.com" , " " )] ]
306293 cb =
307294 addDirectory tempDir $
308295 addCaption " [title](https://google.com)" $
@@ -311,35 +298,7 @@ testMarkdownFormattingCaption2 tk =
311298 result <- runPlotM Nothing (defaultTestConfig {captionFormat = fmt}) $ make cb
312299 assertIsInfix expected (extractCaption result)
313300 where
314- extractCaption (B. Para blocks) = extractImageCaption . head $ blocks
315- extractCaption _ = mempty
316-
317- extractImageCaption (Image _ c _) = c
318- extractImageCaption _ = mempty
319-
320- -------------------------------------------------------------------------------
321- -- Test that Markdown bold formatting in captions is correctly rendered
322- testFigureWithoutCaption :: Toolkit -> TestTree
323- testFigureWithoutCaption tk =
324- testCase " appropriately build an image if no caption" $ do
325- let postfix = unpack . cls $ tk
326- tempDir <- (</> " test-image-if-no-caption-" <> postfix) <$> getTemporaryDirectory
327- ensureDirectoryExistsAndEmpty tempDir
328-
329- -- Note that this test is fragile, in the sense that the expected result must be carefully
330- -- constructed
331- let cb =
332- addDirectory tempDir $ codeBlock tk (trivialContent tk)
333- fmt = B. Format " markdown"
334- result <- runPlotM Nothing (defaultTestConfig {captionFormat = fmt}) $ make cb
335- assertEqual " " (Just mempty ) (extractTitle result)
336- where
337- extractTitle (B. Para blocks) = extractImageCaption . head $ blocks
338- extractTitle _ = Nothing
339-
340- extractImageCaption (Image _ _ (_, title)) = Just title
341- extractImageCaption _ = Nothing
342-
301+ extractCaption (B. Figure _ (Caption _ caption) _) = caption
343302
344303-------------------------------------------------------------------------------
345304-- Test that cleanOutpuDirs correctly cleans the output directory specified in a block.
0 commit comments