Replies: 5 comments 9 replies
-
@argent0 can you share the diff directly here too that the changes can be seen easily ? ```diff
<copy paste your git diff result>
``` Ex: https://stackoverflow.com/a/40883538/3436535 Thanks you ! |
Beta Was this translation helpful? Give feedback.
-
Wow, that's cool! I learned something new :)
|
Beta Was this translation helpful? Give feedback.
-
How about this: diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs
index 1e9867d07..6db492e70 100644
--- a/src/Text/Pandoc/Readers/Markdown.hs
+++ b/src/Text/Pandoc/Readers/Markdown.hs
@@ -1013,18 +1013,16 @@ normalDefinitionList = do
para :: PandocMonad m => MarkdownParser m (F Blocks)
para = try $ do
exts <- getOption readerExtensions
- let implicitFigures x
- | extensionEnabled Ext_implicit_figures exts = do
- x' <- x
- case B.toList x' of
- [Image attr alt (src,tit)]
- | not (null alt) ->
- -- the fig: at beginning of title indicates a figure
- return $ B.singleton
- $ Image attr alt (src, "fig:" <> tit)
- _ -> return x'
- | otherwise = x
- result <- implicitFigures . trimInlinesF <$> inlines1
+ result <- trimInlinesF <$> inlines1
+ let paraOrFigure inlns =
+ case B.toList inlns of
+ [Image attr alt (src, tit)]
+ | extensionEnabled Ext_implicit_figures exts
+ , not (null alt) -> do
+ -- the fig: at beginning of title indicates a figure
+ B.para $ B.singleton
+ $ Image attr alt (src, "fig:" <> tit)
+ _ -> B.para inlns
option (B.plain <$> result)
$ try $ do
newline
@@ -1047,7 +1045,7 @@ para = try $ do
if divLevel > 0
then lookAhead divFenceEnd
else mzero
- return $ B.para <$> result
+ return $ paraOrFigure <$> result
plain :: PandocMonad m => MarkdownParser m (F Blocks)
plain = fmap B.plain . trimInlinesF <$> inlines1 A bit hacky though. |
Beta Was this translation helpful? Give feedback.
-
I'm wondering whether we could simplify our task by adding another helper function; maybe something along these lines: -- | Converts a singleton containing an image into a figure;
-- returns @Nothing@ if that's not possible.
imageToFigure :: Inlines -> Maybe Blocks
imageToFigure = undefined It seems that this operation is a common occurrence in the readers. |
Beta Was this translation helpful? Give feedback.
-
But can you "compute" in a pattern synonym?
It's not simple, but possible when combining pattern synonyms with view
patterns. The following example illustrates the method. Running it with
`stack test.hs` yields `nny`.
```haskell
#!/usr/bin/env stack
-- stack --resolver lts-17.15 script
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ViewPatterns #-}
import Data.Text (Text)
import qualified Data.Text as T
import qualified Data.Text.IO as T
newtype Foo = Foo Text
pattern Fubar :: Text -> Foo
pattern Fubar bar <- Foo (T.stripPrefix "fu" -> Just bar)
main :: IO ()
main = do
case Foo "funny" of
Fubar title -> T.putStrLn title
_ -> T.putStrLn "no match"
```
|
Beta Was this translation helpful? Give feedback.
-
Hello, this is the preliminary code for the markdown reader:
Diff
Resulting Function
This replaces the function here
Beta Was this translation helpful? Give feedback.
All reactions