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$ $endif$ - $if(title-prefix)$$title-prefix$ - $endif$$if(pagetitle)$$pagetitle$$endif$ $if(html5)$ $else$ @@ -18,6 +17,12 @@ $for(author)$ $endfor$ $if(date)$ +$endif$ + $if(title-prefix)$$title-prefix$ - $endif$$if(pagetitle)$$pagetitle$$endif$ +$if(html5)$ + $endif$ $if(highlighting-css)$ 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 @@ - My S5 Document + My S5 Document 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 @@ - My S5 Document + My S5 Document 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 @@ - My S5 Document + My S5 Document STUFF INSERTED 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 @@ - Pandoc Test Suite + Pandoc Test Suite

Pandoc Test Suite

@@ -74,7 +74,7 @@ >

A list:

    1. item one
    2. Ordered

      Tight:

        1. First

        and:

          1. One

          Loose using tabs:

            1. First

            and using spaces:

              1. One

              Multiple paragraphs:

                1. Item 1, graf one.

                  Here’s another:

                    1. First

                    Same thing but with paragraphs:

                      1. First

                        Fancy list markers

                          1. begins with 2
                          2. and now 3

                            with a continuation

                              1. sublist with roman numerals, starting with 4
                              2. more items
                                  more items
                                  1. a subsublist

                                  Nesting:

                                    1. Upper Alpha
                                        Upper Alpha
                                        1. Upper Roman.
                                            Upper Roman.
                                            1. Decimal start with 6
                                                Decimal start with 6
                                                1. Lower alpha with paren

                                                orange fruit

                                                  1. sublist
                                                  2. '+''+e+''+'<\/'+ >

                                                      1. And in list items.