Advertisement
kafkafuura

rxf.hs

Jun 13th, 2019
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- rxf.hs
  2. -- Slim Filter-Only Version of (un)rubyext.hs
  3. import Text.Pandoc.Definition
  4. import Text.Pandoc.Walk (walk)
  5. import Text.Pandoc.JSON
  6.  
  7. -- readOpts = def {readerExtensions = pandocExtensions}
  8. -- writeOpts = def {writerExtensions = pandocExtensions}
  9.  
  10. inlineWalker :: [Inline] -> [Inline]
  11. inlineWalker = foldr htmlToFuriExt []
  12. -- inlineWalker = foldr furiExtToHtml []
  13.  
  14. htmlToFuriExt :: Inline -> [Inline] -> [Inline]
  15. htmlToFuriExt i@(RawInline (Format f) tag) acc
  16.  | not (f == "html" && tag == "<ruby>") = i:acc
  17.  | otherwise = convertRT acc
  18. htmlToFuriExt i acc = i:acc
  19.  
  20. furiExtToHtml :: Inline -> [Inline] -> [Inline]
  21. furiExtToHtml (Link _ [Str furi] ('-':kanji,_)) acc =
  22.  RawInline (Format "html") "<ruby>" : Str kanji : RawInline (Format "html") "<rt>" : Str furi : RawInline (Format "html") "</rt>" : RawInline (Format "html") "</ruby>" : acc
  23. furiExtToHtml i acc = i:acc
  24.  
  25. convertRT ((Str kanji):(RawInline (Format f1) tag1):(Str furigana):(RawInline (Format f2) tag2):is)
  26.  | (tag1 == "<rt>") && (tag2 == "</rt>") = (Link nullAttr [Str furigana] ("-"++kanji,[])) : convertRT is
  27. convertRT ((RawInline (Format f) tag):is)
  28.  | f == "html" && tag == "</ruby>" = is
  29. convertRT (i:is) = convertRT is
  30. convertRT [] = []
  31.  
  32. main = toJSONFilter inlineWalker
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement