Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 33 lines (26 sloc) 0.999 kb
a8db141 @jgm Use PigLatin plugin instead of CapitalizeOption.
authored
1 module PigLatin (plugin) where
2
3 -- This plugin converts a page to pig latin if the 'language' metadata
4 -- field is set to 'pig latin'. This demonstrates how to get access to
5 -- metadata in a plugin.
6
7 import Network.Gitit.Interface
478d0ba Cleaned up PigLatin plugin demo.
John MacFarlane authored
8 import Data.Char (toLower, toUpper, isLower, isUpper, isLetter)
a8db141 @jgm Use PigLatin plugin instead of CapitalizeOption.
authored
9
10 plugin :: Plugin
11 plugin = PageTransform $ \doc -> do
12 meta <- askMeta
13 case lookup "language" meta of
14 Just s | map toLower s == "pig latin" ->
15 return $ processWith pigLatinStr doc
16 _ -> return doc
17
18 pigLatinStr :: Inline -> Inline
19 pigLatinStr (Str "") = Str ""
478d0ba Cleaned up PigLatin plugin demo.
John MacFarlane authored
20 pigLatinStr (Str (c:cs)) | isLower c && isConsonant c =
21 Str (cs ++ (c : "ay"))
22 pigLatinStr (Str (c:cs)) | isUpper c && isConsonant c =
23 Str (capitalize cs ++ (toLower c : "ay"))
112e8b0 @jgm Plugins: hlint and import cleanup (gwern).
authored
24 pigLatinStr (Str x@(c:_)) | isLetter c = Str (x ++ "yay")
a8db141 @jgm Use PigLatin plugin instead of CapitalizeOption.
authored
25 pigLatinStr x = x
26
112e8b0 @jgm Plugins: hlint and import cleanup (gwern).
authored
27 isConsonant :: Char -> Bool
2465bcb @gwern Strip trailing whitespace; misc -Wall and hlint
gwern authored
28 isConsonant c = c `notElem` "aeiouAEIOU"
478d0ba Cleaned up PigLatin plugin demo.
John MacFarlane authored
29
a8db141 @jgm Use PigLatin plugin instead of CapitalizeOption.
authored
30 capitalize :: String -> String
31 capitalize "" = ""
32 capitalize (c:cs) = toUpper c : cs
Something went wrong with that request. Please try again.