Page 1 of 3

Crayon Syntax Highlighter for Classic editor OR Gutenberg

Posted: Sun Jan 10, 2021 12:14 am
by axew3
Required to fix all about Crayon Syntax Highlighter making it work under php7> until last php8 and WordPress, at date of this post it is 5.6.

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
crayon-syntax-highlighter_Gut_Classic_11JAN21.zip
(2.08 MiB) Downloaded 1131 times

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  
You'll see that Crayon plugin will work both on old classic or Gutenberg.
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.
crayon-syntax-highlighter_patched_10JAN21.zip
(2.08 MiB) Downloaded 883 times
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;   
need to be switched to this instead, to properly work with Classic editor old pages/posts

Code: Select all

    // w3 GUTENBERG fix
    //return $code;   
Now, would be nice to make it work with both in one. I may will check for this as possible, or may someone will come to suggest with a reply download the first zip

Re: Crayon Syntax Highlighter for Classic editor OR Gutenberg

Posted: Sat Jan 16, 2021 11:11 am
by tosunkaya
5 year ago version is still working. Can i use this one when it broke or paste new files? What changes have you made thanks
Maybe you can upload this to wordpress plugin repo.

is it still safe to use the old version

Re: Crayon Syntax Highlighter for Classic editor OR Gutenberg

Posted: Sun Jan 17, 2021 11:05 am
by axew3
Patched files:

Code: Select all

crayon-syntax-highlighter/crayon_formatter.class.php
crayon-syntax-highlighter/crayon_parser.class.php
crayon-syntax-highlighter/crayon_langs.class.php
crayon-syntax-highlighter/util/crayon_util.class.php
crayon-syntax-highlighter/langs/default/default.txt (so now default fully works without errors, maybe for some config still some fix is required?)
crayon-syntax-highlighter/langs/yaml/yaml.txt


others questions i have not well understand the meaning maybe, anyway:
It is secure? I think yes, but i have not review all the code, assuming i were in case able to detect a security bug.
Work on old code: Yes.
Can you post on plugin repository: no, i'm sorry, i will maintain alive here at moment. It is not for specific reason, i would like to do what you say but, no time at moment to follow too many things. May i will do.

If you find any bug report please so it will be fixed

Re: Crayon Syntax Highlighter for Classic editor OR Gutenberg

Posted: Sat Mar 13, 2021 8:32 am
by jainanupam
Seems the fix breaks again with WP version 5.6.2? Did anyone else check?

Re: Crayon Syntax Highlighter for Classic editor OR Gutenberg

Posted: Sat Mar 13, 2021 8:58 am
by axew3
It is here running into 5.6

what kind of problem you have?

Re: Crayon Syntax Highlighter for Classic editor OR Gutenberg

Posted: Wed Mar 17, 2021 6:28 am
by jainanupam
Sorry my bad! I guess I had wrong version enabled (the one without your patch). This seems to be working fine even with WP v5.7. Thank you for the support and help.