git.iko.soy/typeable/pandoc
on master help sign in
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).

commit91510a109f9284934fd5b6386fa23a5fc37b09bb authorJohn MacFarlane <jgm@berkeley.edu> dateTue 11 Jan 2011, 22:25 (16 years ago) parente8ad4ba
10 files changed+72−40
README+1−1 src/Text/Pandoc/Writers/HTML.hs+36−13 src/pandoc.hs+3−2 templates/html.template+9−1 templates/s5.template+1−1 templates/slidy.template+1−1 tests/s5.basic.html+1−1 tests/s5.fancy.html+1−1 tests/s5.inserts.html+1−1 tests/writer.html+18−18
README+1−1
@@ -210,7 +210,7 @@ Options
210210
211211`-5`, `--html5`
212212: Produce HTML5 instead of HTML4. This option has no effect for writers
213− other than `html`, `epub`, `s5`, and `slidy`.
213+ other than `html`.
214214
215215`-m` *URL*, `--latexmathml=`*URL*
216216: Use the [LaTeXMathML] script to display embedded TeX math in HTML output.
src/Text/Pandoc/Writers/HTML.hs+36−13
@@ -190,7 +190,12 @@ tableOfContents opts sects = do
190190 let tocList = catMaybes contents
191191 return $ if null tocList
192192 then Nothing
193− else Just $ thediv ! [prefixedId opts' "TOC"] $ unordList tocList
193+ else Just $
194+ if writerHtml5 opts
195+ then tag "nav" ! [prefixedId opts' "TOC"] $
196+ unordList tocList
197+ else thediv ! [prefixedId opts' "TOC"] $
198+ unordList tocList
194199
195200-- | Convert section number to string
196201showSecNum :: [Int] -> String
@@ -299,8 +304,11 @@ blockToHtml opts (Plain lst) = inlineListToHtml opts lst
299304blockToHtml opts (Para [Image txt (s,tit)]) = do
300305 img <- inlineToHtml opts (Image txt (s,tit))
301306 capt <- inlineListToHtml opts txt
302− return $ thediv ! [theclass "figure"] <<
303− [img, paragraph ! [theclass "caption"] << capt]
307+ return $ if writerHtml5 opts
308+ then tag "figure" <<
309+ [img, tag "figcaption" << capt]
310+ else thediv ! [theclass "figure"] <<
311+ [img, paragraph ! [theclass "caption"] << capt]
304312blockToHtml opts (Para lst) = inlineListToHtml opts lst >>= (return . paragraph)
305313blockToHtml _ (RawHtml str) = return $ primHtml str
306314blockToHtml _ (HorizontalRule) = return $ hr
@@ -371,7 +379,17 @@ blockToHtml opts (OrderedList (startnum, numstyle, _) lst) = do
371379 then [start startnum]
372380 else []) ++
373381 (if numstyle /= DefaultStyle
374− then [thestyle $ "list-style-type: " ++ numstyle' ++ ";"]
382+ then if writerHtml5 opts
383+ then [strAttr "type" $
384+ case numstyle of
385+ Decimal -> "1"
386+ LowerAlpha -> "a"
387+ UpperAlpha -> "A"
388+ LowerRoman -> "i"
389+ UpperRoman -> "I"
390+ _ -> "1"]
391+ else [thestyle $ "list-style-type: " ++
392+ numstyle']
375393 else [])
376394 return $ ordList ! attribs $ contents
377395blockToHtml opts (DefinitionList lst) = do
@@ -384,28 +402,30 @@ blockToHtml opts (DefinitionList lst) = do
384402 else []
385403 return $ dlist ! attribs << concat contents
386404blockToHtml opts (Table capt aligns widths headers rows') = do
387− let alignStrings = map alignmentToString aligns
388405 captionDoc <- if null capt
389406 then return noHtml
390407 else inlineListToHtml opts capt >>= return . caption
391408 let percent w = show (truncate (100*w) :: Integer) ++ "%"
409+ let widthAttrs w = if writerHtml5 opts
410+ then [thestyle $ "width: " ++ percent w]
411+ else [width $ percent w]
392412 let coltags = if all (== 0.0) widths
393413 then noHtml
394414 else concatHtml $ map
395− (\w -> col ! [width $ percent w] $ noHtml) widths
415+ (\w -> col ! (widthAttrs w) $ noHtml) widths
396416 head' <- if all null headers
397417 then return noHtml
398− else liftM (thead <<) $ tableRowToHtml opts alignStrings 0 headers
418+ else liftM (thead <<) $ tableRowToHtml opts aligns 0 headers
399419 body' <- liftM (tbody <<) $
400− zipWithM (tableRowToHtml opts alignStrings) [1..] rows'
420+ zipWithM (tableRowToHtml opts aligns) [1..] rows'
401421 return $ table $ captionDoc +++ coltags +++ head' +++ body'
402422
403423tableRowToHtml :: WriterOptions
404− -> [String]
424+ -> [Alignment]
405425 -> Int
406426 -> [[Block]]
407427 -> State WriterState Html
408−tableRowToHtml opts alignStrings rownum cols' = do
428+tableRowToHtml opts aligns rownum cols' = do
409429 let mkcell = if rownum == 0 then th else td
410430 let rowclass = case rownum of
411431 0 -> "header"
@@ -413,7 +433,7 @@ tableRowToHtml opts alignStrings rownum cols' = do
413433 _ -> "even"
414434 cols'' <- sequence $ zipWith
415435 (\alignment item -> tableItemToHtml opts mkcell alignment item)
416− alignStrings cols'
436+ aligns cols'
417437 return $ tr ! [theclass rowclass] $ toHtmlFromList cols''
418438
419439alignmentToString :: Alignment -> [Char]
@@ -425,12 +445,15 @@ alignmentToString alignment = case alignment of
425445
426446tableItemToHtml :: WriterOptions
427447 -> (Html -> Html)
428− -> [Char]
448+ -> Alignment
429449 -> [Block]
430450 -> State WriterState Html
431451tableItemToHtml opts tag' align' item = do
432452 contents <- blockListToHtml opts item
433− return $ tag' ! [align align'] $ contents
453+ let alignAttrs = if writerHtml5 opts
454+ then [thestyle $ "align: " ++ alignmentToString align']
455+ else [align $ alignmentToString align']
456+ return $ tag' ! alignAttrs $ contents
434457
435458blockListToHtml :: WriterOptions -> [Block] -> State WriterState Html
436459blockListToHtml opts lst =
src/pandoc.hs+3−2
@@ -41,7 +41,7 @@ import System.Exit ( exitWith, ExitCode (..) )
4141import System.FilePath
4242import System.Console.GetOpt
4343import Data.Char ( toLower )
44−import Data.List ( intercalate, isSuffixOf )
44+import Data.List ( intercalate, isSuffixOf, isPrefixOf )
4545import System.Directory ( getAppUserDataDirectory, doesFileExist )
4646import System.IO ( stdout, stderr )
4747import qualified Text.Pandoc.UTF8 as UTF8
@@ -780,7 +780,8 @@ main = do
780780 writerIdentifierPrefix = idPrefix,
781781 writerSourceDirectory = sourceDir,
782782 writerUserDataDir = datadir,
783− writerHtml5 = html5 }
783+ writerHtml5 = html5 &&
784+ "html" `isPrefixOf` writerName' }
784785
785786 when (isNonTextOutput writerName' && outputFile == "-") $
786787 do UTF8.hPutStrLn stderr ("Error: Cannot write " ++ writerName ++ " output to stdout.\n" ++
templates/html.template+9−1
@@ -6,7 +6,6 @@ $else$
66<html xmlns="http://www.w3.org/1999/xhtml"$if(lang)$ lang="$lang$" xml:lang="$lang$"$endif$>
77$endif$
88<head>
9− <title>$if(title-prefix)$$title-prefix$ - $endif$$if(pagetitle)$$pagetitle$$endif$</title>
109$if(html5)$
1110 <meta charset="utf-8" />
1211$else$
@@ -18,6 +17,12 @@ $for(author)$
1817$endfor$
1918$if(date)$
2019 <meta name="date" content="$date$" />
20+$endif$
21+ <title>$if(title-prefix)$$title-prefix$ - $endif$$if(pagetitle)$$pagetitle$$endif$</title>
22+$if(html5)$
23+ <!--[if lt IE 9]>
24+ <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
25+ <![endif]-->
2126$endif$
2227$if(highlighting-css)$
2328 <style type="text/css">
@@ -28,8 +33,11 @@ $for(css)$
2833 <link rel="stylesheet" href="$css$" $if(html5)$$else$type="text/css" $endif$/>
2934$endfor$
3035$if(math)$
36+$if(html5)$
37+$else$
3138 $math$
3239$endif$
40+$endif$
3341$for(header-includes)$
3442 $header-includes$
3543$endfor$
templates/s5.template+1−1
@@ -1,7 +1,6 @@
11<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
22<html xmlns="http://www.w3.org/1999/xhtml">
33<head>
4− <title>$if(title-prefix)$$title-prefix$ - $endif$$if(pagetitle)$$pagetitle$$endif$</title>
54 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
65 <meta name="generator" content="pandoc" />
76$for(author)$
@@ -10,6 +9,7 @@ $endfor$
109$if(date)$
1110 <meta name="date" content="$date$" />
1211$endif$
12+ <title>$if(title-prefix)$$title-prefix$ - $endif$$if(pagetitle)$$pagetitle$$endif$</title>
1313 <!-- configuration parameters -->
1414 <meta name="defaultView" content="slideshow" />
1515 <meta name="controlVis" content="hidden" />
templates/slidy.template+1−1
@@ -3,7 +3,6 @@
33 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
44<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
55<head>
6− <title>$if(title-prefix)$$title-prefix$ - $endif$$if(pagetitle)$$pagetitle$$endif$</title>
76 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
87 <meta name="generator" content="pandoc" />
98$for(author)$
@@ -13,6 +12,7 @@ $if(date)$
1312 <meta name="date" content="$date$" />
1413$endif$
1514$if(highlighting-css)$
15+ <title>$if(title-prefix)$$title-prefix$ - $endif$$if(pagetitle)$$pagetitle$$endif$</title>
1616 <style type="text/css">
1717$highlighting-css$
1818 </style>
tests/s5.basic.html+1−1
@@ -1,12 +1,12 @@
11<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
22<html xmlns="http://www.w3.org/1999/xhtml">
33<head>
4− <title>My S5 Document</title>
54 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
65 <meta name="generator" content="pandoc" />
76 <meta name="author" content="Sam Smith" />
87 <meta name="author" content="Jen Jones" />
98 <meta name="date" content="July 15, 2006" />
9+ <title>My S5 Document</title>
1010 <!-- configuration parameters -->
1111 <meta name="defaultView" content="slideshow" />
1212 <meta name="controlVis" content="hidden" />
tests/s5.fancy.html+1−1
@@ -1,12 +1,12 @@
11<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
22<html xmlns="http://www.w3.org/1999/xhtml">
33<head>
4− <title>My S5 Document</title>
54 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
65 <meta name="generator" content="pandoc" />
76 <meta name="author" content="Sam Smith" />
87 <meta name="author" content="Jen Jones" />
98 <meta name="date" content="July 15, 2006" />
9+ <title>My S5 Document</title>
1010 <!-- configuration parameters -->
1111 <meta name="defaultView" content="slideshow" />
1212 <meta name="controlVis" content="hidden" />
tests/s5.inserts.html+1−1
@@ -1,12 +1,12 @@
11<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
22<html xmlns="http://www.w3.org/1999/xhtml">
33<head>
4− <title>My S5 Document</title>
54 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
65 <meta name="generator" content="pandoc" />
76 <meta name="author" content="Sam Smith" />
87 <meta name="author" content="Jen Jones" />
98 <meta name="date" content="July 15, 2006" />
9+ <title>My S5 Document</title>
1010 <link rel="stylesheet" href="main.css" type="text/css" />
1111 STUFF INSERTED
1212</head>
tests/writer.html+18−18
@@ -1,12 +1,12 @@
11<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
22<html xmlns="http://www.w3.org/1999/xhtml">
33<head>
4− <title>Pandoc Test Suite</title>
54 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
65 <meta name="generator" content="pandoc" />
76 <meta name="author" content="John MacFarlane" />
87 <meta name="author" content="Anonymous" />
98 <meta name="date" content="July 17, 2006" />
9+ <title>Pandoc Test Suite</title>
1010</head>
1111<body>
1212<h1 class="title">Pandoc Test Suite</h1>
@@ -74,7 +74,7 @@
7474 ></pre
7575 ><p
7676 >A list:</p
77− ><ol style="list-style-type: decimal;"
77+ ><ol style="list-style-type: decimal"
7878 ><li
7979 >item one</li
8080 ><li
@@ -207,7 +207,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
207207>Ordered</h2
208208><p
209209>Tight:</p
210−><ol style="list-style-type: decimal;"
210+><ol style="list-style-type: decimal"
211211><li
212212 >First</li
213213 ><li
@@ -217,7 +217,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
217217 ></ol
218218><p
219219>and:</p
220−><ol style="list-style-type: decimal;"
220+><ol style="list-style-type: decimal"
221221><li
222222 >One</li
223223 ><li
@@ -227,7 +227,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
227227 ></ol
228228><p
229229>Loose using tabs:</p
230−><ol style="list-style-type: decimal;"
230+><ol style="list-style-type: decimal"
231231><li
232232 ><p
233233 >First</p
@@ -243,7 +243,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
243243 ></ol
244244><p
245245>and using spaces:</p
246−><ol style="list-style-type: decimal;"
246+><ol style="list-style-type: decimal"
247247><li
248248 ><p
249249 >One</p
@@ -259,7 +259,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
259259 ></ol
260260><p
261261>Multiple paragraphs:</p
262−><ol style="list-style-type: decimal;"
262+><ol style="list-style-type: decimal"
263263><li
264264 ><p
265265 >Item 1, graf one.</p
@@ -291,7 +291,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
291291 ></ul
292292><p
293293>Here’s another:</p
294−><ol style="list-style-type: decimal;"
294+><ol style="list-style-type: decimal"
295295><li
296296 >First</li
297297 ><li
@@ -309,7 +309,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
309309 ></ol
310310><p
311311>Same thing but with paragraphs:</p
312−><ol style="list-style-type: decimal;"
312+><ol style="list-style-type: decimal"
313313><li
314314 ><p
315315 >First</p
@@ -355,7 +355,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
355355 ></ul
356356><h2 id="fancy-list-markers"
357357>Fancy list markers</h2
358−><ol start="2" style="list-style-type: decimal;"
358+><ol start="2" style="list-style-type: decimal"
359359><li
360360 >begins with 2</li
361361 ><li
@@ -363,11 +363,11 @@ These should not be escaped: \$ \\ \&gt; \[ \{
363363 >and now 3</p
364364 ><p
365365 >with a continuation</p
366− ><ol start="4" style="list-style-type: lower-roman;"
366+ ><ol start="4" style="list-style-type: lower-roman"
367367 ><li
368368 >sublist with roman numerals, starting with 4</li
369369 ><li
370− >more items<ol style="list-style-type: upper-alpha;"
370+ >more items<ol style="list-style-type: upper-alpha"
371371 ><li
372372 >a subsublist</li
373373 ><li
@@ -379,13 +379,13 @@ These should not be escaped: \$ \\ \&gt; \[ \{
379379 ></ol
380380><p
381381>Nesting:</p
382−><ol style="list-style-type: upper-alpha;"
382+><ol style="list-style-type: upper-alpha"
383383><li
384− >Upper Alpha<ol style="list-style-type: upper-roman;"
384+ >Upper Alpha<ol style="list-style-type: upper-roman"
385385 ><li
386− >Upper Roman.<ol start="6" style="list-style-type: decimal;"
386+ >Upper Roman.<ol start="6" style="list-style-type: decimal"
387387 ><li
388− >Decimal start with 6<ol start="3" style="list-style-type: lower-alpha;"
388+ >Decimal start with 6<ol start="3" style="list-style-type: lower-alpha"
389389 ><li
390390 >Lower alpha with paren</li
391391 ></ol
@@ -559,7 +559,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
559559 ><dd
560560 ><p
561561 >orange fruit</p
562− ><ol style="list-style-type: decimal;"
562+ ><ol style="list-style-type: decimal"
563563 ><li
564564 >sublist</li
565565 ><li
@@ -1110,7 +1110,7 @@ document.write('<a h'+'ref'+'="ma'+'ilto'+':'+e+'">'+'<code>'+e+'</code>'+'<\/'+
11101110 ></sup
11111111 ></p
11121112 ></blockquote
1113−><ol style="list-style-type: decimal;"
1113+><ol style="list-style-type: decimal"
11141114><li
11151115 >And in list items.<sup
11161116 ><a href="#fn5" class="footnoteRef" id="fnref5"