diff options
author | John MacFarlane <jgm@berkeley.edu> | 2010-12-12 20:09:14 -0800 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2010-12-17 13:39:17 -0800 |
commit | 543aa28c3895d4dc7d3d659b652237efb41661b0 (patch) | |
tree | f3186cc78a5235d0ead022ca0a5abed2c7a5ace0 /src/pandoc.hs | |
parent | 2a075e9d7a31303efa823f1779c2b32f9fb8a14f (diff) | |
download | pandoc-543aa28c3895d4dc7d3d659b652237efb41661b0.tar.gz |
Added new prettyprinting module.
* Added Text.Pandoc.Pretty.
This is better suited for pandoc than the 'pretty' package.
One advantage is that we now get proper wrapping; Emph [Inline]
is no longer treated as a big unwrappable unit. Previously
we only got breaks for spaces at the "outer level." We can also
more easily avoid doubled blank lines. Performance is
significantly better as well.
* Removed Text.Pandoc.Blocks.
Text.Pandoc.Pretty allows you to define blocks and concatenate
them.
* Modified markdown, RST, org readers to use Text.Pandoc.Pretty
instead of Text.PrettyPrint.HughesPJ.
* Text.Pandoc.Shared: Added writerColumns to WriterOptions.
* Markdown, RST, Org writers now break text at writerColumns.
* Added --columns command-line option, which sets stColumns
and writerColumns.
* Table parsing: If the size of the header > stColumns,
use the header size as 100% for purposes of calculating
relative widths of columns.
Diffstat (limited to 'src/pandoc.hs')
-rw-r--r-- | src/pandoc.hs | 58 |
1 files changed, 38 insertions, 20 deletions
diff --git a/src/pandoc.hs b/src/pandoc.hs index df83cdd0b..373919e05 100644 --- a/src/pandoc.hs +++ b/src/pandoc.hs @@ -36,11 +36,11 @@ import Text.Pandoc.Shared ( tabFilter, ObfuscationMethod (..), readDataFile, #ifdef _HIGHLIGHTING import Text.Pandoc.Highlighting ( languages ) #endif -import System.Environment ( getArgs, getProgName, getEnvironment ) +import System.Environment ( getArgs, getProgName ) import System.Exit ( exitWith, ExitCode (..) ) import System.FilePath import System.Console.GetOpt -import Data.Char ( toLower, isDigit ) +import Data.Char ( toLower ) import Data.List ( intercalate, isSuffixOf ) import System.Directory ( getAppUserDataDirectory, doesFileExist ) import System.IO ( stdout, stderr ) @@ -111,6 +111,7 @@ data Opt = Opt , optStrict :: Bool -- ^ Use strict markdown syntax , optReferenceLinks :: Bool -- ^ Use reference links in writing markdown, rst , optWrapText :: Bool -- ^ Wrap text + , optColumns :: Int -- ^ Line length in characters , optPlugins :: [Pandoc -> IO Pandoc] -- ^ Plugins to apply , optEmailObfuscation :: ObfuscationMethod , optIdentifierPrefix :: String @@ -150,6 +151,7 @@ defaultOpts = Opt , optStrict = False , optReferenceLinks = False , optWrapText = True + , optColumns = 72 , optPlugins = [] , optEmailObfuscation = JavascriptObfuscation , optIdentifierPrefix = "" @@ -194,8 +196,14 @@ options = , Option "" ["tab-stop"] (ReqArg - (\arg opt -> return opt { optTabStop = (read arg) } ) - "TABSTOP") + (\arg opt -> + case reads arg of + [(t,"")] | t > 0 -> return opt { optTabStop = t } + _ -> do + UTF8.hPutStrLn stderr $ + "tab-stop must be a number greater than 0" + exitWith $ ExitFailure 31) + "NUMBER") "" -- "Tab stop (default 4)" , Option "" ["strict"] @@ -300,6 +308,18 @@ options = (\opt -> return opt { optWrapText = False })) "" -- "Do not wrap text in output" + , Option "" ["columns"] + (ReqArg + (\arg opt -> + case reads arg of + [(t,"")] | t > 0 -> return opt { optColumns = t } + _ -> do + UTF8.hPutStrLn stderr $ + "columns must be a number greater than 0" + exitWith $ ExitFailure 33) + "NUMBER") + "" -- "Length of line in characters" + , Option "" ["email-obfuscation"] (ReqArg (\arg opt -> do @@ -333,17 +353,18 @@ options = , Option "" ["base-header-level"] (ReqArg - (\arg opt -> do - if all isDigit arg && (read arg :: Int) >= 1 - then do - let oldTransforms = optTransforms opt - let shift = read arg - 1 - return opt{ optTransforms = - headerShift shift : oldTransforms } - else do - UTF8.hPutStrLn stderr $ "base-header-level must be a number >= 1" - exitWith $ ExitFailure 19) - "LEVEL") + (\arg opt -> + case reads arg of + [(t,"")] | t > 0 -> do + let oldTransforms = optTransforms opt + let shift = t - 1 + return opt{ optTransforms = + headerShift shift : oldTransforms } + _ -> do + UTF8.hPutStrLn stderr $ + "base-header-level must be a number > 0" + exitWith $ ExitFailure 19) + "NUMBER") "" -- "Headers base level" , Option "" ["template"] @@ -617,6 +638,7 @@ main = do , optStrict = strict , optReferenceLinks = referenceLinks , optWrapText = wrap + , optColumns = columns , optEmailObfuscation = obfuscationMethod , optIdentifierPrefix = idPrefix , optIndentedCodeClasses = codeBlockClasses @@ -668,11 +690,6 @@ main = do Right t -> t Left e -> error (show e) - environment <- getEnvironment - let columns = case lookup "COLUMNS" environment of - Just cols -> read cols - Nothing -> stateColumns defaultParserState - let standalone' = standalone || isNonTextOutput writerName' variables' <- case (writerName', standalone', offline) of @@ -746,6 +763,7 @@ main = do writerStrictMarkdown = strict, writerReferenceLinks = referenceLinks, writerWrapText = wrap, + writerColumns = columns, writerLiterateHaskell = "+lhs" `isSuffixOf` writerName' || lhsExtension [outputFile], writerEmailObfuscation = if strict |