module MathiasSM.Filters (processRubyText) where
import Data.Text qualified as T
import Text.Pandoc (Inline (Link, RawInline, Str))
processRubyText :: Inline -> Inline
processRubyText :: Inline -> Inline
processRubyText x :: Inline
x@(Link Attr
_ [Str Text
kanji] (Text
src, Text
_)) =
case Text -> Maybe (Char, Text)
T.uncons Text
src of
Just (Char
'-', Text
ruby) ->
Format -> Text -> Inline
RawInline Format
"html" (Text -> Inline) -> Text -> Inline
forall a b. (a -> b) -> a -> b
$
Text
"<ruby>" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
kanji Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"<rp>(</rp><rt>" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
ruby Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"</rt><rp>)</rp></ruby>"
Maybe (Char, Text)
_ -> Inline
x
processRubyText Inline
x = Inline
x