@@ -170,6 +170,7 @@ inTemplate opts tit auths date toc body' newvars =
170 , ("pagetitle", topTitle')
170 , ("pagetitle", topTitle')
171 , ("title", renderHtmlFragment tit)
171 , ("title", renderHtmlFragment tit)
172 , ("date", date') ] ++
172 , ("date", date') ] ++
173+ [ ("html5","true") | writerHtml5 opts ] ++
173 (case toc of
174 (case toc of
174 Just t -> [ ("toc", renderHtmlFragment t)]
175 Just t -> [ ("toc", renderHtmlFragment t)]
175 Nothing -> []) ++
176 Nothing -> []) ++
@@ -189,7 +190,12 @@ tableOfContents opts sects = do
189 let tocList = catMaybes contents
190 let tocList = catMaybes contents
190 return $ if null tocList
191 return $ if null tocList
191 then Nothing
192 then Nothing
195+ then tag "nav" ! [prefixedId opts' "TOC"] $
192− else Just $ thediv ! [prefixedId opts' "TOC"] $ unordList tocList
197+ else thediv ! [prefixedId opts' "TOC"] $
194-- | Convert section number to string
200-- | Convert section number to string
195showSecNum :: [Int] -> String
201showSecNum :: [Int] -> String
@@ -226,7 +232,9 @@ elementToHtml opts (Sec level num id' title' elements) = do
226 return $ if slides -- S5 gets confused by the extra divs around sections
232 return $ if slides -- S5 gets confused by the extra divs around sections
227 then toHtmlFromList stuff
233 then toHtmlFromList stuff
228 else if writerSectionDivs opts
234 else if writerSectionDivs opts
235+ then if writerHtml5 opts
236+ then tag "section" << stuff
229− then thediv ! [prefixedId opts id'] << stuff
237+ else thediv ! [prefixedId opts id'] << stuff
230 else toHtmlFromList stuff
238 else toHtmlFromList stuff
232-- | Convert list of Note blocks to a footnote <div>.
240-- | Convert list of Note blocks to a footnote <div>.
@@ -296,8 +304,11 @@ blockToHtml opts (Plain lst) = inlineListToHtml opts lst
296blockToHtml opts (Para [Image txt (s,tit)]) = do
304blockToHtml opts (Para [Image txt (s,tit)]) = do
297 img <- inlineToHtml opts (Image txt (s,tit))
305 img <- inlineToHtml opts (Image txt (s,tit))
298 capt <- inlineListToHtml opts txt
306 capt <- inlineListToHtml opts txt
307+ return $ if writerHtml5 opts
308+ then tag "figure" <<
309+ [img, tag "figcaption" << capt]
299− return $ thediv ! [theclass "figure"] <<
310+ else thediv ! [theclass "figure"] <<
300− [img, paragraph ! [theclass "caption"] << capt]
311+ [img, paragraph ! [theclass "caption"] << capt]
301blockToHtml opts (Para lst) = inlineListToHtml opts lst >>= (return . paragraph)
312blockToHtml opts (Para lst) = inlineListToHtml opts lst >>= (return . paragraph)
302blockToHtml _ (RawHtml str) = return $ primHtml str
313blockToHtml _ (RawHtml str) = return $ primHtml str
303blockToHtml _ (HorizontalRule) = return $ hr
314blockToHtml _ (HorizontalRule) = return $ hr
@@ -368,7 +379,17 @@ blockToHtml opts (OrderedList (startnum, numstyle, _) lst) = do
368 then [start startnum]
379 then [start startnum]
369 else []) ++
380 else []) ++
370 (if numstyle /= DefaultStyle
381 (if numstyle /= DefaultStyle
382+ then if writerHtml5 opts
383+ then [strAttr "type" $
371− then [thestyle $ "list-style-type: " ++ numstyle' ++ ";"]
391+ else [thestyle $ "list-style-type: " ++
373 return $ ordList ! attribs $ contents
394 return $ ordList ! attribs $ contents
374blockToHtml opts (DefinitionList lst) = do
395blockToHtml opts (DefinitionList lst) = do
@@ -381,28 +402,30 @@ blockToHtml opts (DefinitionList lst) = do
382 return $ dlist ! attribs << concat contents
403 return $ dlist ! attribs << concat contents
383blockToHtml opts (Table capt aligns widths headers rows') = do
404blockToHtml opts (Table capt aligns widths headers rows') = do
384− let alignStrings = map alignmentToString aligns
385 captionDoc <- if null capt
405 captionDoc <- if null capt
386 then return noHtml
406 then return noHtml
387 else inlineListToHtml opts capt >>= return . caption
407 else inlineListToHtml opts capt >>= return . caption
388 let percent w = show (truncate (100*w) :: Integer) ++ "%"
408 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]
389 let coltags = if all (== 0.0) widths
412 let coltags = if all (== 0.0) widths
390 then noHtml
413 then noHtml
391 else concatHtml $ map
414 else concatHtml $ map
392− (\w -> col ! [width $ percent w] $ noHtml) widths
415+ (\w -> col ! (widthAttrs w) $ noHtml) widths
393 head' <- if all null headers
416 head' <- if all null headers
394 then return noHtml
417 then return noHtml
395− else liftM (thead <<) $ tableRowToHtml opts alignStrings 0 headers
418+ else liftM (thead <<) $ tableRowToHtml opts aligns 0 headers
396 body' <- liftM (tbody <<) $
419 body' <- liftM (tbody <<) $
397− zipWithM (tableRowToHtml opts alignStrings) [1..] rows'
420+ zipWithM (tableRowToHtml opts aligns) [1..] rows'
398 return $ table $ captionDoc +++ coltags +++ head' +++ body'
421 return $ table $ captionDoc +++ coltags +++ head' +++ body'
400tableRowToHtml :: WriterOptions
423tableRowToHtml :: WriterOptions
401− -> [String]
424+ -> [Alignment]
403 -> [[Block]]
426 -> [[Block]]
404 -> State WriterState Html
427 -> State WriterState Html
405−tableRowToHtml opts alignStrings rownum cols' = do
428+tableRowToHtml opts aligns rownum cols' = do
406 let mkcell = if rownum == 0 then th else td
429 let mkcell = if rownum == 0 then th else td
407 let rowclass = case rownum of
430 let rowclass = case rownum of
408 0 -> "header"
431 0 -> "header"
@@ -410,7 +433,7 @@ tableRowToHtml opts alignStrings rownum cols' = do
410 _ -> "even"
433 _ -> "even"
411 cols'' <- sequence $ zipWith
434 cols'' <- sequence $ zipWith
412 (\alignment item -> tableItemToHtml opts mkcell alignment item)
435 (\alignment item -> tableItemToHtml opts mkcell alignment item)
413− alignStrings cols'
436+ aligns cols'
414 return $ tr ! [theclass rowclass] $ toHtmlFromList cols''
437 return $ tr ! [theclass rowclass] $ toHtmlFromList cols''
416alignmentToString :: Alignment -> [Char]
439alignmentToString :: Alignment -> [Char]
@@ -422,12 +445,15 @@ alignmentToString alignment = case alignment of
423tableItemToHtml :: WriterOptions
446tableItemToHtml :: WriterOptions
424 -> (Html -> Html)
447 -> (Html -> Html)
425− -> [Char]
448+ -> Alignment
426 -> [Block]
449 -> [Block]
427 -> State WriterState Html
450 -> State WriterState Html
428tableItemToHtml opts tag' align' item = do
451tableItemToHtml opts tag' align' item = do
429 contents <- blockListToHtml opts item
452 contents <- blockListToHtml opts item
453+ let alignAttrs = if writerHtml5 opts
454+ then [thestyle $ "align: " ++ alignmentToString align']
455+ else [align $ alignmentToString align']
430− return $ tag' ! [align align'] $ contents
456+ return $ tag' ! alignAttrs $ contents
432blockListToHtml :: WriterOptions -> [Block] -> State WriterState Html
458blockListToHtml :: WriterOptions -> [Block] -> State WriterState Html
433blockListToHtml opts lst =
459blockListToHtml opts lst =