aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2011-01-11 20:37:06 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2011-01-11 21:18:46 -0800
commite8ad4ba43c7c187a5b6ee6025bc6039488d7f420 (patch)
tree09f1c8d8765796962b06bd5dfdea5b7c3ed1a241
parent6b1407d2090057bb951ecd0b239b659c138cc6b8 (diff)
downloadpandoc-e8ad4ba43c7c187a5b6ee6025bc6039488d7f420.tar.gz
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.
-rw-r--r--README16
-rw-r--r--src/Text/Pandoc/Shared.hs2
-rw-r--r--src/Text/Pandoc/Writers/HTML.hs5
-rw-r--r--src/pandoc.hs11
-rw-r--r--templates/html.template19
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 `<div>` tags, and attach identifiers to the
- enclosing `<div>` rather than the header itself.
+: Wrap sections in `<div>` tags (or `<section>` tags in HTML5),
+ and attach identifiers to the enclosing `<div>` (or `<section>`)
+ 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 `<div>` 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 `<div>`
+(or `<section>`) 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 <div>.
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)$
+<!DOCTYPE html>
+<html$if(lang)$ lang="$lang$"$endif$>
+$else$
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml">
+<html xmlns="http://www.w3.org/1999/xhtml"$if(lang)$ lang="$lang$" xml:lang="$lang$"$endif$>
+$endif$
<head>
<title>$if(title-prefix)$$title-prefix$ - $endif$$if(pagetitle)$$pagetitle$$endif$</title>
+$if(html5)$
+ <meta charset="utf-8" />
+$else$
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+$endif$
<meta name="generator" content="pandoc" />
$for(author)$
<meta name="author" content="$author$" />
@@ -16,7 +25,7 @@ $highlighting-css$
</style>
$endif$
$for(css)$
- <link rel="stylesheet" href="$css$" type="text/css" />
+ <link rel="stylesheet" href="$css$" $if(html5)$$else$type="text/css" $endif$/>
$endfor$
$if(math)$
$math$
@@ -30,7 +39,13 @@ $for(include-before)$
$include-before$
$endfor$
$if(title)$
+$if(html5)$
+<header>
+$endif$
<h1 class="title">$title$</h1>
+$if(html5)$
+</header>
+$endif$
$endif$
$if(toc)$
$toc$