Skip to content

Commit

Permalink
HTML writer: ensure that line numbers in code blocks get id-prefix.
Browse files Browse the repository at this point in the history
Closes #5650.
  • Loading branch information
jgm committed Jul 19, 2019
1 parent 4d65bbf commit 5c655e8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/Text/Pandoc/Writers/HTML.hs
Original file line number Diff line number Diff line change
Expand Up @@ -776,8 +776,8 @@ blockToHtml opts (CodeBlock (id',classes,keyvals) rawCode) = do
then do
modify $ \st -> st{ stCodeBlockNum = stCodeBlockNum st + 1 }
codeblocknum <- gets stCodeBlockNum
return ("cb" ++ show codeblocknum)
else return id'
return (writerIdentifierPrefix opts ++ "cb" ++ show codeblocknum)
else return (writerIdentifierPrefix opts ++ id')
let tolhs = isEnabled Ext_literate_haskell opts &&
any (\c -> map toLower c == "haskell") classes &&
any (\c -> map toLower c == "literate") classes
Expand All @@ -800,7 +800,9 @@ blockToHtml opts (CodeBlock (id',classes,keyvals) rawCode) = do
addAttrs opts (id',classes,keyvals)
$ H.pre $ H.code $ toHtml adjCode
Right h -> modify (\st -> st{ stHighlighting = True }) >>
addAttrs opts (id'',[],keyvals) h
-- we set writerIdentifierPrefix to "" since id'' already
-- includes it:
addAttrs opts{writerIdentifierPrefix = ""} (id'',[],keyvals) h
blockToHtml opts (BlockQuote blocks) = do
-- in S5, treat list in blockquote specially
-- if default is incremental, make it nonincremental;
Expand Down
22 changes: 22 additions & 0 deletions test/command/5650.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
````
% pandoc --id-prefix foo
```haskell
a
b
```
^D
<div class="sourceCode" id="foocb1"><pre class="sourceCode haskell"><code class="sourceCode haskell"><span id="foocb1-1"><a href="#foocb1-1"></a>a</span>
<span id="foocb1-2"><a href="#foocb1-2"></a>b</span></code></pre></div>
````

````
% pandoc --id-prefix foo
``` {.haskell #bar}
a
b
```
^D
<div class="sourceCode" id="foobar"><pre class="sourceCode haskell"><code class="sourceCode haskell"><span id="foobar-1"><a href="#foobar-1"></a>a</span>
<span id="foobar-2"><a href="#foobar-2"></a>b</span></code></pre></div>
````

0 comments on commit 5c655e8

Please sign in to comment.