From 33ff2fed2171fb8b8267e9fff5fbff27d047dd96 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Tue, 11 Jan 2011 20:23:43 -0800 Subject: Text.Pandoc: Improved readers, writers lists for lhs variants. Now the lhs variants set the needed literate Haskell flag in parser state and writer options. --- src/Text/Pandoc.hs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/Text/Pandoc.hs b/src/Text/Pandoc.hs index c752ffede..3532c1d4b 100644 --- a/src/Text/Pandoc.hs +++ b/src/Text/Pandoc.hs @@ -146,13 +146,15 @@ readers :: [(String, ParserState -> String -> Pandoc)] readers = [("native" , \_ -> read) ,("json" , \_ -> decodeJSON) ,("markdown" , readMarkdown) - ,("markdown+lhs" , readMarkdown) + ,("markdown+lhs" , \st -> + readMarkdown st{ stateLiterateHaskell = True}) ,("rst" , readRST) ,("textile" , readTextile) -- TODO : textile+lhs ,("rst+lhs" , readRST) ,("html" , readHtml) ,("latex" , readLaTeX) - ,("latex+lhs" , readLaTeX) + ,("latex+lhs" , \st -> + readLaTeX st{ stateLiterateHaskell = True}) ] -- | Association list of formats and writers (omitting the @@ -161,21 +163,25 @@ writers :: [ ( String, WriterOptions -> Pandoc -> String ) ] writers = [("native" , writeNative) ,("json" , \_ -> encodeJSON) ,("html" , writeHtmlString) - ,("html+lhs" , writeHtmlString) + ,("html+lhs" , \o -> + writeHtmlString o{ writerLiterateHaskell = True }) ,("s5" , writeHtmlString) ,("slidy" , writeHtmlString) ,("docbook" , writeDocbook) ,("opendocument" , writeOpenDocument) ,("latex" , writeLaTeX) - ,("latex+lhs" , writeLaTeX) + ,("latex+lhs" , \o -> + writeLaTeX o{ writerLiterateHaskell = True }) ,("context" , writeConTeXt) ,("texinfo" , writeTexinfo) ,("man" , writeMan) ,("markdown" , writeMarkdown) - ,("markdown+lhs" , writeMarkdown) + ,("markdown+lhs" , \o -> + writeMarkdown o{ writerLiterateHaskell = True }) ,("plain" , writePlain) ,("rst" , writeRST) - ,("rst+lhs" , writeRST) + ,("rst+lhs" , \o -> + writeRST o{ writerLiterateHaskell = True }) ,("mediawiki" , writeMediaWiki) ,("textile" , writeTextile) ,("rtf" , writeRTF) -- cgit v1.2.3 From 6b1407d2090057bb951ecd0b239b659c138cc6b8 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Tue, 11 Jan 2011 20:34:49 -0800 Subject: Setup.hs: -Wall clean. --- Setup.hs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Setup.hs b/Setup.hs index b68435216..455909795 100644 --- a/Setup.hs +++ b/Setup.hs @@ -9,7 +9,7 @@ import Distribution.Verbosity ( Verbosity, silent ) import Distribution.Simple.InstallDirs (mandir, bindir, CopyDest (NoCopyDest)) import Distribution.Simple.Utils (copyFiles) import Control.Exception ( bracket_ ) -import Control.Monad ( unless, when ) +import Control.Monad ( unless ) import System.Process ( rawSystem, runCommand, runProcess, waitForProcess ) import System.FilePath ( (), (<.>) ) import System.Directory @@ -55,8 +55,8 @@ runTestSuite _ _ pkg lbi = do -- | Build man pages from markdown sources in man/man1/. makeManPages :: Args -> BuildFlags -> PackageDescription -> LocalBuildInfo -> IO () -makeManPages _ flags _ buildInfo = do - let pandocPath = (buildDir buildInfo) "pandoc" "pandoc" +makeManPages _ flags _ bi = do + let pandocPath = (buildDir bi) "pandoc" "pandoc" makeManPage pandocPath (fromFlag $ buildVerbosity flags) "markdown2pdf.1" let testCmd = "runghc -package-conf=dist/package.conf.inplace MakeManPage.hs" -- makes pandoc.1 from README runCommand testCmd >>= waitForProcess >>= exitWith -- cgit v1.2.3 From e8ad4ba43c7c187a5b6ee6025bc6039488d7f420 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Tue, 11 Jan 2011 20:37:06 -0800 Subject: Preliminary support for HTML5. + Added writerHtml5 writer option. + Added --html5 option. + Added support for lang in html tag (so you can do 'pandoc -s --V lang=en', for example). + Updated html template with conditionals for HTML5. + When HTML5 selected, use
tag around title in document, and use
tags instead of
s if --section-divs specified. --- README | 16 ++++++++++++---- src/Text/Pandoc/Shared.hs | 2 ++ src/Text/Pandoc/Writers/HTML.hs | 5 ++++- src/pandoc.hs | 11 ++++++++++- templates/html.template | 19 +++++++++++++++++-- 5 files changed, 45 insertions(+), 8 deletions(-) diff --git a/README b/README index 1647ef4a9..f6d82e193 100644 --- a/README +++ b/README @@ -208,6 +208,10 @@ Options `markdown` or `textile`. It is selected automatically when the input format is `textile` or the output format is `latex` or `context`.) +`-5`, `--html5` +: Produce HTML5 instead of HTML4. This option has no effect for writers + other than `html`, `epub`, `s5`, and `slidy`. + `-m` *URL*, `--latexmathml=`*URL* : Use the [LaTeXMathML] script to display embedded TeX math in HTML output. To insert a link to a local copy of the `LaTeXMathML.js` script, @@ -262,8 +266,9 @@ Options By default, sections are not numbered. `--section-divs` -: Wrap sections in `
` tags, and attach identifiers to the - enclosing `
` rather than the header itself. +: Wrap sections in `
` tags (or `
` tags in HTML5), + and attach identifiers to the enclosing `
` (or `
`) + rather than the header itself. See [Section identifiers](#header-identifiers-in-html), below. `--no-wrap` @@ -504,6 +509,8 @@ depending on the output format, but include: multiple values) `date` : date of document, as specified in title block +`lang` +: language code for HTML documents Variables may be set at the command line using the `-V/--variable` option. This allows users to include custom variables in their @@ -1143,8 +1150,9 @@ Note, however, that this method of providing links to sections works only in HTML. If the `--section-divs` option is specified, then each section will -be wrapped in a `div`, and the identifier will be attached to the -enclosing `
` tag rather than the header itself. This allows entire +be wrapped in a `div` (or a `section`, if `--html5` was specified), +and the identifier will be attached to the enclosing `
` +(or `
`) tag rather than the header itself. This allows entire sections to be manipulated using javascript or treated differently in CSS. diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs index cc94cf635..f757f4479 100644 --- a/src/Text/Pandoc/Shared.hs +++ b/src/Text/Pandoc/Shared.hs @@ -481,6 +481,7 @@ data WriterOptions = WriterOptions , writerUserDataDir :: Maybe FilePath -- ^ Path of user data directory , writerCiteMethod :: CiteMethod -- ^ How to print cites , writerBiblioFiles :: [FilePath] -- ^ Biblio files to use for citations + , writerHtml5 :: Bool -- ^ Produce HTML5 } deriving Show -- | Default writer options. @@ -510,6 +511,7 @@ defaultWriterOptions = , writerUserDataDir = Nothing , writerCiteMethod = Citeproc , writerBiblioFiles = [] + , writerHtml5 = False } -- diff --git a/src/Text/Pandoc/Writers/HTML.hs b/src/Text/Pandoc/Writers/HTML.hs index b8da4bec0..c61387fa7 100644 --- a/src/Text/Pandoc/Writers/HTML.hs +++ b/src/Text/Pandoc/Writers/HTML.hs @@ -170,6 +170,7 @@ inTemplate opts tit auths date toc body' newvars = , ("pagetitle", topTitle') , ("title", renderHtmlFragment tit) , ("date", date') ] ++ + [ ("html5","true") | writerHtml5 opts ] ++ (case toc of Just t -> [ ("toc", renderHtmlFragment t)] Nothing -> []) ++ @@ -226,7 +227,9 @@ elementToHtml opts (Sec level num id' title' elements) = do return $ if slides -- S5 gets confused by the extra divs around sections then toHtmlFromList stuff else if writerSectionDivs opts - then thediv ! [prefixedId opts id'] << stuff + then if writerHtml5 opts + then tag "section" << stuff + else thediv ! [prefixedId opts id'] << stuff else toHtmlFromList stuff -- | Convert list of Note blocks to a footnote
. diff --git a/src/pandoc.hs b/src/pandoc.hs index 8811e6816..0e57f8eb7 100644 --- a/src/pandoc.hs +++ b/src/pandoc.hs @@ -102,6 +102,7 @@ data Opt = Opt , optOffline :: Bool -- ^ Make slideshow accessible offline , optXeTeX :: Bool -- ^ Format latex for xetex , optSmart :: Bool -- ^ Use smart typography + , optHtml5 :: Bool -- ^ Produce HTML5 in HTML , optHTMLMathMethod :: HTMLMathMethod -- ^ Method to print HTML math , optReferenceODT :: Maybe FilePath -- ^ Path of reference.odt , optEPUBStylesheet :: Maybe String -- ^ EPUB stylesheet @@ -142,6 +143,7 @@ defaultOpts = Opt , optOffline = False , optXeTeX = False , optSmart = False + , optHtml5 = False , optHTMLMathMethod = PlainMath , optReferenceODT = Nothing , optEPUBStylesheet = Nothing @@ -226,6 +228,11 @@ options = (\opt -> return opt { optSmart = True })) "" -- "Use smart quotes, dashes, and ellipses" + , Option "5" ["html5"] + (NoArg + (\opt -> return opt { optHtml5 = True })) + "" -- "Produce HTML5 in HTML output" + , Option "m" ["latexmathml", "asciimathml"] (OptArg (\arg opt -> @@ -629,6 +636,7 @@ main = do , optOffline = offline , optXeTeX = xetex , optSmart = smart + , optHtml5 = html5 , optHTMLMathMethod = mathMethod , optReferenceODT = referenceODT , optEPUBStylesheet = epubStylesheet @@ -771,7 +779,8 @@ main = do else obfuscationMethod, writerIdentifierPrefix = idPrefix, writerSourceDirectory = sourceDir, - writerUserDataDir = datadir } + writerUserDataDir = datadir, + writerHtml5 = html5 } when (isNonTextOutput writerName' && outputFile == "-") $ do UTF8.hPutStrLn stderr ("Error: Cannot write " ++ writerName ++ " output to stdout.\n" ++ diff --git a/templates/html.template b/templates/html.template index bd1864ff0..eabda4f44 100644 --- a/templates/html.template +++ b/templates/html.template @@ -1,8 +1,17 @@ +$if(html5)$ + + +$else$ - + +$endif$ $if(title-prefix)$$title-prefix$ - $endif$$if(pagetitle)$$pagetitle$$endif$ +$if(html5)$ + +$else$ +$endif$ $for(author)$ @@ -16,7 +25,7 @@ $highlighting-css$ $endif$ $for(css)$ - + $endfor$ $if(math)$ $math$ @@ -30,7 +39,13 @@ $for(include-before)$ $include-before$ $endfor$ $if(title)$ +$if(html5)$ +
+$endif$

$title$

+$if(html5)$ +
+$endif$ $endif$ $if(toc)$ $toc$ -- cgit v1.2.3 From 91510a109f9284934fd5b6386fa23a5fc37b09bb Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Tue, 11 Jan 2011 22:25:57 -0800 Subject: Improvements to --html5 support: +