git.iko.soy/typeable/pandoc
on master help sign in
Use latest skylighting; ensure no duplicate ids on code lines.

The line identifiers are built using the code block's identifier as a prefix. If the code block has null identifier, we use "cb1", "cb2", etc. Closes #4031.

commit856587ff63b1e89c71b73a367f5ba1730050e6dd authorJohn MacFarlane <jgm@berkeley.edu> dateThu 2 Nov 2017, 16:02 (9 years ago) parent5df2722
6 files changed+24−13
pandoc.cabal+1−1 src/Text/Pandoc/Highlighting.hs+5−2 src/Text/Pandoc/Writers/HTML.hs+11−3 stack.yaml+1−1 test/lhs-test.html+3−3 test/lhs-test.html+lhs+3−3
pandoc.cabal+1−1
@@ -320,7 +320,7 @@ library
320320 tagsoup >= 0.13.7 && < 0.15,
321321 base64-bytestring >= 0.1 && < 1.1,
322322 zlib >= 0.5 && < 0.7,
323− skylighting >= 0.4.2 && <0.5,
323+ skylighting >= 0.4.3 && <0.5,
324324 data-default >= 0.4 && < 0.8,
325325 temporary >= 1.1 && < 1.3,
326326 blaze-html >= 0.5 && < 0.10,
src/Text/Pandoc/Highlighting.hs+5−2
@@ -81,12 +81,15 @@ highlight :: SyntaxMap
8181 -> Attr -- ^ Attributes of the CodeBlock
8282 -> String -- ^ Raw contents of the CodeBlock
8383 -> Either String a
84−highlight syntaxmap formatter (_, classes, keyvals) rawCode =
84+highlight syntaxmap formatter (ident, classes, keyvals) rawCode =
8585 let firstNum = fromMaybe 1 (safeRead (fromMaybe "1" $ lookup "startFrom" keyvals))
8686 fmtOpts = defaultFormatOpts{
8787 startNumber = firstNum,
8888 numberLines = any (`elem`
89− ["number","numberLines", "number-lines"]) classes }
89+ ["number","numberLines", "number-lines"]) classes,
90+ lineIdPrefix = if null ident
91+ then mempty
92+ else T.pack (ident ++ "-") }
9093 tokenizeOpts = TokenizerConfig{ syntaxMap = syntaxmap
9194 , traceOutput = False }
9295 classes' = map T.pack classes
src/Text/Pandoc/Writers/HTML.hs+11−3
@@ -101,6 +101,7 @@ data WriterState = WriterState
101101 , stHtml5 :: Bool -- ^ Use HTML5
102102 , stEPUBVersion :: Maybe EPUBVersion -- ^ EPUB version if for epub
103103 , stSlideVariant :: HTMLSlideVariant
104+ , stCodeBlockNum :: Int -- ^ Number of code block
104105 }
105106
106107defaultWriterState :: WriterState
@@ -108,7 +109,8 @@ defaultWriterState = WriterState {stNotes= [], stMath = False, stQuotes = False,
108109 stHighlighting = False, stSecNum = [],
109110 stElement = False, stHtml5 = False,
110111 stEPUBVersion = Nothing,
111− stSlideVariant = NoSlides}
112+ stSlideVariant = NoSlides,
113+ stCodeBlockNum = 0}
112114
113115-- Helpers to render HTML with the appropriate function.
114116
@@ -703,6 +705,12 @@ blockToHtml _ HorizontalRule = do
703705 html5 <- gets stHtml5
704706 return $ if html5 then H5.hr else H.hr
705707blockToHtml opts (CodeBlock (id',classes,keyvals) rawCode) = do
708+ id'' <- if null id'
709+ then do
710+ modify $ \st -> st{ stCodeBlockNum = stCodeBlockNum st + 1 }
711+ codeblocknum <- gets stCodeBlockNum
712+ return ("cb" ++ show codeblocknum)
713+ else return id'
706714 let tolhs = isEnabled Ext_literate_haskell opts &&
707715 any (\c -> map toLower c == "haskell") classes &&
708716 any (\c -> map toLower c == "literate") classes
@@ -716,7 +724,7 @@ blockToHtml opts (CodeBlock (id',classes,keyvals) rawCode) = do
716724 else rawCode
717725 hlCode = if isJust (writerHighlightStyle opts)
718726 then highlight (writerSyntaxMap opts) formatHtmlBlock
719− (id',classes',keyvals) adjCode
727+ (id'',classes',keyvals) adjCode
720728 else Left ""
721729 case hlCode of
722730 Left msg -> do
@@ -725,7 +733,7 @@ blockToHtml opts (CodeBlock (id',classes,keyvals) rawCode) = do
725733 addAttrs opts (id',classes,keyvals)
726734 $ H.pre $ H.code $ toHtml adjCode
727735 Right h -> modify (\st -> st{ stHighlighting = True }) >>
728− addAttrs opts (id',[],keyvals) h
736+ addAttrs opts (id'',[],keyvals) h
729737blockToHtml opts (BlockQuote blocks) = do
730738 -- in S5, treat list in blockquote specially
731739 -- if default is incremental, make it nonincremental;
stack.yaml+1−1
@@ -9,7 +9,7 @@ packages:
99extra-deps:
1010- pandoc-types-1.17.2
1111- hslua-0.9.2
12−- skylighting-0.4.2
12+- skylighting-0.4.3
1313- cmark-gfm-0.1.1
1414- QuickCheck-2.10.0.1
1515- tasty-quickcheck-0.9.1
test/lhs-test.html+3−3
@@ -72,9 +72,9 @@ code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Infor
7272<h1 id="lhs-test">lhs test</h1>
7373<p><code>unsplit</code> is an arrow that takes a pair of values and combines them to
7474return a single value:</p>
75−<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><div class="sourceLine" id="1" href="#1" data-line-number="1"><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</div>
76−<div class="sourceLine" id="2" href="#2" data-line-number="2">unsplit <span class="fu">=</span> arr <span class="fu">.</span> uncurry</div>
77−<div class="sourceLine" id="3" href="#3" data-line-number="3"> <span class="co">-- arr (\op (x,y) -&gt; x `op` y)</span></div></code></pre>
75+<pre class="sourceCode literate haskell" id="cb1"><code class="sourceCode haskell"><div class="sourceLine" id="cb1-1" data-line-number="cb1-1"><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</div>
76+<div class="sourceLine" id="cb1-2" data-line-number="cb1-2">unsplit <span class="fu">=</span> arr <span class="fu">.</span> uncurry</div>
77+<div class="sourceLine" id="cb1-3" data-line-number="cb1-3"> <span class="co">-- arr (\op (x,y) -&gt; x `op` y)</span></div></code></pre>
7878<p><code>(***)</code> combines two arrows into a new arrow by running the two arrows on a
7979pair of values (one arrow on the first item of the pair and one arrow on the
8080second item of the pair).</p>
test/lhs-test.html+lhs+3−3
@@ -72,9 +72,9 @@ code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Infor
7272<h1 id="lhs-test">lhs test</h1>
7373<p><code>unsplit</code> is an arrow that takes a pair of values and combines them to
7474return a single value:</p>
75−<pre class="sourceCode literate literatehaskell"><code class="sourceCode literatehaskell"><div class="sourceLine" id="1" href="#1" data-line-number="1"><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</div>
76−<div class="sourceLine" id="2" href="#2" data-line-number="2"><span class="ot">&gt;</span> unsplit <span class="fu">=</span> arr <span class="fu">.</span> uncurry</div>
77−<div class="sourceLine" id="3" href="#3" data-line-number="3"><span class="ot">&gt;</span> <span class="co">-- arr (\op (x,y) -&gt; x `op` y)</span></div></code></pre>
75+<pre class="sourceCode literate literatehaskell" id="cb1"><code class="sourceCode literatehaskell"><div class="sourceLine" id="cb1-1" data-line-number="cb1-1"><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</div>
76+<div class="sourceLine" id="cb1-2" data-line-number="cb1-2"><span class="ot">&gt;</span> unsplit <span class="fu">=</span> arr <span class="fu">.</span> uncurry</div>
77+<div class="sourceLine" id="cb1-3" data-line-number="cb1-3"><span class="ot">&gt;</span> <span class="co">-- arr (\op (x,y) -&gt; x `op` y)</span></div></code></pre>
7878<p><code>(***)</code> combines two arrows into a new arrow by running the two arrows on a
7979pair of values (one arrow on the first item of the pair and one arrow on the
8080second item of the pair).</p>