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

Clarification - Is it possible to simplify the list of supported languages in the TinyMCE plugin? #223

Closed ajtruckle closed 4 years ago

ajtruckle commented 4 years ago

Is it possible to reduce the list of languages displayed in the drop-down list?

Just curious.

AndiDittrich commented 4 years ago

you should really read the docs :stuck_out_tongue:

https://github.com/EnlighterJS/documentation/blob/master/wordpress/FilterHooks.md#filterenlighter_languages

ajtruckle commented 4 years ago

you should really read the docs 😛 https://github.com/EnlighterJS/documentation/blob/master/wordpress/FilterHooks.md#filterenlighter_languages

You are right! I suppose I am not used to looking through GitHub to find the documentation. I get frustrated too when I get questions answers in the help system that I have provided. :)

I have been successful with this and I wanted to go over a few things with you if I may.

Observation 1 When I started writing my code snippet to remove the languages (using your sample to start from) my editor was raising syntax errors. It did not like lines of code like unset $langs['Java'];. What I had to do was insert braces, so my final code looked like this:

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');

Observation 2 When I create the snippet (using my snippets plugin) it offers where to run the snippet:

I assumed the first option Run snippet everywhere.

Observation 3 This might be more appropriate in a distinct issue. In your language drop-down list you have:

languages

The first entry is Default (Global settings). This description is fine from the perspective of the website author as he knows about the plugin EnlighterJS and (if he has a good memory) knows what his global settings choice was. But this will not mean anything to a standard user of my support forum who may want to insert code. Therefore, my suggestion is to rephrase that as (for example):

Default (Generic)

AndiDittrich commented 4 years ago
  1. thanks i've to fix the docs
  2. "everywhere" is the right place
  3. you can also override the whole language list/entries - it is an associative array which contains the language identifier as key and the display name as value. for debugging use print_r to display the full list
ajtruckle commented 4 years ago

3. you can also override the whole language list/entries - it is an associative array which contains the language identifier as key and the display name as value. for debugging use print_r to display the full list

I understand. I had not thought of doing things that way and I can see the merits of that.

According to the enlighter plugin in Wordpress it says these are the available language ids:

Does that cover all of them? I have a side question though based on your suggestion. How can I build the new text string "Default (xxxx)" where xxxx is the global setting description?, and what would the id counter be, default?

AndiDittrich commented 4 years ago

again...please read the docs, especially the filter hooks - then just try+error and no, it doesn't cover all of them - you can use print_r within the filter hook to get a full list or take look into the contextual help on the settings page - it includes a dynamic list

ajtruckle commented 4 years ago

look into the contextual help on the settings page - it includes a dynamic list

Yes, that is where I got the list from:

help

AndiDittrich commented 4 years ago

the list is much longer by default, but in case you've already modified the list via the filter hooks the contextual help will also change

ajtruckle commented 4 years ago

Doh! Gotcha.

ajtruckle commented 4 years ago

Although, that dynamic list does not include "default". I will investigate with print_r.

AndiDittrich commented 4 years ago

the list only includes the specific language shortcodes, not all languages

ajtruckle commented 4 years ago

According to print_r:

Array
(
    [Generic Highlighting] => generic
    [CSS (Cascading Style Sheets)] => css
    [HTML (Hypertext Markup Language)] => html
    [Java] => java
    [Javascript] => js
    [JSON] => json
    [Markdown] => md
    [PHP] => php
    [Python] => python
    [Ruby] => ruby
    [Batch MS-DOS] => msdos
    [Shell Script] => shell
    [SQL] => sql
    [XML] => xml
    [C] => c
    [C++] => cpp
    [C#] => csharp
    [RUST] => rust
    [LUA] => lua
    [Matlab] => matlab
    [NSIS] => nsis
    [Diff] => diff
    [VHDL] => vhdl
    [Avr Assembly] => avrasm
    [Generic Assembly] => asm
    [Kotlin] => kotlin
    [Squirrel] => squirrel
    [Ini/Conf Syntax] => ini
    [RAW Code] => raw
    [No Highlighting] => no-highlight
)

This list does not include the Default (Global Settings) entry to which my discussion was about.

AndiDittrich commented 4 years ago

ok sry, then it's currently not possible to change this

ajtruckle commented 4 years ago

OK. No worries. have to live with it for now. :)