aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2011-01-11 22:25:57 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2011-01-11 23:15:30 -0800
commit91510a109f9284934fd5b6386fa23a5fc37b09bb (patch)
tree2cee03745727c1926ccfefcdf52e6c4b1a6603dc
parente8ad4ba43c7c187a5b6ee6025bc6039488d7f420 (diff)
downloadpandoc-91510a109f9284934fd5b6386fa23a5fc37b09bb.tar.gz
Improvements to --html5 support:
+ <nav> for TOC, <figure> for figures, type attribute in <ol>. + Don't add math javascript in html5. + Use style attributes instead of deprecated width, align. + html template: move <title> after <meta>. Note: charset needs to be declared before title. + slidy and s5 templates: move <title> after <meta>. + html template: Added link to html5 shim for IE. + Make --html5 have an effect only for 'html' writer (not s5, slidy, epub).
-rw-r--r--README2
-rw-r--r--src/Text/Pandoc/Writers/HTML.hs49
-rw-r--r--src/pandoc.hs5
-rw-r--r--templates/html.template10
-rw-r--r--templates/s5.template2
-rw-r--r--templates/slidy.template2
-rw-r--r--tests/s5.basic.html2
-rw-r--r--tests/s5.fancy.html2
-rw-r--r--tests/s5.inserts.html2
-rw-r--r--tests/writer.html36
10 files changed, 72 insertions, 40 deletions
diff --git a/README b/README
index f6d82e193..07f2266af 100644
--- a/README
+++ b/README
@@ -210,7 +210,7 @@ Options
`-5`, `--html5`
: Produce HTML5 instead of HTML4. This option has no effect for writers
- other than `html`, `epub`, `s5`, and `slidy`.
+ other than `html`.
`-m` *URL*, `--latexmathml=`*URL*
: Use the [LaTeXMathML] script to display embedded TeX math in HTML output.
diff --git a/src/Text/Pandoc/Writers/HTML.hs b/src/Text/Pandoc/Writers/HTML.hs
index c61387fa7..901575434 100644
--- a/src/Text/Pandoc/Writers/HTML.hs
+++ b/src/Text/Pandoc/Writers/HTML.hs
@@ -190,7 +190,12 @@ tableOfContents opts sects = do
let tocList = catMaybes contents
return $ if null tocList
then Nothing
- else Just $ thediv ! [prefixedId opts' "TOC"] $ unordList tocList
+ else Just $
+ if writerHtml5 opts
+ then tag "nav" ! [prefixedId opts' "TOC"] $
+ unordList tocList
+ else thediv ! [prefixedId opts' "TOC"] $
+ unordList tocList
-- | Convert section number to string
showSecNum :: [Int] -> String
@@ -299,8 +304,11 @@ blockToHtml opts (Plain lst) = inlineListToHtml opts lst
blockToHtml opts (Para [Image txt (s,tit)]) = do
img <- inlineToHtml opts (Image txt (s,tit))
capt <- inlineListToHtml opts txt
- return $ thediv ! [theclass "figure"] <<
- [img, paragraph ! [theclass "caption"] << capt]
+ return $ if writerHtml5 opts
+ then tag "figure" <<
+ [img, tag "figcaption" << capt]
+ else thediv ! [theclass "figure"] <<
+ [img, paragraph ! [theclass "caption"] << capt]
blockToHtml opts (Para lst) = inlineListToHtml opts lst >>= (return . paragraph)
blockToHtml _ (RawHtml str) = return $ primHtml str
blockToHtml _ (HorizontalRule) = return $ hr
@@ -371,7 +379,17 @@ blockToHtml opts (OrderedList (startnum, numstyle, _) lst) = do
then [start startnum]
else []) ++
(if numstyle /= DefaultStyle
- then [thestyle $ "list-style-type: " ++ numstyle' ++ ";"]
+ then if writerHtml5 opts
+ then [strAttr "type" $
+ case numstyle of
+ Decimal -> "1"
+ LowerAlpha -> "a"
+ UpperAlpha -> "A"
+ LowerRoman -> "i"
+ UpperRoman -> "I"
+ _ -> "1"]
+ else [thestyle $ "list-style-type: " ++
+ numstyle']
else [])
return $ ordList ! attribs $ contents
blockToHtml opts (DefinitionList lst) = do
@@ -384,28 +402,30 @@ blockToHtml opts (DefinitionList lst) = do
else []
return $ dlist ! attribs << concat contents
blockToHtml opts (Table capt aligns widths headers rows') = do
- let alignStrings = map alignmentToString aligns
captionDoc <- if null capt
then return noHtml
else inlineListToHtml opts capt >>= return . caption
let percent w = show (truncate (100*w) :: Integer) ++ "%"
+ let widthAttrs w = if writerHtml5 opts
+ then [thestyle $ "width: " ++ percent w]
+ else [width $ percent w]
let coltags = if all (== 0.0) widths
then noHtml
else concatHtml $ map
- (\w -> col ! [width $ percent w] $ noHtml) widths
+ (\w -> col ! (widthAttrs w) $ noHtml) widths
head' <- if all null headers
then return noHtml
- else liftM (thead <<) $ tableRowToHtml opts alignStrings 0 headers
+ else liftM (thead <<) $ tableRowToHtml opts aligns 0 headers
body' <- liftM (tbody <<) $
- zipWithM (tableRowToHtml opts alignStrings) [1..] rows'
+ zipWithM (tableRowToHtml opts aligns) [1..] rows'
return $ table $ captionDoc +++ coltags +++ head' +++ body'
tableRowToHtml :: WriterOptions
- -> [String]
+ -> [Alignment]
-> Int
-> [[Block]]
-> State WriterState Html
-tableRowToHtml opts alignStrings rownum cols' = do
+tableRowToHtml opts aligns rownum cols' = do
let mkcell = if rownum == 0 then th else td
let rowclass = case rownum of
0 -> "header"
@@ -413,7 +433,7 @@ tableRowToHtml opts alignStrings rownum cols' = do
_ -> "even"
cols'' <- sequence $ zipWith
(\alignment item -> tableItemToHtml opts mkcell alignment item)
- alignStrings cols'
+ aligns cols'
return $ tr ! [theclass rowclass] $ toHtmlFromList cols''
alignmentToString :: Alignment -> [Char]
@@ -425,12 +445,15 @@ alignmentToString alignment = case alignment of
tableItemToHtml :: WriterOptions
-> (Html -> Html)
- -> [Char]
+ -> Alignment
-> [Block]
-> State WriterState Html
tableItemToHtml opts tag' align' item = do
contents <- blockListToHtml opts item
- return $ tag' ! [align align'] $ contents
+ let alignAttrs = if writerHtml5 opts
+ then [thestyle $ "align: " ++ alignmentToString align']
+ else [align $ alignmentToString align']
+ return $ tag' ! alignAttrs $ contents
blockListToHtml :: WriterOptions -> [Block] -> State WriterState Html
blockListToHtml opts lst =
diff --git a/src/pandoc.hs b/src/pandoc.hs
index 0e57f8eb7..2068f5fc6 100644
--- a/src/pandoc.hs
+++ b/src/pandoc.hs
@@ -41,7 +41,7 @@ import System.Exit ( exitWith, ExitCode (..) )
import System.FilePath
import System.Console.GetOpt
import Data.Char ( toLower )
-import Data.List ( intercalate, isSuffixOf )
+import Data.List ( intercalate, isSuffixOf, isPrefixOf )
import System.Directory ( getAppUserDataDirectory, doesFileExist )
import System.IO ( stdout, stderr )
import qualified Text.Pandoc.UTF8 as UTF8
@@ -780,7 +780,8 @@ main = do
writerIdentifierPrefix = idPrefix,
writerSourceDirectory = sourceDir,
writerUserDataDir = datadir,
- writerHtml5 = html5 }
+ writerHtml5 = html5 &&
+ "html" `isPrefixOf` writerName' }
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 eabda4f44..3f8b76fed 100644
--- a/templates/html.template
+++ b/templates/html.template
@@ -6,7 +6,6 @@ $else$
<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$
@@ -19,6 +18,12 @@ $endfor$
$if(date)$
<meta name="date" content="$date$" />
$endif$
+ <title>$if(title-prefix)$$title-prefix$ - $endif$$if(pagetitle)$$pagetitle$$endif$</title>
+$if(html5)$
+ <!--[if lt IE 9]>
+ <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
+ <![endif]-->
+$endif$
$if(highlighting-css)$
<style type="text/css">
$highlighting-css$
@@ -28,8 +33,11 @@ $for(css)$
<link rel="stylesheet" href="$css$" $if(html5)$$else$type="text/css" $endif$/>
$endfor$
$if(math)$
+$if(html5)$
+$else$
$math$
$endif$
+$endif$
$for(header-includes)$
$header-includes$
$endfor$
diff --git a/templates/s5.template b/templates/s5.template
index 480c1e435..c1f727f6e 100644
--- a/templates/s5.template
+++ b/templates/s5.template
@@ -1,7 +1,6 @@
<!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">
<head>
- <title>$if(title-prefix)$$title-prefix$ - $endif$$if(pagetitle)$$pagetitle$$endif$</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="pandoc" />
$for(author)$
@@ -10,6 +9,7 @@ $endfor$
$if(date)$
<meta name="date" content="$date$" />
$endif$
+ <title>$if(title-prefix)$$title-prefix$ - $endif$$if(pagetitle)$$pagetitle$$endif$</title>
<!-- configuration parameters -->
<meta name="defaultView" content="slideshow" />
<meta name="controlVis" content="hidden" />
diff --git a/templates/slidy.template b/templates/slidy.template
index f625c36e2..9cfdb8f5e 100644
--- a/templates/slidy.template
+++ b/templates/slidy.template
@@ -3,7 +3,6 @@
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
- <title>$if(title-prefix)$$title-prefix$ - $endif$$if(pagetitle)$$pagetitle$$endif$</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="pandoc" />
$for(author)$
@@ -13,6 +12,7 @@ $if(date)$
<meta name="date" content="$date$" />
$endif$
$if(highlighting-css)$
+ <title>$if(title-prefix)$$title-prefix$ - $endif$$if(pagetitle)$$pagetitle$$endif$</title>
<style type="text/css">
$highlighting-css$
</style>
diff --git a/tests/s5.basic.html b/tests/s5.basic.html
index 825d05868..64971417a 100644
--- a/tests/s5.basic.html
+++ b/tests/s5.basic.html
@@ -1,12 +1,12 @@
<!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">
<head>
- <title>My S5 Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="pandoc" />
<meta name="author" content="Sam Smith" />
<meta name="author" content="Jen Jones" />
<meta name="date" content="July 15, 2006" />
+ <title>My S5 Document</title>
<!-- configuration parameters -->
<meta name="defaultView" content="slideshow" />
<meta name="controlVis" content="hidden" />
diff --git a/tests/s5.fancy.html b/tests/s5.fancy.html
index f4f2e7815..200990b6a 100644
--- a/tests/s5.fancy.html
+++ b/tests/s5.fancy.html
@@ -1,12 +1,12 @@
<!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">
<head>
- <title>My S5 Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="pandoc" />
<meta name="author" content="Sam Smith" />
<meta name="author" content="Jen Jones" />
<meta name="date" content="July 15, 2006" />
+ <title>My S5 Document</title>
<!-- configuration parameters -->
<meta name="defaultView" content="slideshow" />
<meta name="controlVis" content="hidden" />
diff --git a/tests/s5.inserts.html b/tests/s5.inserts.html
index 90014f2e6..3010ef758 100644
--- a/tests/s5.inserts.html
+++ b/tests/s5.inserts.html
@@ -1,12 +1,12 @@
<!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">
<head>
- <title>My S5 Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="pandoc" />
<meta name="author" content="Sam Smith" />
<meta name="author" content="Jen Jones" />
<meta name="date" content="July 15, 2006" />
+ <title>My S5 Document</title>
<link rel="stylesheet" href="main.css" type="text/css" />
STUFF INSERTED
</head>
diff --git a/tests/writer.html b/tests/writer.html
index 39ae2ebb7..ae83dc20f 100644
--- a/tests/writer.html
+++ b/tests/writer.html
@@ -1,12 +1,12 @@
<!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">
<head>
- <title>Pandoc Test Suite</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="pandoc" />
<meta name="author" content="John MacFarlane" />
<meta name="author" content="Anonymous" />
<meta name="date" content="July 17, 2006" />
+ <title>Pandoc Test Suite</title>
</head>
<body>
<h1 class="title">Pandoc Test Suite</h1>
@@ -74,7 +74,7 @@
></pre
><p
>A list:</p
- ><ol style="list-style-type: decimal;"
+ ><ol style="list-style-type: decimal"
><li
>item one</li
><li
@@ -207,7 +207,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
>Ordered</h2
><p
>Tight:</p
-><ol style="list-style-type: decimal;"
+><ol style="list-style-type: decimal"
><li
>First</li
><li
@@ -217,7 +217,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
></ol
><p
>and:</p
-><ol style="list-style-type: decimal;"
+><ol style="list-style-type: decimal"
><li
>One</li
><li
@@ -227,7 +227,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
></ol
><p
>Loose using tabs:</p
-><ol style="list-style-type: decimal;"
+><ol style="list-style-type: decimal"
><li
><p
>First</p
@@ -243,7 +243,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
></ol
><p
>and using spaces:</p
-><ol style="list-style-type: decimal;"
+><ol style="list-style-type: decimal"
><li
><p
>One</p
@@ -259,7 +259,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
></ol
><p
>Multiple paragraphs:</p
-><ol style="list-style-type: decimal;"
+><ol style="list-style-type: decimal"
><li
><p
>Item 1, graf one.</p
@@ -291,7 +291,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
></ul
><p
>Here’s another:</p
-><ol style="list-style-type: decimal;"
+><ol style="list-style-type: decimal"
><li
>First</li
><li
@@ -309,7 +309,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
></ol
><p
>Same thing but with paragraphs:</p
-><ol style="list-style-type: decimal;"
+><ol style="list-style-type: decimal"
><li
><p
>First</p
@@ -355,7 +355,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
></ul
><h2 id="fancy-list-markers"
>Fancy list markers</h2
-><ol start="2" style="list-style-type: decimal;"
+><ol start="2" style="list-style-type: decimal"
><li
>begins with 2</li
><li
@@ -363,11 +363,11 @@ These should not be escaped: \$ \\ \&gt; \[ \{
>and now 3</p
><p
>with a continuation</p
- ><ol start="4" style="list-style-type: lower-roman;"
+ ><ol start="4" style="list-style-type: lower-roman"
><li
>sublist with roman numerals, starting with 4</li
><li
- >more items<ol style="list-style-type: upper-alpha;"
+ >more items<ol style="list-style-type: upper-alpha"
><li
>a subsublist</li
><li
@@ -379,13 +379,13 @@ These should not be escaped: \$ \\ \&gt; \[ \{
></ol
><p
>Nesting:</p
-><ol style="list-style-type: upper-alpha;"
+><ol style="list-style-type: upper-alpha"
><li
- >Upper Alpha<ol style="list-style-type: upper-roman;"
+ >Upper Alpha<ol style="list-style-type: upper-roman"
><li
- >Upper Roman.<ol start="6" style="list-style-type: decimal;"
+ >Upper Roman.<ol start="6" style="list-style-type: decimal"
><li
- >Decimal start with 6<ol start="3" style="list-style-type: lower-alpha;"
+ >Decimal start with 6<ol start="3" style="list-style-type: lower-alpha"
><li
>Lower alpha with paren</li
></ol
@@ -559,7 +559,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
><dd
><p
>orange fruit</p
- ><ol style="list-style-type: decimal;"
+ ><ol style="list-style-type: decimal"
><li
>sublist</li
><li
@@ -1110,7 +1110,7 @@ document.write('<a h'+'ref'+'="ma'+'ilto'+':'+e+'">'+'<code>'+e+'</code>'+'<\/'+
></sup
></p
></blockquote
-><ol style="list-style-type: decimal;"
+><ol style="list-style-type: decimal"
><li
>And in list items.<sup
><a href="#fn5" class="footnoteRef" id="fnref5"