From df0ce7658c28f45dd9afee804c76e3411b53c0ef Mon Sep 17 00:00:00 2001 From: fiddlosopher Date: Tue, 1 Dec 2009 06:56:47 +0000 Subject: [PATCH] Added --default-code-classes option. This specifies classes to use for indented code blocks. Thanks to buttock for the (slightly modified) patch. Resolves Issue #87. git-svn-id: https://pandoc.googlecode.com/svn/trunk@1637 788f1e2b-df1e-0410-8736-df70ead52e1b --- README | 5 +++++ man/man1/pandoc.1.md | 5 +++++ src/Text/Pandoc/Readers/Markdown.hs | 3 ++- src/Text/Pandoc/Shared.hs | 6 ++++-- src/pandoc.hs | 13 ++++++++++++- 5 files changed, 28 insertions(+), 4 deletions(-) diff --git a/README b/README index f5f964ec4..ecf41cb3a 100644 --- a/README +++ b/README @@ -384,6 +384,11 @@ For further documentation, see the `pandoc(1)` man page. is specified, *references* is used regardless of the presence of this option. +`--default-code-classes`*=classes* +: specifies classes to use for indented code blocks--for example, + `perl,numberLines` or `haskell`. Multiple classes may be separated + by spaces or commas. + `--dump-args` : is intended to make it easier to create wrapper scripts that use Pandoc. It causes Pandoc to dump information about the arguments diff --git a/man/man1/pandoc.1.md b/man/man1/pandoc.1.md index 9a0907321..f587526fa 100644 --- a/man/man1/pandoc.1.md +++ b/man/man1/pandoc.1.md @@ -154,6 +154,11 @@ to Pandoc. Or use `html2markdown`(1), a wrapper around `pandoc`. If `--strict` is specified, *references* is used regardless of the presence of this option. +\--default-code-classes*=classes* +: Specify classes to use for indented code blocks--for example, + `perl,numberLines` or `haskell`. Multiple classes may be separated + by spaces or commas. + \--toc, \--table-of-contents : Include an automatically generated table of contents (HTML, markdown, RTF) or an instruction to create one (LaTeX, reStructuredText). diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs index f4384d493..cfd9c8b5c 100644 --- a/src/Text/Pandoc/Readers/Markdown.hs +++ b/src/Text/Pandoc/Readers/Markdown.hs @@ -394,7 +394,8 @@ codeBlockIndented = do l <- indentedLine return $ b ++ l)) optional blanklines - return $ CodeBlock ("",[],[]) $ stripTrailingNewlines $ concat contents + st <- getState + return $ CodeBlock ("", stateDefaultCodeClasses st, []) $ stripTrailingNewlines $ concat contents lhsCodeBlock :: GenParser Char ParserState Block lhsCodeBlock = do diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs index a0c45072d..73b5740d1 100644 --- a/src/Text/Pandoc/Shared.hs +++ b/src/Text/Pandoc/Shared.hs @@ -671,7 +671,8 @@ data ParserState = ParserState stateSmart :: Bool, -- ^ Use smart typography? stateLiterateHaskell :: Bool, -- ^ Treat input as literate haskell stateColumns :: Int, -- ^ Number of columns in terminal - stateHeaderTable :: [HeaderType] -- ^ Ordered list of header types used + stateHeaderTable :: [HeaderType], -- ^ Ordered list of header types used + stateDefaultCodeClasses :: [String] -- ^ Classes to use for indented code blocks } deriving Show @@ -695,7 +696,8 @@ defaultParserState = stateSmart = False, stateLiterateHaskell = False, stateColumns = 80, - stateHeaderTable = [] } + stateHeaderTable = [], + stateDefaultCodeClasses = [] } data HeaderType = SingleHeader Char -- ^ Single line of characters underneath diff --git a/src/pandoc.hs b/src/pandoc.hs index d6c45501e..937491a6a 100644 --- a/src/pandoc.hs +++ b/src/pandoc.hs @@ -153,6 +153,7 @@ data Opt = Opt , optSanitizeHTML :: Bool -- ^ Sanitize HTML , optPlugins :: [Pandoc -> IO Pandoc] -- ^ Plugins to apply , optEmailObfuscation :: ObfuscationMethod + , optDefaultCodeClasses :: [String] -- ^ Default classes for indented code blocks #ifdef _CITEPROC , optBiblioFile :: String , optBiblioFormat :: String @@ -189,6 +190,7 @@ defaultOpts = Opt , optSanitizeHTML = False , optPlugins = [] , optEmailObfuscation = JavascriptObfuscation + , optDefaultCodeClasses = [] #ifdef _CITEPROC , optBiblioFile = [] , optBiblioFormat = [] @@ -312,6 +314,13 @@ options = "none|javascript|references") "" -- "Method for obfuscating email in HTML" + , Option "" ["default-code-classes"] + (ReqArg + (\arg opt -> return opt { optDefaultCodeClasses = words $ + map (\c -> if c == ',' then ' ' else c) arg }) + "STRING") + "" -- "Classes (whitespace- or comma-separated) to use for indented code-blocks" + , Option "" ["toc", "table-of-contents"] (NoArg (\opt -> return opt { optTableOfContents = True })) @@ -531,6 +540,7 @@ main = do , optWrapText = wrap , optSanitizeHTML = sanitize , optEmailObfuscation = obfuscationMethod + , optDefaultCodeClasses = codeBlockClasses #ifdef _CITEPROC , optBiblioFile = biblioFile , optBiblioFormat = biblioFormat @@ -586,7 +596,8 @@ main = do stateSmart = smart || writerName' `elem` ["latex", "context", "man"], stateColumns = columns, - stateStrict = strict } + stateStrict = strict, + stateDefaultCodeClasses = codeBlockClasses } let csslink = if null css then "" else concatMap