EnlighterJS / Plugin.WordPress

:package: Official WordPress Plugin of EnlighterJS
http://wordpress.org/plugins/enlighter/
GNU General Public License v2.0
115 stars 18 forks source link

Removing unused languages #238

Closed ajtruckle closed 4 years ago

ajtruckle commented 4 years ago

In your previous version I was able to use this code snippet to remove languages from the drop-down list:

function mm_ejs_languages($langs){
    unset ($langs['Java']);
    unset ($langs['Javascript']);
    unset ($langs['JSON']);
    unset ($langs['Python']);
    unset ($langs['Ruby']);
    unset ($langs['C']);
    unset ($langs['RUST']);
    unset ($langs['LUA']);
    unset ($langs['Matlab']);
    unset ($langs['NSIS']);
    unset ($langs['Diff']);
    unset ($langs['VHDL']);
    unset ($langs['Avr Assembly']);
    unset ($langs['Generic Assembly']);
    unset ($langs['Kotlin']);
    unset ($langs['Squirrel']);
    return $langs;
}

// add a custom filter to modify the language list
add_filter('enlighter_languages', 'mm_ejs_languages');

This no longer works with v4 so I am getting all languages.

AndiDittrich commented 4 years ago

the internal data structure has changed, you've to modify your code (keys/values swapped)

Array
(
    [generic] => Generic Highlighting
    [avrasm] => Avr Assembly
    [asm] => Generic Assembly
    [c] => C
    [cpp] => C++
    [csharp] => C#
    [css] => CSS
    [cython] => Cython
    [cordpro] => CordPro
    [diff] => Diff
    [dockerfile] => Dockerfile
    [groovy] => Groovy
    [golang] => Go
    [html] => HTML
    [ini] => Ini/Conf Syntax
    [java] => Java
    [js] => Javascript
    [json] => JSON
    [kotlin] => Kotlin
    [less] => LESS
    [lua] => LUA
    [md] => Markdown
    [matlab] => Matlab/Octave
    [nsis] => NSIS
    [php] => PHP
    [powershell] => PowerShell
    [prolog] => Prolog
    [python] => Python
    [ruby] => Ruby
    [rust] => Rust
    [scss] => SCSS
    [shell] => Shellscript
    [sql] => SQL
    [squirrel] => Squirrel
    [swift] => Swift
    [typescript] => TypeScript
    [vhdl] => VHDL
    [visualbasic] => VisualBasic
    [xml] => XML
    [yaml] => YAML
    [raw] => RAW Code
)
ajtruckle commented 4 years ago

the internal data structure has changed, you've to modify your code (keys/values swapped)

Thanks for that explanation. So, if I adjust my code like this it would be correct, right?

function mm_ejs_languages($langs){
    unset ($langs['java']);
    unset ($langs['js']);
    unset ($langs['json']);
    unset ($langs['python']);
    unset ($langs['ruby']);
    unset ($langs['c']);
    unset ($langs['rust']);
    unset ($langs['lua']);
    unset ($langs['matlab']);
    unset ($langs['nsis']);
    unset ($langs['diff']);
    unset ($langs['vhdl']);
    unset ($langs['avrasm']);
    unset ($langs['asm']);
    unset ($langs['kotlin']);
    unset ($langs['squirrel']);
    return $langs;
}

// add a custom filter to modify the language list
add_filter('enlighter_languages', 'mm_ejs_languages');
AndiDittrich commented 4 years ago

of course, this should work as expected

AndiDittrich commented 4 years ago

the docs have also been updated

ajtruckle commented 4 years ago

Thanks for latest version. :)

ajtruckle commented 3 years ago

Sorry for being so dumb! I can't remember how to find out the official new language name ids in the default array so I can unset them (like R and RouterOS). I tried to find in the docs but could not locate. Sorry to bring this up again! Thanks for your good work!

AndiDittrich commented 3 years ago

look into LanguageManager.php or use print_r