From c4c77517e993d453fdc9a05c8c7593ac1ae2199b Mon Sep 17 00:00:00 2001 From: fiddlosopher Date: Tue, 30 Sep 2008 20:16:03 +0000 Subject: Have the '-v' option print syntax highlighting languages separated by commas, and wrapped in lines, instead of in five columns as before. git-svn-id: https://pandoc.googlecode.com/svn/trunk@1459 788f1e2b-df1e-0410-8736-df70ead52e1b --- Main.hs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'Main.hs') diff --git a/Main.hs b/Main.hs index 7cf4e9970..c5cfa84b4 100644 --- a/Main.hs +++ b/Main.hs @@ -69,14 +69,18 @@ compileInfo = #endif if null languages then "\n" - else "\nCompiled with syntax highlighting support for:\n" ++ - (unlines $ map unwords $ chunk 5 $ map (\s -> s ++ replicate (15 - length s) ' ') languages) - --- | Splits a list into groups of at most n. -chunk :: Int -> [a] -> [[a]] -chunk size lst = - let (next, rest) = splitAt size lst - in if null rest then [next] else next : chunk size rest + else "\nCompiled with syntax highlighting support for:\n" ++ wrapWords 78 languages + +-- | Converts a list of strings into a single string with the items printed as +-- comma separated words in lines with a maximum line length. +wrapWords :: Int -> [String] -> String +wrapWords c = wrap' c c where + wrap' _ _ [] = "" + wrap' cols remaining (x:xs) = if remaining == cols + then x ++ wrap' cols (remaining - length x) xs + else if (length x + 1) > remaining + then ",\n" ++ x ++ wrap' cols (cols - length x) xs + else ", " ++ x ++ wrap' cols (remaining - (length x + 2)) xs -- | Association list of formats and readers. readers :: [(String, ParserState -> String -> Pandoc)] -- cgit v1.2.3