@@ -277,11 +277,14 @@ the file given?
277#!/usr/bin/env runhaskell
277#!/usr/bin/env runhaskell
278-- includes.hs
278-- includes.hs
279import Text.Pandoc.JSON
279import Text.Pandoc.JSON
280+import qualified Data.Text.IO as TIO
281+import qualified Data.Text as T
281doInclude :: Block -> IO Block
283doInclude :: Block -> IO Block
282doInclude cb@(CodeBlock (id, classes, namevals) contents) =
284doInclude cb@(CodeBlock (id, classes, namevals) contents) =
283 case lookup "include" namevals of
285 case lookup "include" namevals of
284− Just f -> return . (CodeBlock (id, classes, namevals)) =<< readFile f
286+ Just f -> CodeBlock (id, classes, namevals) <$>
287+ TIO.readFile (T.unpack f)
285 Nothing -> return cb
288 Nothing -> return cb
286doInclude x = return x
289doInclude x = return x
@@ -358,17 +361,23 @@ markdown link with a URL beginning with a hyphen is interpreted as ruby:
360~~~ {.haskell}
363~~~ {.haskell}
364+{-# LANGUAGE OverloadedStrings #-}
361-- handleruby.hs
365-- handleruby.hs
362import Text.Pandoc.JSON
366import Text.Pandoc.JSON
363import System.Environment (getArgs)
367import System.Environment (getArgs)
368+import qualified Data.Text as T
365handleRuby :: Maybe Format -> Inline -> Inline
370handleRuby :: Maybe Format -> Inline -> Inline
366−handleRuby (Just format) (Link _ [Str ruby] ('-':kanji,_))
371+handleRuby (Just format) x@(Link attr [Str ruby] (src,_)) =
372+ case T.uncons src of
367− | format == Format "html" = RawInline format
374+ | format == Format "html" -> RawInline format $
368− $ "<ruby>" ++ kanji ++ "<rp>(</rp><rt>" ++ ruby ++ "</rt><rp>)</rp></ruby>"
375+ "<ruby>" <> kanji <> "<rp>(</rp><rt>" <> ruby <>
376+ "</rt><rp>)</rp></ruby>"
369− | format == Format "latex" = RawInline format
377+ | format == Format "latex" -> RawInline format $
370− $ "\\ruby{" ++ kanji ++ "}{" ++ ruby ++ "}"
378+ "\\ruby{" <> kanji <> "}{" <> ruby <> "}"
371− | otherwise = Str ruby
379+ | otherwise -> Str ruby
372handleRuby _ x = x
381handleRuby _ x = x
374main :: IO ()
383main :: IO ()
@@ -395,6 +404,11 @@ Then run it:
396 \ruby{飯}{はん}
405 \ruby{飯}{はん}
407+Note: to use this to generate PDFs via LaTeX, you'll need
408+to use `--pdf-engine=xelatex`, specify a `mainfont` that has
409+the Japanese characters (e.g. "Noto Sans CJK TC"), and add
410+`\usepackage{ruby}` to your template or header-includes.
398# Exercises
412# Exercises
4001. Put all the regular text in a markdown document in ALL CAPS
4141. Put all the regular text in a markdown document in ALL CAPS