-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Option to default to line-number for all code blocks #912
Comments
It’s super easy to do so yourself, as a pre-processing step before Prism runs. Assuming you're using a $$("pre:not(.no-line-numbers) > code").forEach(code => code.parentNode.classList.add("line-numbers")); If you’re not using $$("pre:not(.no-line-numbers)").forEach(pre => pre.classList.add("line-numbers")); |
This is exactly what I am doing at the moment. I just feel it would be nicer to actually have that within the plugin. But I guess you do not like it because it needs config? |
I was just suggesting a temporary workaround that will work now, independently of what decision we make here. |
Another way to go would be to make it an inherited option, just like language. i.e. you can put the |
Hmm, I definitely agree with the reasoning for opt-out. 👍 Of course, BC breaks are a concern. A possibility would be a version bump. Also of course, it is not going to really break anything, as it is just adding line numbers, but I see your problem. We could make it opt-out, but have the possibility of a no-line-numbers class on a shared ancestor, which would make it easy to fix any breakage. But this would mean we would than have to check for the individual I think the beast would be to think in the direction of opt-out and how this can be done with none to minimum BC problems. |
Hey @LeaVerou I have been thinking about this a bit:
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. |
I like the idea of having plugins in separate repos!
Not everybody using Prism can code JS, but all our users can work with HTML. Note that around 50% or more of HTML authors are not super comfortable with JS. Ideally there should be a way to provide both and it should be in the core or some base plugin that gets included if at least one plugin is included. @zeitgeist87 did some work on writing such a plugin a while ago, but it was way too large for this purpose IIRC. We need something small and compact, even if it doesn't cover all possible use cases ever, so that it doesn't add any significant weight to the plugins. |
Hey @LeaVerou, sadly I have no idea how you build the editor and also not how one would change it to use repos, but it could possibly be done with something like gulp on the server. The plugins should be underneath https://github.com/PrismJS and somewhere there would be a repo where you send an issue to add a new plugin. If it is agreed the plugin should be added, you (or somebody) could create a new repo there. Themes could potentially also get their own repos, but maybe that is overkill. Maybe it would make sense to add a "Prism-project" repo, which is the code for the website. There users could add an issue for a new plugin.
I totally agree with this and I think this is one of the advantages of Prism. But this could be easily solved by adding (and requiring every plugin to have) sensible defaults. This should make it possible to use prism just like now without any config, put still allow for configuration. I think my suggestions would be very small as it is just a getter / setter idea and could be easily get to the core (and also used in the core but of course with sensible defaults.) |
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. |
Hi, any news about this ? It would be really nice to simply have to download this plugin and let it numbering line by default :-) |
+1 |
+1 |
nice tool. Can I ask how can I fix one line result . Something shows my code as only one line stripping all new lines. |
@tsubasacode Please open a new issue and describe the problem in more detail. Maybe even add an example project or JSFiddle, so I can reproduce your problem. |
Thank you very much. I found a online and realized that it was because of I was getting the code from editable div instead of textarea. When I switched to textarea it worked as perfectly. |
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: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.The text was updated successfully, but these errors were encountered: