question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Option to default to line-number for all code blocks

See original GitHub issue

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.

Issue Analytics

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

github_iconTop GitHub Comments

4reactions
lukasoppermanncommented, Mar 20, 2016

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.

2reactions
LeaVeroucommented, Apr 25, 2016

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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

1 Code::Blocks Project Management
The display of line numbers in Code::Blocks can be activated via 'Settings' →'General Settings' in the field 'Show line numbers'. The shortcut Ctrl-G...
Read more >
How to enable line numbers in minted for code blocks with ...
I would like to continue using the default setting in the code above, but I want to be able to enable line numbers...
Read more >
Line numbers for every cell in VSCode Jupyter Notebook Cells
In VS Code Jupyter Notebook, you can toggle line numbers by pressing L. The trick is to select the current cell first.
Read more >
Code blocks - Fork of Material for MkDocs - Jim Andreas intro
Line numbers can be added to a code block by using the linenums="<start>" option directly after the short name, whereas <start> represents the...
Read more >
Number lines in code blocks with Rmarkdown - Atusy's blog
See ?rmarkdown::html_document for available highlight options. --- title: Line numbers with Rmarkdown documents output ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found