{-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE OverloadedStrings #-} module Commonmark.Extensions.Strikethrough ( HasStrikethrough(..) , strikethroughSpec ) where import Commonmark.Types import Commonmark.Syntax import Commonmark.Inlines import Commonmark.SourceMap import Commonmark.Html strikethroughSpec :: (Monad m, IsBlock il bl, IsInline il, HasStrikethrough il) => SyntaxSpec m il bl strikethroughSpec :: forall (m :: * -> *) il bl. (Monad m, IsBlock il bl, IsInline il, HasStrikethrough il) => SyntaxSpec m il bl strikethroughSpec = forall a. Monoid a => a mempty { syntaxFormattingSpecs :: [FormattingSpec il] syntaxFormattingSpecs = [ forall il. Char -> Bool -> Bool -> Maybe (il -> il) -> Maybe (il -> il) -> Char -> FormattingSpec il FormattingSpec Char '~' Bool True Bool True forall a. Maybe a Nothing (forall a. a -> Maybe a Just forall a. HasStrikethrough a => a -> a strikethrough) Char '~' ] } class HasStrikethrough a where strikethrough :: a -> a instance HasStrikethrough (Html a) where strikethrough :: Html a -> Html a strikethrough Html a x = forall a. Text -> Maybe (Html a) -> Html a htmlInline Text "del" (forall a. a -> Maybe a Just Html a x) instance (HasStrikethrough i, Monoid i) => HasStrikethrough (WithSourceMap i) where strikethrough :: WithSourceMap i -> WithSourceMap i strikethrough WithSourceMap i x = (forall a. HasStrikethrough a => a -> a strikethrough forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> WithSourceMap i x) forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a <* Text -> WithSourceMap () addName Text "strikethrough"