@@ -341,6 +341,32 @@ testChecksFail tk =
341
341
assertBool " " (expectedCheck result)
342
342
assertChecksFail _ = assertEqual " Test skipped" True True
343
343
344
+ -------------------------------------------------------------------------------
345
+ -- Test that Markdown bold formatting in captions is correctly rendered
346
+ testAttributesPreservedOnFigure :: Toolkit -> TestTree
347
+ testAttributesPreservedOnFigure tk =
348
+ testCase " preserves code block attributes and sets them on the Figure element" $ do
349
+ let postfix = unpack . cls $ tk
350
+ tempDir <- (</> " test-preserved-attrs-" <> postfix) <$> getTemporaryDirectory
351
+ ensureDirectoryExistsAndEmpty tempDir
352
+
353
+ -- Note that this test is fragile, in the sense that the expected result must be carefully
354
+ -- constructed
355
+ let expectedAttrs = (" hello" , [cls tk], [(" key1" , " val1" ), (" key2" , " val2" )])
356
+ cb = setAttrs expectedAttrs $
357
+ addDirectory tempDir $
358
+ addCaption " [title](https://google.com)" $
359
+ codeBlock tk (trivialContent tk)
360
+ fmt = B. Format " markdown"
361
+ Figure (id', _, keyvals) _ _ <- runPlotM Nothing (defaultTestConfig { captionFormat = fmt
362
+ , defaultDirectory = tempDir
363
+ }) $ make cb
364
+ let (expectedId, _, expectedKeyVals) = expectedAttrs
365
+ assertEqual " identifier" expectedId id'
366
+ assertEqual " key-value pairs" expectedKeyVals keyvals
367
+ where
368
+ extractCaption (B. Figure _ (Caption _ caption) _) = caption
369
+
344
370
codeBlock :: Toolkit -> Script -> Block
345
371
codeBlock tk script = CodeBlock (mempty , [cls tk], mempty ) script
346
372
@@ -388,6 +414,9 @@ addWithSource :: Bool -> Block -> Block
388
414
addWithSource yn (CodeBlock (id', cls, attrs) script) =
389
415
CodeBlock (id', cls, attrs ++ [(tshow WithSourceK , pack . show $ yn)]) script
390
416
417
+ setAttrs :: Attr -> Block -> Block
418
+ setAttrs attrs (CodeBlock _ script) = CodeBlock attrs script
419
+
391
420
-- | Assert that a file exists
392
421
assertFileExists :: HasCallStack => FilePath -> Assertion
393
422
assertFileExists filepath = do
0 commit comments