jgm / skylighting

A Haskell syntax highlighting library with tokenizers derived from KDE syntax highlighting descriptions
195 stars 63 forks source link

A way to disable autolinks in fenced code blocks #197

Closed max-arnold closed 2 months ago

max-arnold commented 2 months ago

It would be nice to disable autolinks in fenced djangotemplate (and other languages) code blocks. Right now it is not the case:

echo -e '```djangotemplate\nhttp://example.com\n```' | pandoc -f markdown

<div class="sourceCode" id="cb1"><pre
class="sourceCode djangotemplate"><code class="sourceCode djangotemplate"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a>http://example.com</span></code></pre></div>

I'm converting a markdown file with some code blocks to pdf (via weasyprint), and in the resulting snippets links are hoverable and clickable. It doesn't make sense in my scenario because the links are pointing either to localhost or example.com subdomains, or just http://x.x.x.x.

My expectation was that using --from markdown-autolink_bare_uris should affect the whole document, but apparently it doesn't work for fenced code blocks (maybe inline code as well?). Not sure how to fix that in a backward compatible way though... Maybe something like this:

```djangotemplate-autolink_bare_uris
http://example.com
```

Or maybe define another extension that is enabled by default but can be disabled via --from markdown-autolink_fenced_bare_uris.

Based on https://github.com/jgm/pandoc/discussions/10219

jgm commented 2 months ago

Sorry, I think I may have misunderstood your original worry about this. I thought you were objecting to the empty <a>..</a>. But this would not have the effect of making http://example.com a clickable link. If that is happening, it is not because of the HTML pandoc is generating.

<span id="cb1-1">
  <a href="#cb1-1" aria-hidden="true" tabindex="-1">
  </a>
  http://example.com
</span>

won't create a link on http://example.com, which is outside of the <a> element.

jgm commented 2 months ago

Are you sure you don't have some JavaScript thing running that adds autolinks in HTML?

max-arnold commented 2 months ago

Apparently I'm dumb today... It was macOS Preview app that made all these links in the PDF file clickable 🤦‍♂️ And when I went to debug this, I noticed these <a> tags but missed the fact that they are empty.

I'm really sorry for wasting your time. Thank you for pointing me in the right direction!