The code has been also patched to correctly assign colors into code lines and to correctly parse all languages. (almost for what i have test out). If you find any bug may report
This is the LAST version that will work both on
old Classic Editor and new Gutenberg:
to use on Gutenberg, just add Code Block into page or post, paste the code into, then save
or edit the old directly as it display on edit page/post, and save. Enjoy
Beside something else, this new version, just add the follow (respect others here below for Classic or Gutenberg) and it is modified this way on
/crayon-syntax-highlighter/crayon_formatter.class.php
Code: Select all
// w3 GUTENBERG fix (may more characters needs to be added if not correctly parsed)
$search = array('<', '>', '[', ']', '&');
$replace = array('<', '>', '[', ']','&');
$code = str_replace($search, $replace, $code);
// w3 GUTENBERG fix // on gutenberg this will work fine
//return $code; // on gutenberg this will work fine
it is not re-tested under php8 right now, so if you find that i have forget something and you have some error on php8, just let know please
P.s editing old inserted code, may adding something more via copy/paste, you'll see that may <br /> tags appears into code output.
Switch to wordpress to view page as code mode, remove those <br /> or any unwanted chars, and save. All will be ok now.
note this line above: // w3 GUTENBERG fix (may more characters needs to be added if not correctly parsed)
if you find any entity that should be added, because it is not correctly parsed, let know
Note:
I can confirm that the unwanted javascript $test alert is no longer there and that the front end is displaying the syntax high-lighted code correctly. (Un)fortunately I’m still not using Gutenberg since I created the site many years ago and prefer to keep working with what I know. And, as you’ve said the TinyMCE icon is missing, but I can always get around this by simply hard coding a <pre tag.
"Single" versions:
The version for Gutenberg only, fully working:
to use on Gutenberg, just add Code Block into page or post, paste the code into, then save.
All will work fine.
In the case that this version, do not work with old code inserted on posts or pages through the old Classic editor (the code do not display or is not well formatted) then you'll have to use this instead:
what it change, is exactly ONE single line into a single file, that is:
/crayon-syntax-highlighter/crayon_formatter.class.php
where this code:
Code: Select all
// w3 GUTENBERG fix
return $code;
Code: Select all
// w3 GUTENBERG fix
//return $code;