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