Handle autolinks

main
staticvoid 2022-06-27 20:25:02 +03:00
parent e4df4da062
commit 8aa18bfcf7
1 changed files with 8 additions and 3 deletions

View File

@ -33,8 +33,8 @@ data InlinePiece = Str Text
| Strong Inline
| Underline Inline
| Strikethrough Inline
-- | Autolink { dest :: Text }
| Link { dest, title :: Text
| Autolink { dest :: Text }
| Link { dest :: Text
, descr :: Inline
}
| Code Text
@ -50,7 +50,8 @@ mapText f (Inline pieces) = Inline (mapText' <$> pieces) where
mapText' (Strong i) = Strong (mapText f i)
mapText' (Underline i) = Underline (mapText f i)
mapText' (Strikethrough i) = Strikethrough (mapText f i)
mapText' Link{dest, title, descr} = Link { dest, title, descr = mapText f descr }
mapText' (Autolink t) = Link {dest = t, descr = str (f t)}
mapText' Link{dest, descr} = Link { dest, descr = mapText f descr }
mapText' (Code t) = Code t
instance Semigroup Inline where
@ -80,6 +81,7 @@ instance IsInline Inline where
escapedChar c = str $ "\\" <> one c
emph = Inline . one . Emph
strong = Inline . one . Strong
link dest _title (Inline (Str descr :<| Empty)) | dest == descr = Inline $ one Autolink {dest}
link dest _title descr =
descr <> fromList [ Str " ("
, Underline (str dest)
@ -148,6 +150,9 @@ instance PrintColor Inline where
where
mkStrikethrough :: (IsString s, ToString s) => s -> s
mkStrikethrough s = fromString do { c <- toString s; [c, chr 822] }
printPiece Autolink{dest} = do
withSgr [ANSI.SetUnderlining ANSI.SingleUnderline] do
putTextO dest
printPiece Link{dest, descr} = do
printColor descr
withSgr [ANSI.SetUnderlining ANSI.SingleUnderline] do