|
1 | 1 | {-# LANGUAGE FlexibleInstances, MultiParamTypeClasses, DeriveDataTypeable, |
2 | 2 | GeneralizedNewtypeDeriving, CPP, StandaloneDeriving, DeriveGeneric, |
3 | | - DeriveTraversable, OverloadedStrings, PatternGuards #-} |
| 3 | + DeriveTraversable, OverloadedStrings, PatternGuards, PatternSynonyms #-} |
4 | 4 | {- |
5 | 5 | Copyright (C) 2010-2019 John MacFarlane |
6 | 6 |
|
@@ -170,6 +170,7 @@ module Text.Pandoc.Builder ( module Text.Pandoc.Definition |
170 | 170 | , caption |
171 | 171 | , simpleCaption |
172 | 172 | , emptyCaption |
| 173 | + , pattern SimpleFigure |
173 | 174 | , simpleFigureWith |
174 | 175 | , simpleFigure |
175 | 176 | , divWith |
@@ -568,6 +569,21 @@ simpleCaption = caption Nothing |
568 | 569 | emptyCaption :: Caption |
569 | 570 | emptyCaption = simpleCaption mempty |
570 | 571 |
|
| 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 | + |
571 | 587 | simpleFigureWith :: Attr -> Inlines -> Text -> Text -> Blocks |
572 | 588 | simpleFigureWith attr figureCaption url title = |
573 | 589 | para $ imageWith attr url ("fig:" <> title) figureCaption |
|
0 commit comments