prism: Option to default to line-number for all code blocks

Hey @LeaVerou,

so I am using your awesome prism syntax highlighter for my blog. I would like all code blocks to have line numbers (with maybe the occasional one without line numbers).

I think it would be pretty awesome to add some kind of config to set the line-number plugin into a default-on state. In this state, the plugin would always add line-numbers, apart from the code blocks where the class .no-line-numbers is added.

Adding the .line-numbers class for every code-block has the following disadvantages in some cases:

  • if done automatically, you can not unset it
  • I am using markdown files, which are parsed by the php commonmark and it is not so easy to automatically change the behavior to always add line-numbers. As they are sticking to the commonmark specs, I don’t think they should change their behaviour, so it would be much simpler to add it to prism.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 15 (10 by maintainers)

Most upvoted comments

Hey @LeaVerou I have been thinking about this a bit:

  • maybe it would actually be a good idea to extract plugins to their own git repos, this way they could be individually sem-versioned (one could easily communicate BC breakage by sem-version)
    • you website could still build a download with everything included
    • it would make working with prism via bower a little easier
    • a changelog much like here http://keepachangelog.com/ can communicate any changes and like to an upgrade FAQ to help people fix BC breakage. (I no there already is a changelog which is fine, but maybe a little more details could be added to the realses 😄 )
  • somehow adding a class to an ancestor e.g. the <article> feels like configuration to me
    • if there is configuration, wouldn’t it be better to make it real and add it in js?

The Prism object could have a small config method, which only has a getter and setter (no other logic). This way any plugin (also thrid-party plugins) could have the user add configs and retrieve it in the plugin to deal with it. Of course, there should be sensible defaults, so that the “load a go” way of using Prism, that you have going now, still works.

Prism.config({
  'auto-line-numbers': true 
});

I really like the idea of just adding a js and css file and everything starts automatically, thus I would say it should still work. But if feel Prism is at a point, where this approach needs to be extended because whenever you actually want to do some more “advanced” stuff, its getting a little hard.

Actually, it doesn’t need to be repos under PrismJS, it could be any repo, as long as we store its info in components.js. That way people can push fixes to their plugins without requiring our approval, and we can still offer a nice build with everything from the Prism page. Unfortunately, I don’t have the time to work on this, but perhaps @Golmote or @zeitgeist87 do?