linenums support for inline option by lightxue · Pull Request #652 · Python-Markdown/markdown (original) (raw)

I've been experimenting with Pygments inline in SuperFences. I'm not suggesting we should or shouldn't include inline output in CodeHilite, only showcasing what I've been experimenting with (I myself am still debating whether to include in my own package).

Anyways, there is a way to do inline and still be able to select, and copy and paste in a sane manner. By default, Pygments does something like this for inline line numbers:

1

This means that when you copy and paste from the code block, you will pick up line numbers which can be annoying.

But if you alter the output to:

You can use CSS and display line numbers that don't get included in a copy/paste.

[data-linenos]:before { content: attr(data-linenos); /* some additional padding and/or margin may be required. */ }

Now you can have inline output with sane selection and copy/paste:

screenshot 2018-06-15 21 41 22

The subclassing of the Pygments HtmlFormatter object is pretty straight forward: facelessuser/pymdown-extensions@a67a3e7#diff-e331ec6f621f208fd178913907efa563R118.

So, if inline was a preferred, or at least a desirable output option, it could be done in a similar fashion. I generally don't like Pygments default inline output because of the bad copy/paste side effects.

Just some food for thought while considering adding inline.