Package: pandoc Version: 1.3-1 Severity: wishlist Tags: patch Hi!
It would be very handy if pandoc would have an option to specify the base level for headers. An example is worth many words: Given a Markdown file with an header like: ## Header level 2 When the base level is set to 3, pandoc would generate an HTML file with: <h4>Header level 2</h4> Having such feature would be helpful to generate complex documents from different files. The attached patch adds a --headers-base-level option as a possible implementation. Cheers, -- Jérémy Bobbio .''`. lu...@debian.org : :Ⓐ : # apt-get install anarchism `. `'` `-
--- pandoc-1.3.orig/man/man1/pandoc.1.md +++ pandoc-1.3/man/man1/pandoc.1.md @@ -169,6 +169,9 @@ to Pandoc. Or use `html2markdown`(1), a RTF) or an instruction to create one (LaTeX, reStructuredText). This option has no effect on man, DocBook, or S5 output. +\--headers-base-level=*LEVEL* +: Specify the base level for headers (defaults to 1). + -c *CSS*, \--css=*CSS* : Link to a CSS style sheet. *CSS* is the pathname of the style sheet. --- pandoc-1.3.orig/src/pandoc.hs +++ pandoc-1.3/src/pandoc.hs @@ -135,6 +135,7 @@ data Opt = Opt , optParseRaw :: Bool -- ^ Parse unconvertable HTML and TeX , optCSS :: [String] -- ^ CSS file to link to , optTableOfContents :: Bool -- ^ Include table of contents + , optHeadersBaseLevel :: Int -- ^ Headers base level , optIncludeInHeader :: String -- ^ File to include in header , optIncludeBeforeBody :: String -- ^ File to include at top of body , optIncludeAfterBody :: String -- ^ File to include at end of body @@ -173,6 +174,7 @@ defaultOpts = Opt , optParseRaw = False , optCSS = [] , optTableOfContents = False + , optHeadersBaseLevel = 1 , optIncludeInHeader = "" , optIncludeBeforeBody = "" , optIncludeAfterBody = "" @@ -334,6 +336,12 @@ options = (\opt -> return opt { optTableOfContents = True })) "" -- "Include table of contents" + , Option "" ["headers-base-level"] + (ReqArg + (\arg opt -> return opt { optHeadersBaseLevel = (read arg) }) + "LEVEL") + "" -- "Headers base level" + , Option "c" ["css"] (ReqArg (\arg opt -> do @@ -497,6 +505,10 @@ defaultWriterName x = ['.',y] | y `elem` ['1'..'9'] -> "man" _ -> "html" +shiftHeaderLevels :: Int -> Block -> Block +shiftHeaderLevels shift (Header level inner) = Header (level + shift) inner +shiftHeaderLevels _ x = x + main :: IO () main = do @@ -531,6 +543,7 @@ main = do , optParseRaw = parseRaw , optCSS = css , optTableOfContents = toc + , optHeadersBaseLevel = headersBaseLevel , optIncludeInHeader = includeHeader , optIncludeBeforeBody = includeBefore , optIncludeAfterBody = includeAfter @@ -656,15 +669,18 @@ main = do let convertTabs = tabFilter (if preserveTabs then 0 else tabStop) doc <- fmap (reader startParserState . convertTabs . intercalate "\n") (readSources sources) + + let doc' = if headersBaseLevel > 1 then processWith (shiftHeaderLevels (headersBaseLevel - 1)) doc + else doc - doc' <- do + doc'' <- do #ifdef _CITEPROC - processBiblio cslFile refs doc + processBiblio cslFile refs doc' #else - return doc + return doc' #endif - let writerOutput = writer writerOptions doc' ++ "\n" + let writerOutput = writer writerOptions doc'' ++ "\n" case writerName' of "odt" -> saveOpenDocumentAsODT outputFile sourceDirRelative writerOutput
signature.asc
Description: Digital signature