asvd / microlight

highlights code in any programming language
http://asvd.github.io/microlight
MIT License
1.48k stars 63 forks source link

Support `<pre><code>` tags. #14

Open 2brownc opened 3 years ago

2brownc commented 3 years ago

Currently microlight class needs to be included in the class list. But most syntax highlight scripts automatically work on code wrapped in <pre><code> tags.

I request same behavior with microlight.js.

Qix- commented 3 years ago

What would be better is:

https://github.com/asvd/microlight/blob/master/microlight.js#L39-L41

Changing this to:

-     var reset = function(cls) {
+     var reset = function(nodes) {
         // nodes to highlight
-        microlighted = _document.getElementsByClassName(cls||'microlight');
+        microlighted = nodes || _document.getElementsByClassName('microlight');

And then release as a major version bump.

This would solve all problems in a way that is trivially backwards compatible.

gurugeek commented 2 years ago

Following @Qix- Idea I modified it to highlight all automatically

    var reset = function(nodes) {
        microlighted = document.getElementsByTagName("code");

you can find the fork here https://github.com/gurugeek/microlight/blob/master/microlight.js

Qix- commented 2 years ago

@gurugeek your change does not do what I suggested.