-
Notifications
You must be signed in to change notification settings - Fork 12
Add syntax_highlighting_code_block_auto_detect_languages filter #36
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
Conversation
|
@allejo Thoughts on this? |
allejo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't tested this code myself but it looks logically good to me
| if ( ! empty( $auto_detect_languages ) ) { | ||
| $highlighter->setAutodetectLanguages( $auto_detect_languages ); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is good! Without this check and setting autodetect to an empty array would still work, however, it would trigger the highlighter to reindex all of its languages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's right..
What is the behavior when the array is empty? Does it iterate over all languages in alphabetical order? If so, perhaps a default should be devised based on how popular the languages are?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the highlighter is configured to have 0 auto-detect languages, either by calling setAutodetectLanguages explicitly or setting the subset to null in highlightAuto, it will use every language registered (all ~185 languages) via brute-force.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As for having a default set of languages to autodetect:
- if you mean in highlight.php, that'd be left to highlight.js to decide (even though right now, it looks like some legacy behavior sets XML, JSON, JS, CSS, PHP, HTTP, as the default autodetection, see: https://github.com/scrivo/highlight.php/blob/master/Highlight/Highlighter.php#L97-L105)
- but if you mean for this plug-in, that's entirely feasible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the highlighter is configured to have 0 auto-detect languages, either by calling
setAutodetectLanguagesexplicitly or setting the subset to null inhighlightAuto, it will use every language registered (all ~185 languages) via brute-force.
And this brute force of all 185 languages is the default behavior?
As for having a default set of languages to autodetect:
Yeah, I suppose in this plugin. If we could somehow determine the relative popularity of each language by frequency of use on GitHub, for example, then this could be the default value used here when calling setAutodetectLanguages. Users could filter it to modify the order.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And this brute force of all 185 languages is the default behavior?
So the default behavior for highlight.php is to use "xml", "json", "javascript", "css", "php", "http" as the default auto-detect languages. However, this is legacy behavior and will change since highlight.js does not have any default languages (I should clarify this in the README). highlight.js will brute force its way through all its registered languages but it has different default builds with just some languages, so the brute force approach doesn't typically go through all 185 languages unless you use a full build. highlight.php only has a full build.
But yes, if you give the autodetection an empty array, the default behavior will be to use all 185 languages.
Add ability to restrict the set of languages which are used for auto-detection.
Usage:
Fixes #34.