git.iko.soy/typeable/pandoc
on master help sign in
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 <header> tag around title in document, and use <section> tags instead of <div>s if --section-divs specified.

commite8ad4ba43c7c187a5b6ee6025bc6039488d7f420 authorJohn MacFarlane <jgm@berkeley.edu> dateTue 11 Jan 2011, 20:37 (16 years ago) parent6b1407d
5 files changed+45−8
README+12−4 src/Text/Pandoc/Shared.hs+2 src/Text/Pandoc/Writers/HTML.hs+4−1 src/pandoc.hs+10−1 templates/html.template+17−2
README+12−4
@@ -208,6 +208,10 @@ Options
208208 `markdown` or `textile`. It is selected automatically when the input
209209 format is `textile` or the output format is `latex` or `context`.)
210210
211+`-5`, `--html5`
212+: Produce HTML5 instead of HTML4. This option has no effect for writers
213+ other than `html`, `epub`, `s5`, and `slidy`.
214+
211215`-m` *URL*, `--latexmathml=`*URL*
212216: Use the [LaTeXMathML] script to display embedded TeX math in HTML output.
213217 To insert a link to a local copy of the `LaTeXMathML.js` script,
@@ -262,8 +266,9 @@ Options
262266 By default, sections are not numbered.
263267
264268`--section-divs`
265−: Wrap sections in `<div>` tags, and attach identifiers to the
266− enclosing `<div>` rather than the header itself.
269+: Wrap sections in `<div>` tags (or `<section>` tags in HTML5),
270+ and attach identifiers to the enclosing `<div>` (or `<section>`)
271+ rather than the header itself.
267272 See [Section identifiers](#header-identifiers-in-html), below.
268273
269274`--no-wrap`
@@ -504,6 +509,8 @@ depending on the output format, but include:
504509 multiple values)
505510`date`
506511: date of document, as specified in title block
512+`lang`
513+: language code for HTML documents
507514
508515Variables may be set at the command line using the `-V/--variable`
509516option. This allows users to include custom variables in their
@@ -1143,8 +1150,9 @@ Note, however, that this method of providing links to sections works
11431150only in HTML.
11441151
11451152If the `--section-divs` option is specified, then each section will
1146−be wrapped in a `div`, and the identifier will be attached to the
1147−enclosing `<div>` tag rather than the header itself. This allows entire
1153+be wrapped in a `div` (or a `section`, if `--html5` was specified),
1154+and the identifier will be attached to the enclosing `<div>`
1155+(or `<section>`) tag rather than the header itself. This allows entire
11481156sections to be manipulated using javascript or treated differently in
11491157CSS.
11501158
src/Text/Pandoc/Shared.hs+2
@@ -481,6 +481,7 @@ data WriterOptions = WriterOptions
481481 , writerUserDataDir :: Maybe FilePath -- ^ Path of user data directory
482482 , writerCiteMethod :: CiteMethod -- ^ How to print cites
483483 , writerBiblioFiles :: [FilePath] -- ^ Biblio files to use for citations
484+ , writerHtml5 :: Bool -- ^ Produce HTML5
484485 } deriving Show
485486
486487-- | Default writer options.
@@ -510,6 +511,7 @@ defaultWriterOptions =
510511 , writerUserDataDir = Nothing
511512 , writerCiteMethod = Citeproc
512513 , writerBiblioFiles = []
514+ , writerHtml5 = False
513515 }
514516
515517--
src/Text/Pandoc/Writers/HTML.hs+4−1
@@ -170,6 +170,7 @@ inTemplate opts tit auths date toc body' newvars =
170170 , ("pagetitle", topTitle')
171171 , ("title", renderHtmlFragment tit)
172172 , ("date", date') ] ++
173+ [ ("html5","true") | writerHtml5 opts ] ++
173174 (case toc of
174175 Just t -> [ ("toc", renderHtmlFragment t)]
175176 Nothing -> []) ++
@@ -226,7 +227,9 @@ elementToHtml opts (Sec level num id' title' elements) = do
226227 return $ if slides -- S5 gets confused by the extra divs around sections
227228 then toHtmlFromList stuff
228229 else if writerSectionDivs opts
229− then thediv ! [prefixedId opts id'] << stuff
230+ then if writerHtml5 opts
231+ then tag "section" << stuff
232+ else thediv ! [prefixedId opts id'] << stuff
230233 else toHtmlFromList stuff
231234
232235-- | Convert list of Note blocks to a footnote <div>.
src/pandoc.hs+10−1
@@ -102,6 +102,7 @@ data Opt = Opt
102102 , optOffline :: Bool -- ^ Make slideshow accessible offline
103103 , optXeTeX :: Bool -- ^ Format latex for xetex
104104 , optSmart :: Bool -- ^ Use smart typography
105+ , optHtml5 :: Bool -- ^ Produce HTML5 in HTML
105106 , optHTMLMathMethod :: HTMLMathMethod -- ^ Method to print HTML math
106107 , optReferenceODT :: Maybe FilePath -- ^ Path of reference.odt
107108 , optEPUBStylesheet :: Maybe String -- ^ EPUB stylesheet
@@ -142,6 +143,7 @@ defaultOpts = Opt
142143 , optOffline = False
143144 , optXeTeX = False
144145 , optSmart = False
146+ , optHtml5 = False
145147 , optHTMLMathMethod = PlainMath
146148 , optReferenceODT = Nothing
147149 , optEPUBStylesheet = Nothing
@@ -226,6 +228,11 @@ options =
226228 (\opt -> return opt { optSmart = True }))
227229 "" -- "Use smart quotes, dashes, and ellipses"
228230
231+ , Option "5" ["html5"]
232+ (NoArg
233+ (\opt -> return opt { optHtml5 = True }))
234+ "" -- "Produce HTML5 in HTML output"
235+
229236 , Option "m" ["latexmathml", "asciimathml"]
230237 (OptArg
231238 (\arg opt ->
@@ -629,6 +636,7 @@ main = do
629636 , optOffline = offline
630637 , optXeTeX = xetex
631638 , optSmart = smart
639+ , optHtml5 = html5
632640 , optHTMLMathMethod = mathMethod
633641 , optReferenceODT = referenceODT
634642 , optEPUBStylesheet = epubStylesheet
@@ -771,7 +779,8 @@ main = do
771779 else obfuscationMethod,
772780 writerIdentifierPrefix = idPrefix,
773781 writerSourceDirectory = sourceDir,
774− writerUserDataDir = datadir }
782+ writerUserDataDir = datadir,
783+ writerHtml5 = html5 }
775784
776785 when (isNonTextOutput writerName' && outputFile == "-") $
777786 do UTF8.hPutStrLn stderr ("Error: Cannot write " ++ writerName ++ " output to stdout.\n" ++
templates/html.template+17−2
@@ -1,8 +1,17 @@
1+$if(html5)$
2+<!DOCTYPE html>
3+<html$if(lang)$ lang="$lang$"$endif$>
4+$else$
15<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2−<html xmlns="http://www.w3.org/1999/xhtml">
6+<html xmlns="http://www.w3.org/1999/xhtml"$if(lang)$ lang="$lang$" xml:lang="$lang$"$endif$>
7+$endif$
38<head>
49 <title>$if(title-prefix)$$title-prefix$ - $endif$$if(pagetitle)$$pagetitle$$endif$</title>
10+$if(html5)$
11+ <meta charset="utf-8" />
12+$else$
513 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
14+$endif$
615 <meta name="generator" content="pandoc" />
716$for(author)$
817 <meta name="author" content="$author$" />
@@ -16,7 +25,7 @@ $highlighting-css$
1625 </style>
1726$endif$
1827$for(css)$
19− <link rel="stylesheet" href="$css$" type="text/css" />
28+ <link rel="stylesheet" href="$css$" $if(html5)$$else$type="text/css" $endif$/>
2029$endfor$
2130$if(math)$
2231 $math$
@@ -30,7 +39,13 @@ $for(include-before)$
3039$include-before$
3140$endfor$
3241$if(title)$
42+$if(html5)$
43+<header>
44+$endif$
3345<h1 class="title">$title$</h1>
46+$if(html5)$
47+</header>
48+$endif$
3449$endif$
3550$if(toc)$
3651$toc$