diff options
author | John MacFarlane <jgm@berkeley.edu> | 2020-12-09 21:14:11 -0800 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2020-12-10 08:59:55 -0800 |
commit | a3eb87b2eab9def3e28364b43300043f5e13268d (patch) | |
tree | 6616cb502c29fd331ea5401f8acdb21cbbe92e13 /src/Text/Pandoc/Readers | |
parent | 8c9010864cd818031d7eff161a57459709751517 (diff) | |
download | pandoc-a3eb87b2eab9def3e28364b43300043f5e13268d.tar.gz |
Add sourcepos extension for commonmarke
* Add `Ext_sourcepos` constructor for `Extension`.
* Add `sourcepos` extension (only for commonmark).
* Bump to 2.11.3
With the `sourcepos` extension set set, `data-pos` attributes are added
to the AST by the commonmark reader. No other readers are affected. The
`data-pos` attributes are put on elements that accept attributes; for
other elements, an enlosing Div or Span is added to hold the attributes.
Closes #4565.
Diffstat (limited to 'src/Text/Pandoc/Readers')
-rw-r--r-- | src/Text/Pandoc/Readers/CommonMark.hs | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/Text/Pandoc/Readers/CommonMark.hs b/src/Text/Pandoc/Readers/CommonMark.hs index d32a38342..9eef498e1 100644 --- a/src/Text/Pandoc/Readers/CommonMark.hs +++ b/src/Text/Pandoc/Readers/CommonMark.hs @@ -32,11 +32,15 @@ import Data.Typeable -- | Parse a CommonMark formatted string into a 'Pandoc' structure. readCommonMark :: PandocMonad m => ReaderOptions -> Text -> m Pandoc -readCommonMark opts s = do - let res = runIdentity $ commonmarkWith (specFor opts) "" s - case res of - Left err -> throwError $ PandocParsecError s err - Right (Cm bls :: Cm () Blocks) -> return $ B.doc bls +readCommonMark opts s + | isEnabled Ext_sourcepos opts = + case runIdentity (commonmarkWith (specFor opts) "" s) of + Left err -> throwError $ PandocParsecError s err + Right (Cm bls :: Cm SourceRange Blocks) -> return $ B.doc bls + | otherwise = + case runIdentity (commonmarkWith (specFor opts) "" s) of + Left err -> throwError $ PandocParsecError s err + Right (Cm bls :: Cm () Blocks) -> return $ B.doc bls specFor :: (Monad m, Typeable m, Typeable a, Rangeable (Cm a Inlines), Rangeable (Cm a Blocks)) |