{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverloadedStrings #-}
module Commonmark.Extensions.Subscript
  ( HasSubscript(..)
  , subscriptSpec )
where
import Commonmark.Types
import Commonmark.Syntax
import Commonmark.Inlines
import Commonmark.SourceMap
import Commonmark.Html

subscriptSpec :: (Monad m, IsBlock il bl, IsInline il, HasSubscript il)
              => SyntaxSpec m il bl
subscriptSpec :: forall (m :: * -> *) il bl.
(Monad m, IsBlock il bl, IsInline il, HasSubscript il) =>
SyntaxSpec m il bl
subscriptSpec = SyntaxSpec m il bl
forall a. Monoid a => a
mempty
  { syntaxFormattingSpecs = [
      FormattingSpec '~' True True (Just subscript) Nothing '~'
      ]
  }

class HasSubscript a where
  subscript :: a -> a

instance HasSubscript (Html a) where
  subscript :: Html a -> Html a
subscript Html a
x = Text -> Maybe (Html a) -> Html a
forall a. Text -> Maybe (Html a) -> Html a
htmlInline Text
"sub" (Html a -> Maybe (Html a)
forall a. a -> Maybe a
Just Html a
x)

instance (HasSubscript i, Monoid i)
        => HasSubscript (WithSourceMap i) where
  subscript :: WithSourceMap i -> WithSourceMap i
subscript WithSourceMap i
x = (i -> i
forall a. HasSubscript a => a -> a
subscript (i -> i) -> WithSourceMap i -> WithSourceMap i
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> WithSourceMap i
x) WithSourceMap i -> WithSourceMap () -> WithSourceMap i
forall a b. WithSourceMap a -> WithSourceMap b -> WithSourceMap a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Text -> WithSourceMap ()
addName Text
"subscript"