git.iko.soy/typeable/pandoc
on master help sign in
Preserve attributes in highlighted HTML.

The container element will have the classes, id, and key-value attributes you specified in the delimited code block. Previously these were stripped off.

commit012405e8c3df0ce400b05f524d14de88cf5d5115 authorJohn MacFarlane <fiddlosopher@gmail.com> dateWed 28 Dec 2011, 22:04 (15 years ago) parent4fd9fb9
4 files changed+8−5
src/Text/Pandoc/Highlighting.hs+2−1 src/Text/Pandoc/Writers/HTML.hs+4−2 tests/lhs-test.html+1−1 tests/lhs-test.html+lhs+1−1
src/Text/Pandoc/Highlighting.hs+2−1
@@ -70,6 +70,7 @@ highlight formatter (_, classes, keyvals) rawCode =
7070 in case find (`elem` lcLanguages) lcclasses of
7171 Nothing -> Nothing
7272 Just language -> Just
73− $ formatter fmtOpts{ codeClasses = [language] }
73+ $ formatter fmtOpts{ codeClasses = [language],
74+ containerClasses = classes }
7475 $ highlightAs language rawCode
7576
src/Text/Pandoc/Writers/HTML.hs+4−2
@@ -379,7 +379,7 @@ blockToHtml opts (CodeBlock (id',classes,keyvals) rawCode) = do
379379 in return $ foldl (!) H.pre attrs $ H.code
380380 $ toHtml adjCode
381381 Just h -> modify (\st -> st{ stHighlighting = True }) >>
382− return h
382+ return (foldl (!) h (attrsToHtml opts (id',[],keyvals)))
383383blockToHtml opts (BlockQuote blocks) =
384384 -- in S5, treat list in blockquote specially
385385 -- if default is incremental, make it nonincremental;
@@ -547,7 +547,9 @@ inlineToHtml opts inline =
547547 Nothing -> return
548548 $ foldl (!) H.code (attrsToHtml opts attr)
549549 $ strToHtml str
550− Just h -> return h
550+ Just h -> return $ foldl (!) h $
551+ attrsToHtml opts (id',[],keyvals)
552+ where (id',_,keyvals) = attr
551553 (Strikeout lst) -> inlineListToHtml opts lst >>=
552554 return . H.del
553555 (SmallCaps lst) -> inlineListToHtml opts lst >>=
tests/lhs-test.html+1−1
@@ -27,7 +27,7 @@ code > span.er { color: #ff0000; font-weight: bold; }
2727<body>
2828<h1 id="lhs-test">lhs test</h1>
2929<p><code>unsplit</code> is an arrow that takes a pair of values and combines them to return a single value:</p>
30−<pre class="sourceCode"><code class="sourceCode haskell"><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
30+<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><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
3131unsplit <span class="fu">=</span> arr <span class="fu">.</span> <span class="fu">uncurry</span>
3232 <span class="co">-- arr (\op (x,y) -&gt; x `op` y) </span></code></pre>
3333<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>
tests/lhs-test.html+lhs+1−1
@@ -27,7 +27,7 @@ code > span.er { color: #ff0000; font-weight: bold; }
2727<body>
2828<h1 id="lhs-test">lhs test</h1>
2929<p><code>unsplit</code> is an arrow that takes a pair of values and combines them to return a single value:</p>
30−<pre class="sourceCode"><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
30+<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
3131<span class="fu">&gt;</span> unsplit <span class="fu">=</span> arr <span class="fu">.</span> <span class="fu">uncurry</span>
3232<span class="fu">&gt;</span> <span class="co">-- arr (\op (x,y) -&gt; x `op` y) </span></code></pre>
3333<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>