Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions src/Text/Markdown/SlamDown/Parser/Inline.purs
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,16 @@ inlines = L.many inline2 <* PS.eof
inline1 ∷ P.Parser String (SD.Inline a)
inline1 =
PC.try inline0
<|> PC.try link
<|> PC.try (image (inline0 <|> other))
<|> PC.try (link (inline0 <|> other))

inline2 ∷ P.Parser String (SD.Inline a)
inline2 = do
res ←
PC.try formField
<|> PC.try (Right <$> inline1)
<|> PC.try (Right <$> image)
<|> PC.try (Right <$> inline0)
<|> PC.try (Right <$> image (inline1 <|> other))
<|> PC.try (Right <$> link (inline1 <|> other))
<|> (Right <$> other)
case res of
Right v → pure v
Expand Down Expand Up @@ -202,11 +204,11 @@ inlines = L.many inline2 <* PS.eof
pure <<< SD.Code eval <<< S.trim $ contents


link ∷ P.Parser String (SD.Inline a)
link = SD.Link <$> linkLabel <*> linkTarget
link ∷ P.Parser String (SD.Inline a) → P.Parser String (SD.Inline a)
link p = SD.Link <$> linkLabel <*> linkTarget
where
linkLabel ∷ P.Parser String (L.List (SD.Inline a))
linkLabel = PS.string "[" *> PC.manyTill (inline0 <|> other) (PS.string "]")
linkLabel = PS.string "[" *> PC.manyTill p (PS.string "]")

linkTarget ∷ P.Parser String SD.LinkTarget
linkTarget = inlineLink <|> referenceLink
Expand All @@ -217,11 +219,11 @@ inlines = L.many inline2 <* PS.eof
referenceLink ∷ P.Parser String SD.LinkTarget
referenceLink = SD.ReferenceLink <$> PC.optionMaybe ((S.fromCharArray <<< A.fromFoldable) <$> (PS.string "[" *> PC.manyTill PS.anyChar (PS.string "]")))

image ∷ P.Parser String (SD.Inline a)
image = SD.Image <$> imageLabel <*> imageUrl
image ∷ P.Parser String (SD.Inline a) → P.Parser String (SD.Inline a)
image p = SD.Image <$> imageLabel <*> imageUrl
where
imageLabel ∷ P.Parser String (L.List (SD.Inline a))
imageLabel = PS.string "![" *> PC.manyTill (inline1 <|> other) (PS.string "]")
imageLabel = PS.string "![" *> PC.manyTill p (PS.string "]")

imageUrl ∷ P.Parser String String
imageUrl = S.fromCharArray <<< A.fromFoldable <$> (PS.string "(" *> PC.manyTill PS.anyChar (PS.string ")"))
Expand Down