Skip to content

Commit 343a9e1

Browse files
committed
Add the SimpleFigure bidirectional pattern synonym.
1 parent 757cca3 commit 343a9e1

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/Text/Pandoc/Builder.hs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses, DeriveDataTypeable,
22
GeneralizedNewtypeDeriving, CPP, StandaloneDeriving, DeriveGeneric,
3-
DeriveTraversable, OverloadedStrings, PatternGuards #-}
3+
DeriveTraversable, OverloadedStrings, PatternGuards, PatternSynonyms #-}
44
{-
55
Copyright (C) 2010-2019 John MacFarlane
66
@@ -170,6 +170,7 @@ module Text.Pandoc.Builder ( module Text.Pandoc.Definition
170170
, caption
171171
, simpleCaption
172172
, emptyCaption
173+
, pattern SimpleFigure
173174
, simpleFigureWith
174175
, simpleFigure
175176
, divWith
@@ -568,6 +569,21 @@ simpleCaption = caption Nothing
568569
emptyCaption :: Caption
569570
emptyCaption = simpleCaption mempty
570571

572+
-- | Bidirectional patter synonym
573+
--
574+
-- It can pass as a Block constructor
575+
--
576+
-- λ> SimpleFigure nullAttr [] (T.pack "") (T.pack "")
577+
-- Para [Image ("",[],[]) [] ("","fig:")]
578+
--
579+
-- It can be used to pattern match
580+
-- foo :: Block -> ...
581+
-- foo (SimpleFigure attr figureCaption src title) -> handleFigure ...
582+
pattern SimpleFigure :: Attr -> [Inline] -> Text -> Text -> Block
583+
pattern SimpleFigure attr figureCaption src title <- Para [Image attr figureCaption (src, title)] where
584+
SimpleFigure attr figureCaption src title =
585+
Para [Image attr figureCaption (src, "fig:" <> title)]
586+
571587
simpleFigureWith :: Attr -> Inlines -> Text -> Text -> Blocks
572588
simpleFigureWith attr figureCaption url title =
573589
para $ imageWith attr url ("fig:" <> title) figureCaption

0 commit comments

Comments
 (0)