" ++ unwords (map linkify $ sort ls) ++ "
" ++ "\n" where linkify l = a $ Anchor [ Attribute "name" (sanitizeAnchor l) , Attribute "href" (gitHubAnchor l) ] (codify l) h1 :: String -> Env h1 = heading 1 h2 :: String -> Env h2 = heading 2 h3 :: String -> Env h3 = heading 3 heading :: Int -> String -> Env heading level string = do metadata <- ask return $ replicate level '#' ++ " " ++ string ++ anch (pluginName metadata) ++ "\n\n" where anch name = a $ Anchor [ Attribute "name" (sanitizeAnchor $ pre ++ string) , Attribute "href" (gitHubAnchor $ pre ++ string) ] "" where pre = maybe "" (++ "-") name -- | Wraps a string in ``/`
` tags.
-- TODO: remember why I'm not using backticks here.
codify :: String -> String
codify s = "" ++ s ++ "
"
a :: Anchor -> String
a (Anchor attributes target) = "" ++ target ++ ""
where
attrs = if not (null attributes)
then " " ++ attributesString attributes
else ""
attributesString :: [Attribute] -> String
attributesString as = unwords (map attributeToString as)
where attributeToString (Attribute name value) = name ++ "=\"" ++ value ++ "\""
gitHubAnchor :: String -> String
gitHubAnchor n = "#user-content-" ++ sanitizeAnchor n
-- TODO: make sure symbol table knows about option targets too
option :: Node -> Env
option (OptionAnnotation n t d) = do
h <- h3 $ "`" ++ n ++ "` (" ++ t ++ ", default: " ++ def ++ ")"
return $ targets ++ h
where targets = linkTargets [n]
def = fromMaybe "none" d
option _ = invalidNode
command :: Node -> Env
command (CommandAnnotation name params) = do
content <- h3 $ "`:" ++ annotation ++ "`"
return $ target ++ content
where target = linkTargets [":" ++ name]
annotation = rstrip $ name ++ " " ++ fromMaybe "" params
command _ = invalidNode
mapping :: String -> Env
mapping name = h3 $ "`" ++ name ++ "`"