@@ -277,11 +277,14 @@ the file given?
277277#!/usr/bin/env runhaskell
278278-- includes.hs
279279import Text.Pandoc.JSON
280+import qualified Data.Text.IO as TIO
281+import qualified Data.Text as T
280282
281283doInclude :: Block -> IO Block
282284doInclude cb@(CodeBlock (id, classes, namevals) contents) =
283285 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)
285288 Nothing -> return cb
286289doInclude x = return x
287290
@@ -358,17 +361,23 @@ markdown link with a URL beginning with a hyphen is interpreted as ruby:
358361 [はん](-飯)
359362
360363~~~ {.haskell}
364+{-# LANGUAGE OverloadedStrings #-}
361365-- handleruby.hs
362366import Text.Pandoc.JSON
363367import System.Environment (getArgs)
368+import qualified Data.Text as T
364369
365370handleRuby :: Maybe Format -> Inline -> Inline
366−handleRuby (Just format) (Link _ [Str ruby] ('-':kanji,_))
367− | format == Format "html" = RawInline format
368− $ "<ruby>" ++ kanji ++ "<rp>(</rp><rt>" ++ ruby ++ "</rt><rp>)</rp></ruby>"
369− | format == Format "latex" = RawInline format
370− $ "\\ruby{" ++ kanji ++ "}{" ++ ruby ++ "}"
371− | otherwise = Str ruby
371+handleRuby (Just format) x@(Link attr [Str ruby] (src,_)) =
372+ case T.uncons src of
373+ Just ('-',kanji)
374+ | format == Format "html" -> RawInline format $
375+ "<ruby>" <> kanji <> "<rp>(</rp><rt>" <> ruby <>
376+ "</rt><rp>)</rp></ruby>"
377+ | format == Format "latex" -> RawInline format $
378+ "\\ruby{" <> kanji <> "}{" <> ruby <> "}"
379+ | otherwise -> Str ruby
380+ _ -> x
372381handleRuby _ x = x
373382
374383main :: IO ()
@@ -395,6 +404,11 @@ Then run it:
395404 ^D
396405 \ruby{飯}{はん}
397406
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.
411+
398412# Exercises
399413
4004141. Put all the regular text in a markdown document in ALL CAPS