diff options
| author | John MacFarlane <[email protected]> | 2020-05-14 09:32:19 -0700 |
|---|---|---|
| committer | John MacFarlane <[email protected]> | 2020-05-14 09:32:19 -0700 |
| commit | edf630442c351cef9d49c9b251766063bee6fb2d (patch) | |
| tree | 92c1ba5e109c920d75973d63919b855ae65eb28a | |
| parent | 28c2c8e96bda5980d27e7afacd75dc651a47e80f (diff) | |
Support implicit_figure extension in commonmark reader.
| -rw-r--r-- | src/Text/Pandoc/Extensions.hs | 2 | ||||
| -rw-r--r-- | src/Text/Pandoc/Readers/CommonMark.hs | 12 |
2 files changed, 13 insertions, 1 deletions
diff --git a/src/Text/Pandoc/Extensions.hs b/src/Text/Pandoc/Extensions.hs index 3b431d83d..b438fad89 100644 --- a/src/Text/Pandoc/Extensions.hs +++ b/src/Text/Pandoc/Extensions.hs @@ -359,6 +359,7 @@ getDefaultExtensions "commonmark_x" = extensionsFromList , Ext_raw_attribute , Ext_implicit_header_references , Ext_attributes + , Ext_implicit_figures ] getDefaultExtensions "org" = extensionsFromList [Ext_citations, @@ -480,6 +481,7 @@ getAllExtensions f = universalExtensions <> getAll f , Ext_raw_attribute , Ext_implicit_header_references , Ext_attributes + , Ext_implicit_figures ] getAll "gfm" = getAll "commonmark" getAll "commonmark_x" = getAll "commonmark" diff --git a/src/Text/Pandoc/Readers/CommonMark.hs b/src/Text/Pandoc/Readers/CommonMark.hs index a85d9aa37..44c72dc38 100644 --- a/src/Text/Pandoc/Readers/CommonMark.hs +++ b/src/Text/Pandoc/Readers/CommonMark.hs @@ -21,8 +21,10 @@ import Commonmark import Commonmark.Extensions import Commonmark.Pandoc import Data.Text (Text) +import qualified Data.Text as T import Text.Pandoc.Class.PandocMonad (PandocMonad) import Text.Pandoc.Definition +import Text.Pandoc.Walk (walk) import Text.Pandoc.Builder as B import Text.Pandoc.Options import Text.Pandoc.Error @@ -36,8 +38,11 @@ readCommonMark opts s = do commonmarkWith (foldr (<>) defaultSyntaxSpec exts) "input" s case res of Left err -> throwError $ PandocParsecError s err - Right (Cm bls :: Cm () Blocks) -> return $ B.doc bls + Right (Cm bls :: Cm () Blocks) -> return $ B.doc $ postprocess bls where + postprocess = if isEnabled Ext_implicit_figures opts + then walk makeImplicitFigure + else id exts = [ hardLineBreaksSpec | isEnabled Ext_hard_line_breaks opts ] ++ [ smartPunctuationSpec | isEnabled Ext_smart opts ] ++ [ strikethroughSpec | isEnabled Ext_strikeout opts ] ++ @@ -64,3 +69,8 @@ readCommonMark opts s = do [ definitionListSpec | isEnabled Ext_definition_lists opts ] ++ [ taskListSpec | isEnabled Ext_task_lists opts ] +makeImplicitFigure :: Block -> Block +makeImplicitFigure (Para [Image attr label (src, tit)]) + | not ("fig:" `T.isPrefixOf` tit) = + Para [Image attr label (src, "fig:" <> tit)] +makeImplicitFigure x = x |
