File: Markdown.hs

package info (click to toggle)
darcs 2.12.4-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 5,748 kB
  • sloc: haskell: 42,936; sh: 11,086; ansic: 837; perl: 129; makefile: 8
file content (38 lines) | stat: -rw-r--r-- 1,500 bytes parent folder | download | duplicates (3)
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
33
34
35
36
37
38
-- Support for @darcs help markdown@
module Darcs.UI.Options.Markdown ( optionsMarkdown ) where

import Prelude ()
import Darcs.Prelude

import Data.Functor.Compose ( Compose(..) )
import System.Console.GetOpt ( OptDescr(..), ArgDescr(..) )
import Darcs.UI.Options.Util ( DarcsOptDescr )

optionsMarkdown :: [DarcsOptDescr f] -> String
optionsMarkdown opts = unlines
  [ "<table>", unlines (map optionMarkdown opts), "</table>" ]

optionMarkdown :: DarcsOptDescr f -> String
optionMarkdown (Compose (Option a b (NoArg _) h)) = unlines
 [ "<tr>", "<td>", showShortOptionsMd a, "</td>"
         , "<td>", showLongOptionsMd b , "</td>"
         , "<td>", h, "</td>"
 , "</tr>" ]
optionMarkdown (Compose (Option a b (ReqArg _ arg) h)) = unlines
 [ "<tr>", "<td>", showShortOptionsMd a, "</td>"
         , "<td>", showLongOptionsMd (map (++(' ' : arg)) b), "</td>"
         , "<td>", h, "</td>", "</tr>" ]
optionMarkdown (Compose (Option a b (OptArg _ arg) h)) = unlines
 [ "<tr>", "<td>", showShortOptionsMd a, "</td>"
         , "<td>", showLongOptionsMd (map (++("[="++arg++"]")) b), "</td>"
         , "<td>", h, "</td>", "</tr>" ]

showShortOptionsMd :: [Char] -> String
showShortOptionsMd []     = ""
showShortOptionsMd [c]    = "`-"++[c]++"` "
showShortOptionsMd (c:cs) = "`-"++[c]++"`,"++showShortOptionsMd cs

showLongOptionsMd :: [String] -> String
showLongOptionsMd []     = " "
showLongOptionsMd [s]    = "`--" ++ s ++ "` "
showLongOptionsMd (s:ss) = "`--" ++ s ++ "`,"++ showLongOptionsMd ss