-- handleRuby.hsimport Text.PandochandleRuby :: Inline -> InlinehandleRuby (Link txt ('-':kanji,_)) = RawInline "html" rubyHtmlwhere rubyHtml = ("<ruby>" ++ kanji ++ "<rp>(</rp><rt>" ++ "hello" ++ "<rp>)</rp></rt></ruby>")handleRuby x = xreadDoc :: String -> PandocreadDoc = readMarkdown defaultParserStatewriteDoc :: Pandoc -> StringwriteDoc = writeMarkdown defaultWriterOptionsmain :: IO ()main = interact (writeDoc . bottomUp handleRuby . readDoc)
What version are you running now (pandoc --version)? It appears that the
version you're using URL-encodes the source part of the link; the dev
version doesn't do that. You can transform it back to a regular string
by using unescapeURIString from Network.URI. ('cabal install network' if
you don't have it.)
Also, what is the output of 'locale', and what is the encoding of
your input text?
LANG="en_GB.UTF-8"LC_COLLATE="en_GB.UTF-8"LC_CTYPE="en_GB.UTF-8"LC_MESSAGES="en_GB.UTF-8"LC_MONETARY="en_GB.UTF-8"LC_NUMERIC="en_GB.UTF-8"LC_TIME="en_GB.UTF-8"LC_ALL=
-- handleRuby.hsimport Text.Pandocimport Network.URI (unEscapeString)handleRuby :: Inline -> InlinehandleRuby (Link (Str ruby : []) ('-':kanji,_)) = RawInline "html" rubyHtmlwhere rubyHtml = ("<ruby>" ++ unEscapeString kanji ++ "<rp>(</rp><rt>" ++ ruby ++ "<rp>)</rp></rt></ruby>")
handleRuby x = xreadDoc :: String -> PandocreadDoc = readMarkdown defaultParserStatewriteDoc :: Pandoc -> StringwriteDoc = writeMarkdown defaultWriterOptionsmain :: IO ()main = interact (writeDoc . bottomUp handleRuby . readDoc)
-- handleRuby.hsimport Text.Pandoc-- handleRuby :: Inline -> Inline-- handleRuby (Link (Str ruby : []) ('-':kanji,_)) = RawInline "html" rubyHtml-- where rubyHtml = ("<ruby>" ++ kanji ++ "<rp>(</rp><rt>" ++ ruby ++ "</rt><rp>)</rp></ruby>")-- handleRuby x = xhandleRuby :: Inline -> InlinehandleRuby (Link (Str ruby : []) ('-':kanji,_)) = RawInline "latex" rubyLaTeXwhere rubyLaTeX = ("\\ruby{" ++ kanji ++ "}{" ++ ruby ++ "}")handleRuby x = x
handleRuby :: Inline -> Inline
main :: IO ()
main = interact $ jsonFilter (bottomUp handleRuby)
Without any testing, here's a modified version of what you had
that will give you support for both html and latex:
-- handleRuby.hs
-- compile with: ghc --make handleRuby
-- run with:
-- pandoc -t json | ./handleRuby $FORMAT | ./pandoc -f json -t $FORMAT
-- where $FORMAT is either "html" or "latex"
import Text.Pandoc
import System.Environment (getArgs)
type Format = String
handleRuby :: Format -> Inline -> Inline
handleRuby "html" (Link (Str ruby : []) ('-':kanji,_)) = RawInline "html"
$ "<ruby>" ++ kanji ++ "<rp>(</rp><rt>" ++ ruby ++ "</rt><rp>)</rp></ruby>"
handleRuby "latex" (Link (Str ruby : []) ('-':kanji,_)) = RawInline "latex"
$ "\\ruby{" ++ kanji ++ "}{" ++ ruby ++ "}"
handleRuby _ x = x
main :: IO ()
main = do
args <- getArgs
case args of
[format] -> interact $ jsonFilter $ bottomUp (handleRuby format)
_ -> error "Usage: handleRuby (html|latex)"
For a bit more generality you could avoid using RawInline
for these -- that would allow you to do the stripping operations
for any output format.
handleRuby "kanji" (Link txt ('-':kanji,_)) = Str kanji
handleRuby "kana" (Link (Str ruby : []) ('-':kanji,_)) = Str ruby
http://johnmacfarlane.net/pandoc/scripting.html#a-filter-for-ruby-text
Hope you don't mind. It's a really nice example, I think.
John
+++ Qubyte [Feb 14 12 04:56 ]:
> Nice! I'll update the readme. Thanks for the heads up.
>
> --
> You received this message because you are subscribed to the Google
> Groups "pandoc-discuss" group.
> To view this discussion on the web visit
> [1]https://groups.google.com/d/msg/pandoc-discuss/-/yJ3TUkP7Bd0J.
> To post to this group, send email to pandoc-...@googlegroups.com.
> To unsubscribe from this group, send email to
> pandoc-discus...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/pandoc-discuss?hl=en.
>
> References
>
> 1. https://groups.google.com/d/msg/pandoc-discuss/-/yJ3TUkP7Bd0J