HTML writer: Support header attributes.
Note: The attributes go on the enclosing section or div if `--section-divs` is specified. Also fixed a regression (only now noticed) in html+lhs output. Previously the bird tracks were being omitted.
This commit is contained in:
parent
cdee226586
commit
90f0dd15b6
4 changed files with 29 additions and 26 deletions
|
@ -250,9 +250,10 @@ showSecNum = concat . intersperse "." . map show
|
||||||
-- | Converts an Element to a list item for a table of contents,
|
-- | Converts an Element to a list item for a table of contents,
|
||||||
-- retrieving the appropriate identifier from state.
|
-- retrieving the appropriate identifier from state.
|
||||||
elementToListItem :: WriterOptions -> Element -> State WriterState (Maybe Html)
|
elementToListItem :: WriterOptions -> Element -> State WriterState (Maybe Html)
|
||||||
elementToListItem opts (Sec lev num (id',classes,keyvals) headerText subsecs)
|
elementToListItem opts (Sec lev num (id',classes,_) headerText subsecs)
|
||||||
| lev <= writerTOCDepth opts = do
|
| lev <= writerTOCDepth opts = do
|
||||||
let sectnum = if writerNumberSections opts && not (null num)
|
let sectnum = if writerNumberSections opts && not (null num) &&
|
||||||
|
"unnumbered" `notElem` classes
|
||||||
then (H.span ! A.class_ "toc-section-number"
|
then (H.span ! A.class_ "toc-section-number"
|
||||||
$ toHtml $ showSecNum num) >> preEscapedString " "
|
$ toHtml $ showSecNum num) >> preEscapedString " "
|
||||||
else mempty
|
else mempty
|
||||||
|
@ -287,22 +288,24 @@ elementToHtml slideLevel opts (Sec level num (id',classes,keyvals) title' elemen
|
||||||
-- title slides have no content of their own
|
-- title slides have no content of their own
|
||||||
then filter isSec elements
|
then filter isSec elements
|
||||||
else elements
|
else elements
|
||||||
let header'' = if (writerSectionDivs opts ||
|
|
||||||
writerSlideVariant opts == S5Slides ||
|
|
||||||
slide)
|
|
||||||
then header'
|
|
||||||
else header' ! prefixedId opts id'
|
|
||||||
let inNl x = mconcat $ nl opts : intersperse (nl opts) x ++ [nl opts]
|
let inNl x = mconcat $ nl opts : intersperse (nl opts) x ++ [nl opts]
|
||||||
let classes = ["titleslide" | titleSlide] ++ ["slide" | slide] ++
|
let classes' = ["titleslide" | titleSlide] ++ ["slide" | slide] ++
|
||||||
["level" ++ show level]
|
["section" | (slide || writerSectionDivs opts) &&
|
||||||
|
not (writerHtml5 opts) ] ++
|
||||||
|
["level" ++ show level | slide || writerSectionDivs opts ]
|
||||||
|
++ classes
|
||||||
let secttag = if writerHtml5 opts
|
let secttag = if writerHtml5 opts
|
||||||
then H5.section ! A.class_ (toValue $ unwords classes)
|
then H5.section
|
||||||
else H.div ! A.class_ (toValue $ unwords ("section":classes))
|
else H.div
|
||||||
|
let attr = (id',classes',keyvals)
|
||||||
return $ if titleSlide
|
return $ if titleSlide
|
||||||
then mconcat $ (secttag ! prefixedId opts id' $ header'') : innerContents
|
then mconcat $
|
||||||
|
(addAttrs opts attr $ secttag $ header') : innerContents
|
||||||
else if writerSectionDivs opts || slide
|
else if writerSectionDivs opts || slide
|
||||||
then secttag ! prefixedId opts id' $ inNl $ header'' : innerContents
|
then addAttrs opts attr
|
||||||
else mconcat $ intersperse (nl opts) $ header'' : innerContents
|
$ secttag $ inNl $ header' : innerContents
|
||||||
|
else mconcat $ intersperse (nl opts)
|
||||||
|
$ addAttrs opts attr header' : innerContents
|
||||||
|
|
||||||
-- | Convert list of Note blocks to a footnote <div>.
|
-- | Convert list of Note blocks to a footnote <div>.
|
||||||
-- Assumes notes are sorted.
|
-- Assumes notes are sorted.
|
||||||
|
@ -376,8 +379,8 @@ addAttrs opts attr h = foldl (!) h (attrsToHtml opts attr)
|
||||||
|
|
||||||
attrsToHtml :: WriterOptions -> Attr -> [Attribute]
|
attrsToHtml :: WriterOptions -> Attr -> [Attribute]
|
||||||
attrsToHtml opts (id',classes',keyvals) =
|
attrsToHtml opts (id',classes',keyvals) =
|
||||||
[A.class_ (toValue $ unwords classes') | not (null classes')] ++
|
|
||||||
[prefixedId opts id' | not (null id')] ++
|
[prefixedId opts id' | not (null id')] ++
|
||||||
|
[A.class_ (toValue $ unwords classes') | not (null classes')] ++
|
||||||
map (\(x,y) -> customAttribute (fromString x) (toValue y)) keyvals
|
map (\(x,y) -> customAttribute (fromString x) (toValue y)) keyvals
|
||||||
|
|
||||||
imageExts :: [String]
|
imageExts :: [String]
|
||||||
|
@ -423,11 +426,11 @@ blockToHtml opts (CodeBlock (id',classes,keyvals) rawCode) = do
|
||||||
then map (\c -> if map toLower c == "haskell"
|
then map (\c -> if map toLower c == "haskell"
|
||||||
then "literatehaskell"
|
then "literatehaskell"
|
||||||
else c) classes
|
else c) classes
|
||||||
else filter (/= "literate") classes
|
else classes
|
||||||
adjCode = if tolhs
|
adjCode = if tolhs
|
||||||
then unlines . map ("> " ++) . lines $ rawCode
|
then unlines . map ("> " ++) . lines $ rawCode
|
||||||
else rawCode
|
else rawCode
|
||||||
case highlight formatHtmlBlock (id',classes,keyvals) adjCode of
|
case highlight formatHtmlBlock (id',classes',keyvals) adjCode of
|
||||||
Nothing -> return $ addAttrs opts (id',classes,keyvals)
|
Nothing -> return $ addAttrs opts (id',classes,keyvals)
|
||||||
$ H.pre $ H.code $ toHtml adjCode
|
$ H.pre $ H.code $ toHtml adjCode
|
||||||
Just h -> modify (\st -> st{ stHighlighting = True }) >>
|
Just h -> modify (\st -> st{ stHighlighting = True }) >>
|
||||||
|
@ -461,14 +464,14 @@ blockToHtml opts (Header level (ident,_,_) lst) = do
|
||||||
then H.a ! A.href (toValue $
|
then H.a ! A.href (toValue $
|
||||||
'#' : writerIdentifierPrefix opts ++ ident) $ contents'
|
'#' : writerIdentifierPrefix opts ++ ident) $ contents'
|
||||||
else contents'
|
else contents'
|
||||||
return $ (case level of
|
return $ case level of
|
||||||
1 -> H.h1 contents''
|
1 -> H.h1 contents''
|
||||||
2 -> H.h2 contents''
|
2 -> H.h2 contents''
|
||||||
3 -> H.h3 contents''
|
3 -> H.h3 contents''
|
||||||
4 -> H.h4 contents''
|
4 -> H.h4 contents''
|
||||||
5 -> H.h5 contents''
|
5 -> H.h5 contents''
|
||||||
6 -> H.h6 contents''
|
6 -> H.h6 contents''
|
||||||
_ -> H.p contents'')
|
_ -> H.p contents''
|
||||||
blockToHtml opts (BulletList lst) = do
|
blockToHtml opts (BulletList lst) = do
|
||||||
contents <- mapM (blockListToHtml opts) lst
|
contents <- mapM (blockListToHtml opts) lst
|
||||||
let lst' = unordList opts contents
|
let lst' = unordList opts contents
|
||||||
|
|
|
@ -29,9 +29,9 @@ code > span.er { color: #ff0000; font-weight: bold; }
|
||||||
<body>
|
<body>
|
||||||
<h1>lhs test</h1>
|
<h1>lhs test</h1>
|
||||||
<p><code>unsplit</code> is an arrow that takes a pair of values and combines them to return a single value:</p>
|
<p><code>unsplit</code> is an arrow that takes a pair of values and combines them to return a single value:</p>
|
||||||
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="fu">></span><span class="ot"> unsplit ::</span> (<span class="dt">Arrow</span> a) <span class="ot">=></span> (b <span class="ot">-></span> c <span class="ot">-></span> d) <span class="ot">-></span> a (b, c) d
|
<pre class="sourceCode literate literatehaskell"><code class="sourceCode literatehaskell"><span class="ot">> unsplit ::</span> (<span class="dt">Arrow</span> a) <span class="ot">=></span> (b <span class="ot">-></span> c <span class="ot">-></span> d) <span class="ot">-></span> a (b, c) d
|
||||||
<span class="fu">></span> unsplit <span class="fu">=</span> arr <span class="fu">.</span> <span class="fu">uncurry</span>
|
<span class="ot">></span> unsplit <span class="fu">=</span> arr <span class="fu">.</span> <span class="fu">uncurry</span>
|
||||||
<span class="fu">></span> <span class="co">-- arr (\op (x,y) -> x `op` y)</span></code></pre>
|
<span class="ot">></span> <span class="co">-- arr (\op (x,y) -> x `op` y)</span></code></pre>
|
||||||
<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>
|
<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>
|
||||||
<pre><code>f *** g = first f >>> second g</code></pre>
|
<pre><code>f *** g = first f >>> second g</code></pre>
|
||||||
<p>Block quote:</p>
|
<p>Block quote:</p>
|
||||||
|
|
|
@ -36,14 +36,14 @@
|
||||||
<h2>Sam Smith<br/>Jen Jones</h2>
|
<h2>Sam Smith<br/>Jen Jones</h2>
|
||||||
<h3>July 15, 2006</h3>
|
<h3>July 15, 2006</h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="section slide level1" id="first-slide">
|
<div id="first-slide" class="slide section level1">
|
||||||
<h1>First slide</h1>
|
<h1>First slide</h1>
|
||||||
<ul>
|
<ul>
|
||||||
<li>first bullet</li>
|
<li>first bullet</li>
|
||||||
<li>second bullet</li>
|
<li>second bullet</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div class="section slide level1" id="math">
|
<div id="math" class="slide section level1">
|
||||||
<h1>Math</h1>
|
<h1>Math</h1>
|
||||||
<ul>
|
<ul>
|
||||||
<li><span class="math">$\frac{d}{dx}f(x)=\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}$</span></li>
|
<li><span class="math">$\frac{d}{dx}f(x)=\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}$</span></li>
|
||||||
|
|
|
@ -237,14 +237,14 @@
|
||||||
<h2>Sam Smith<br/>Jen Jones</h2>
|
<h2>Sam Smith<br/>Jen Jones</h2>
|
||||||
<h3>July 15, 2006</h3>
|
<h3>July 15, 2006</h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="section slide level1" id="first-slide">
|
<div id="first-slide" class="slide section level1">
|
||||||
<h1>First slide</h1>
|
<h1>First slide</h1>
|
||||||
<ul class="incremental">
|
<ul class="incremental">
|
||||||
<li>first bullet</li>
|
<li>first bullet</li>
|
||||||
<li>second bullet</li>
|
<li>second bullet</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div class="section slide level1" id="math">
|
<div id="math" class="slide section level1">
|
||||||
<h1>Math</h1>
|
<h1>Math</h1>
|
||||||
<ul class="incremental">
|
<ul class="incremental">
|
||||||
<li><span class="LaTeX">$\frac{d}{dx}f(x)=\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}$</span></li>
|
<li><span class="LaTeX">$\frac{d}{dx}f(x)=\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}$</span></li>
|
||||||
|
|
Loading…
Reference in a new issue