Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- rxf.hs
- -- Slim Filter-Only Version of (un)rubyext.hs
- import Text.Pandoc.Definition
- import Text.Pandoc.Walk (walk)
- import Text.Pandoc.JSON
- -- readOpts = def {readerExtensions = pandocExtensions}
- -- writeOpts = def {writerExtensions = pandocExtensions}
- inlineWalker :: [Inline] -> [Inline]
- inlineWalker = foldr htmlToFuriExt []
- -- inlineWalker = foldr furiExtToHtml []
- htmlToFuriExt :: Inline -> [Inline] -> [Inline]
- htmlToFuriExt i@(RawInline (Format f) tag) acc
- | not (f == "html" && tag == "<ruby>") = i:acc
- | otherwise = convertRT acc
- htmlToFuriExt i acc = i:acc
- furiExtToHtml :: Inline -> [Inline] -> [Inline]
- furiExtToHtml (Link _ [Str furi] ('-':kanji,_)) acc =
- RawInline (Format "html") "<ruby>" : Str kanji : RawInline (Format "html") "<rt>" : Str furi : RawInline (Format "html") "</rt>" : RawInline (Format "html") "</ruby>" : acc
- furiExtToHtml i acc = i:acc
- convertRT ((Str kanji):(RawInline (Format f1) tag1):(Str furigana):(RawInline (Format f2) tag2):is)
- | (tag1 == "<rt>") && (tag2 == "</rt>") = (Link nullAttr [Str furigana] ("-"++kanji,[])) : convertRT is
- convertRT ((RawInline (Format f) tag):is)
- | f == "html" && tag == "</ruby>" = is
- convertRT (i:is) = convertRT is
- convertRT [] = []
- main = toJSONFilter inlineWalker
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement