git.iko.soy/typeable/pandoc
on master help sign in
HTML writer: Support header attributes.
90f0dd1John MacFarlane
src/Text/Pandoc/Writers/HTML.hs+22−19
@@ -250,9 +250,10 @@ showSecNum = concat . intersperse "." . map show
250-- | Converts an Element to a list item for a table of contents,
250-- | Converts an Element to a list item for a table of contents,
251-- retrieving the appropriate identifier from state.
251-- retrieving the appropriate identifier from state.
252elementToListItem :: WriterOptions -> Element -> State WriterState (Maybe Html)
252elementToListItem :: WriterOptions -> Element -> State WriterState (Maybe Html)
253−elementToListItem opts (Sec lev num (id',classes,keyvals) headerText subsecs)
253+elementToListItem opts (Sec lev num (id',classes,_) headerText subsecs)
254 | lev <= writerTOCDepth opts = do
254 | lev <= writerTOCDepth opts = do
255− let sectnum = if writerNumberSections opts && not (null num)
255+ let sectnum = if writerNumberSections opts && not (null num) &&
256+ "unnumbered" `notElem` classes
256 then (H.span ! A.class_ "toc-section-number"
257 then (H.span ! A.class_ "toc-section-number"
257 $ toHtml $ showSecNum num) >> preEscapedString " "
258 $ toHtml $ showSecNum num) >> preEscapedString " "
258 else mempty
259 else mempty
@@ -287,22 +288,24 @@ elementToHtml slideLevel opts (Sec level num (id',classes,keyvals) title' elemen
287 -- title slides have no content of their own
288 -- title slides have no content of their own
288 then filter isSec elements
289 then filter isSec elements
289 else elements
290 else elements
290− let header'' = if (writerSectionDivs opts ||
291− writerSlideVariant opts == S5Slides ||
292− slide)
293− then header'
294− else header' ! prefixedId opts id'
295 let inNl x = mconcat $ nl opts : intersperse (nl opts) x ++ [nl opts]
291 let inNl x = mconcat $ nl opts : intersperse (nl opts) x ++ [nl opts]
296− let classes = ["titleslide" | titleSlide] ++ ["slide" | slide] ++
292+ let classes' = ["titleslide" | titleSlide] ++ ["slide" | slide] ++
293+ ["section" | (slide || writerSectionDivs opts) &&
294+ not (writerHtml5 opts) ] ++
297− ["level" ++ show level]
295+ ["level" ++ show level | slide || writerSectionDivs opts ]
296+ ++ classes
298 let secttag = if writerHtml5 opts
297 let secttag = if writerHtml5 opts
299− then H5.section ! A.class_ (toValue $ unwords classes)
298+ then H5.section
300− else H.div ! A.class_ (toValue $ unwords ("section":classes))
299+ else H.div
300+ let attr = (id',classes',keyvals)
301 return $ if titleSlide
301 return $ if titleSlide
302+ then mconcat $
302− then mconcat $ (secttag ! prefixedId opts id' $ header'') : innerContents
303+ (addAttrs opts attr $ secttag $ header') : innerContents
303 else if writerSectionDivs opts || slide
304 else if writerSectionDivs opts || slide
305+ then addAttrs opts attr
304− then secttag ! prefixedId opts id' $ inNl $ header'' : innerContents
306+ $ secttag $ inNl $ header' : innerContents
305− else mconcat $ intersperse (nl opts) $ header'' : innerContents
307+ else mconcat $ intersperse (nl opts)
308+ $ addAttrs opts attr header' : innerContents
306
309
307-- | Convert list of Note blocks to a footnote <div>.
310-- | Convert list of Note blocks to a footnote <div>.
308-- Assumes notes are sorted.
311-- Assumes notes are sorted.
@@ -376,8 +379,8 @@ addAttrs opts attr h = foldl (!) h (attrsToHtml opts attr)
376
379
377attrsToHtml :: WriterOptions -> Attr -> [Attribute]
380attrsToHtml :: WriterOptions -> Attr -> [Attribute]
378attrsToHtml opts (id',classes',keyvals) =
381attrsToHtml opts (id',classes',keyvals) =
379− [A.class_ (toValue $ unwords classes') | not (null classes')] ++
380 [prefixedId opts id' | not (null id')] ++
382 [prefixedId opts id' | not (null id')] ++
383+ [A.class_ (toValue $ unwords classes') | not (null classes')] ++
381 map (\(x,y) -> customAttribute (fromString x) (toValue y)) keyvals
384 map (\(x,y) -> customAttribute (fromString x) (toValue y)) keyvals
382
385
383imageExts :: [String]
386imageExts :: [String]
@@ -423,11 +426,11 @@ blockToHtml opts (CodeBlock (id',classes,keyvals) rawCode) = do
423 then map (\c -> if map toLower c == "haskell"
426 then map (\c -> if map toLower c == "haskell"
424 then "literatehaskell"
427 then "literatehaskell"
425 else c) classes
428 else c) classes
426− else filter (/= "literate") classes
429+ else classes
427 adjCode = if tolhs
430 adjCode = if tolhs
428 then unlines . map ("> " ++) . lines $ rawCode
431 then unlines . map ("> " ++) . lines $ rawCode
429 else rawCode
432 else rawCode
430− case highlight formatHtmlBlock (id',classes,keyvals) adjCode of
433+ case highlight formatHtmlBlock (id',classes',keyvals) adjCode of
431 Nothing -> return $ addAttrs opts (id',classes,keyvals)
434 Nothing -> return $ addAttrs opts (id',classes,keyvals)
432 $ H.pre $ H.code $ toHtml adjCode
435 $ H.pre $ H.code $ toHtml adjCode
433 Just h -> modify (\st -> st{ stHighlighting = True }) >>
436 Just h -> modify (\st -> st{ stHighlighting = True }) >>
@@ -461,14 +464,14 @@ blockToHtml opts (Header level (ident,_,_) lst) = do
461 then H.a ! A.href (toValue $
464 then H.a ! A.href (toValue $
462 '#' : writerIdentifierPrefix opts ++ ident) $ contents'
465 '#' : writerIdentifierPrefix opts ++ ident) $ contents'
463 else contents'
466 else contents'
464− return $ (case level of
467+ return $ case level of
465 1 -> H.h1 contents''
468 1 -> H.h1 contents''
466 2 -> H.h2 contents''
469 2 -> H.h2 contents''
467 3 -> H.h3 contents''
470 3 -> H.h3 contents''
468 4 -> H.h4 contents''
471 4 -> H.h4 contents''
469 5 -> H.h5 contents''
472 5 -> H.h5 contents''
470 6 -> H.h6 contents''
473 6 -> H.h6 contents''
471− _ -> H.p contents'')
474+ _ -> H.p contents''
472blockToHtml opts (BulletList lst) = do
475blockToHtml opts (BulletList lst) = do
473 contents <- mapM (blockListToHtml opts) lst
476 contents <- mapM (blockListToHtml opts) lst
474 let lst' = unordList opts contents
477 let lst' = unordList opts contents
tests/lhs-test.html+lhs+3−3
@@ -29,9 +29,9 @@ code > span.er { color: #ff0000; font-weight: bold; }
29<body>
29<body>
30<h1>lhs test</h1>
30<h1>lhs test</h1>
31<p><code>unsplit</code> is an arrow that takes a pair of values and combines them to return a single value:</p>
31<p><code>unsplit</code> is an arrow that takes a pair of values and combines them to return a single value:</p>
32−<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="fu">&gt;</span><span class="ot"> unsplit ::</span> (<span class="dt">Arrow</span> a) <span class="ot">=&gt;</span> (b <span class="ot">-&gt;</span> c <span class="ot">-&gt;</span> d) <span class="ot">-&gt;</span> a (b, c) d
32+<pre class="sourceCode literate literatehaskell"><code class="sourceCode literatehaskell"><span class="ot">&gt; unsplit ::</span> (<span class="dt">Arrow</span> a) <span class="ot">=&gt;</span> (b <span class="ot">-&gt;</span> c <span class="ot">-&gt;</span> d) <span class="ot">-&gt;</span> a (b, c) d
33−<span class="fu">&gt;</span> unsplit <span class="fu">=</span> arr <span class="fu">.</span> <span class="fu">uncurry</span>
33+<span class="ot">&gt;</span> unsplit <span class="fu">=</span> arr <span class="fu">.</span> <span class="fu">uncurry</span>
34−<span class="fu">&gt;</span> <span class="co">-- arr (\op (x,y) -&gt; x `op` y)</span></code></pre>
34+<span class="ot">&gt;</span> <span class="co">-- arr (\op (x,y) -&gt; x `op` y)</span></code></pre>
35<p><code>(***)</code> combines two arrows into a new arrow by running the two arrows on a pair of values (one arrow on the first item of the pair and one arrow on the second item of the pair).</p>
35<p><code>(***)</code> combines two arrows into a new arrow by running the two arrows on a pair of values (one arrow on the first item of the pair and one arrow on the second item of the pair).</p>
36<pre><code>f *** g = first f &gt;&gt;&gt; second g</code></pre>
36<pre><code>f *** g = first f &gt;&gt;&gt; second g</code></pre>
37<p>Block quote:</p>
37<p>Block quote:</p>
tests/s5.basic.html+2−2
@@ -36,14 +36,14 @@
36 <h2>Sam Smith<br/>Jen Jones</h2>
36 <h2>Sam Smith<br/>Jen Jones</h2>
37 <h3>July 15, 2006</h3>
37 <h3>July 15, 2006</h3>
38</div>
38</div>
39−<div class="section slide level1" id="first-slide">
39+<div id="first-slide" class="slide section level1">
40<h1>First slide</h1>
40<h1>First slide</h1>
41<ul>
41<ul>
42<li>first bullet</li>
42<li>first bullet</li>
43<li>second bullet</li>
43<li>second bullet</li>
44</ul>
44</ul>
45</div>
45</div>
46−<div class="section slide level1" id="math">
46+<div id="math" class="slide section level1">
47<h1>Math</h1>
47<h1>Math</h1>
48<ul>
48<ul>
49<li><span class="math">$\frac{d}{dx}f(x)=\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}$</span></li>
49<li><span class="math">$\frac{d}{dx}f(x)=\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}$</span></li>
tests/s5.fancy.html+2−2
@@ -237,14 +237,14 @@
237 <h2>Sam Smith<br/>Jen Jones</h2>
237 <h2>Sam Smith<br/>Jen Jones</h2>
238 <h3>July 15, 2006</h3>
238 <h3>July 15, 2006</h3>
239</div>
239</div>
240−<div class="section slide level1" id="first-slide">
240+<div id="first-slide" class="slide section level1">
241<h1>First slide</h1>
241<h1>First slide</h1>
242<ul class="incremental">
242<ul class="incremental">
243<li>first bullet</li>
243<li>first bullet</li>
244<li>second bullet</li>
244<li>second bullet</li>
245</ul>
245</ul>
246</div>
246</div>
247−<div class="section slide level1" id="math">
247+<div id="math" class="slide section level1">
248<h1>Math</h1>
248<h1>Math</h1>
249<ul class="incremental">
249<ul class="incremental">
250<li><span class="LaTeX">$\frac{d}{dx}f(x)=\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}$</span></li>
250<li><span class="LaTeX">$\frac{d}{dx}f(x)=\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}$</span></li>