lowlight
lowlight copied to clipboard
highlightAuto does not produce any output if it can't find a suitable language
👋 Hey Titus!
I'm using lowlight and noticed something unusual - if I rely on highlightAuto, the behavior is that, if none of the listed languages have any relevance reported here:
https://github.com/wooorm/lowlight/blob/0f36148072cd096ca86753d6f1ff01589d30d78f/lib/index.js#L164
Then the fallback behavior is to output nothing:
https://github.com/wooorm/lowlight/blob/0f36148072cd096ca86753d6f1ff01589d30d78f/lib/index.js#L174-L180
This is pretty different behavior than highlight.js's automode, in which plaintext is always included as an option:
https://github.com/highlightjs/highlight.js/blob/main/src/highlight.js#L687
That behavior would be ideal - the 'empty' result here isn't all that easy to detect, and it's not super clean to generate the plaintext highlighted result myself.
Some larger context: @wooorm
Auto-detect is going away in version 12 of Highlight.js. If you still want to support this API you'll need to bring your own auto-detect logic to the table, but I warn you it's not a trivial problem at all - and honestly we were never very good at it.
Hey Tom, Josh! 👋
How peculiar. I guess the assumption in the code is that there always is some relevance, except when the input is empty.
What is the output that is expected? Is children: value ? [{type: 'text', value}] : [] on L177 good enough?
For bigger changes, I worry that they might be breaking, and then if Highlight.js is removing this API soon, then I worry that it is not worth much.
Given that autodetect is going away in highlight.js itself, I think it does make sense to remove this API from the next version of lowlight rather than having an API change in the middle. Defaulting to plaintext would be nice, but I think for us we'll probably just only highlight explicitly-stated languages?