Number lines on code blocks in bookdown::htmld_document2 fails because of bookdown:::clean_pandoc2_highlight_tags

I found line numbers on code blocks in rmarkdown::html_document is possible by
giving YAML front matter with highlight: pygment and chunk options with class.source = "numberLines" (Number lines in code blocks with Rmarkdown)

However, this is not the case for bookdown::html_document2 and because bookdown:::clean_pandoc2_highlight_tags removes tags required for numbering.

Does anybody know why this process is required?

Example

A following screenshot is created by html code below.

image

<div class="sourceCode" id="cb15"><pre class="sourceCode numberSource r numberLines"><code class="sourceCode r"><a class="sourceLine" id="cb15-1" title="1">x &lt;-<span class="st"> </span><span class="kw">seq</span>(<span class="dv">10</span>)</a>
<a class="sourceLine" id="cb15-2" title="2"><span class="kw">mean</span>(x)</a></code></pre></div>

Embedding the above html code directory in .Rmd file and kniting as bookdown:::html_document2 results in

<div id="cb15" class="sourceCode">
<pre class="sourceCode numberSource r numberLines"><code class="sourceCode r">x &lt;-<span class="st"> </span><span class="kw">seq</span>(<span class="dv">10</span>)
<span class="kw">mean</span>(x)</code></pre>
</div>

which is rendered on browser as

image

I think This process is required in bookdown so that another syntax higlighting that pandoc could be applied. (Gitbook I guess). This function has been created for use in split_chapter internal fonction but has been added last October in html_document2

It is difficult to know why when you are not the developper :smile:
I think you can open an issue and ask about that and if an argument could be added to optionaly choose to use pandoc syntax highlighting with html_document2 if one wants to. We'll see if the current maintainer of bookdown has the answer to why.

Thank you for the answer.
I opened an issue, and hope my feature request will be accepted.

Merged #706

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.