48 lines
1.5 KiB
Haskell
Executable File
48 lines
1.5 KiB
Haskell
Executable File
#!/usr/bin/env runhaskell
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
{-# LANGUAGE ViewPatterns #-}
|
|
|
|
import Text.Pandoc.JSON
|
|
import Text.Pandoc.Writers (writeLaTeX)
|
|
import Data.Text (Text)
|
|
import qualified Data.Text as T
|
|
import Data.Default (def)
|
|
import Text.Pandoc.Class (runPure)
|
|
import Data.Either (fromRight)
|
|
import System.Environment (getArgs)
|
|
|
|
main :: IO ()
|
|
main = do
|
|
format <- getFormat
|
|
toJSONFilter $ case format of
|
|
"latex" -> allekirjoittajat latex
|
|
_ -> id
|
|
|
|
getFormat :: IO String
|
|
getFormat = head <$> getArgs
|
|
|
|
latex blocks = RawBlock (Format "latex") $ T.intercalate "\n"
|
|
[ "\\vspace{1cm}"
|
|
, "\\begin{table}[H]"
|
|
, "Pöytäkirjan vakuudeksi,"
|
|
, "\\vspace{8mm}"
|
|
, "\\begin{center}"
|
|
, "\\begin{tabular}{p{0.45\\textwidth} p{0.45\\textwidth}}"
|
|
, format names
|
|
, "\\end{tabular}"
|
|
, "\\end{center}"
|
|
, "\\end{table}"]
|
|
where names = fromRight (error "conversion failed!") $
|
|
runPure $ mapM (writeLaTeX def . Pandoc mempty) blocks
|
|
format (x:y:ys) = "\\dotfill & \\dotfill \\\\\n" <> x <> " & " <> y <>
|
|
"\\vspace{0.8cm}\\\\\n" <> format ys
|
|
format [x] = "\\dotfill & \\\\\n" <> x <> " & \\\\\n"
|
|
format [] = ""
|
|
|
|
allekirjoittajat :: ([[Block]] -> Block) -> Block -> Block
|
|
allekirjoittajat f (Div (_, (elem "allekirjoittajat" -> True), _) [(OrderedList _ blocks)])
|
|
= f blocks
|
|
allekirjoittajat f (Div (_, (elem "allekirjoittajat" -> True), _) [(BulletList blocks)])
|
|
= f blocks
|
|
allekirjoittajat _ x = x
|