File: PigLatin.hs

package info (click to toggle)
gitit 0.12.1.1%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,008 kB
  • ctags: 78
  • sloc: haskell: 4,963; xml: 245; sh: 65; makefile: 16
file content (32 lines) | stat: -rw-r--r-- 999 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
module PigLatin (plugin) where

-- This plugin converts a page to pig latin if the 'language' metadata
-- field is set to 'pig latin'. This demonstrates how to get access to
-- metadata in a plugin.

import Network.Gitit.Interface
import Data.Char (toLower, toUpper, isLower, isUpper, isLetter)

plugin :: Plugin
plugin = PageTransform $ \doc -> do
  meta <- askMeta
  case lookup "language" meta of
       Just s | map toLower s == "pig latin" ->
         return $ processWith pigLatinStr doc
       _ -> return doc

pigLatinStr :: Inline -> Inline
pigLatinStr (Str "") = Str ""
pigLatinStr (Str (c:cs)) | isLower c && isConsonant c =
  Str (cs ++ (c : "ay"))
pigLatinStr (Str (c:cs)) | isUpper c && isConsonant c =
  Str (capitalize cs ++ (toLower c : "ay"))
pigLatinStr (Str x@(c:_)) | isLetter c = Str (x ++ "yay")
pigLatinStr x       = x

isConsonant :: Char -> Bool
isConsonant c = c `notElem` "aeiouAEIOU"

capitalize :: String -> String
capitalize "" = ""
capitalize (c:cs) = toUpper c : cs