Crayon Syntax Highlighter for Classic editor OR Gutenberg

User avatar
axew3
w3all User
w3all User
Posts: 2569
Joined: Fri Jan 22, 2016 5:15 pm
Location: Italy
Contact:

Crayon Syntax Highlighter for Classic editor OR Gutenberg

Post 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 385 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 200 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

tosunkaya
Posts: 1
Joined: Sat Jan 16, 2021 11:05 am
Contact:

Re: Crayon Syntax Highlighter for Classic editor OR Gutenberg

Post 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

User avatar
axew3
w3all User
w3all User
Posts: 2569
Joined: Fri Jan 22, 2016 5:15 pm
Location: Italy
Contact:

Re: Crayon Syntax Highlighter for Classic editor OR Gutenberg

Post 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

jainanupam

Re: Crayon Syntax Highlighter for Classic editor OR Gutenberg

Post by jainanupam »

Seems the fix breaks again with WP version 5.6.2? Did anyone else check?

User avatar
axew3
w3all User
w3all User
Posts: 2569
Joined: Fri Jan 22, 2016 5:15 pm
Location: Italy
Contact:

Re: Crayon Syntax Highlighter for Classic editor OR Gutenberg

Post by axew3 »

It is here running into 5.6

what kind of problem you have?

jainanupam

Re: Crayon Syntax Highlighter for Classic editor OR Gutenberg

Post 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.

rev273
Posts: 2
Joined: Tue Apr 20, 2021 8:36 pm

Re: Crayon Syntax Highlighter for Classic editor OR Gutenberg

Post by rev273 »

Hi, thank you for your update for PHP 7.4, it works fine.

I have two questions:
1) TinyMCE icon is missing now. If there any chance to fix it? very uncomfortable work without it.
2) My code using tabs indent and in the program it looks flat and alignment correct:
Image
But on website it displayed crookedly
Image
Any idea how to change it?

Thank you.

User avatar
axew3
w3all User
w3all User
Posts: 2569
Joined: Fri Jan 22, 2016 5:15 pm
Location: Italy
Contact:

Re: Crayon Syntax Highlighter for Classic editor OR Gutenberg

Post by axew3 »

Not at moment, but i surely will take a look asap!
Sorry for delay on answer, missed!

pbnet
Posts: 3
Joined: Thu May 06, 2021 12:17 pm

Re: Crayon Syntax Highlighter for Classic editor OR Gutenberg

Post by pbnet »

Hello, I'm on WordPress 5.7.1 and PHP v7.4.12.
I've installed the update from: https://www.axew3.com/w3/forums/downloa ... php?id=388 and have the following behavior:
- Visitors accessing my site, can see the correct content displayed by the add-in:

Image

The problem is when adding or editing a new post:
- when adding a new post, the Syntax Highlighter icon is not present, so I don't know how to add the content using the add-in:

Image

- when editing a post that already uses the add-in, the format is not displayed correctly:

Image

Could you please fix this great plugin or give me a hint on what should I do?

Thanks.

User avatar
axew3
w3all User
w3all User
Posts: 2569
Joined: Fri Jan 22, 2016 5:15 pm
Location: Italy
Contact:

Re: Crayon Syntax Highlighter for Classic editor OR Gutenberg

Post by axew3 »

Hello, into my test, using gutenberg i can use the code block to add code into and edit it as more like.

Using the old way instead, may it is:

create the post, or enter to edit it, than switch to code editor mode
and use like this:

Code: Select all

<pre class="lang:default decode:true crayon-selected">... code ...</pre>
Could be also:

Code: Select all

<pre class="lang:php decode:true crayon-selected">... code ...</pre>
Note that, into my test, i had to SAVE THE FILE, in code editor mode, or it may sometime fail on correctly parse the content (adding some unwanted closing tag).
Into my tests, if it is an old, post, the <> icon appear into the old editor that display.
I will take a look as i can to fix and review all the plugin.

pbnet
Posts: 3
Joined: Thu May 06, 2021 12:17 pm

Re: Crayon Syntax Highlighter for Classic editor OR Gutenberg

Post by pbnet »

Thanks a lot.
The workaround is OK.
Any chance you could fix the icon for inserting code?

Thanks.

rev273
Posts: 2
Joined: Tue Apr 20, 2021 8:36 pm

Re: Crayon Syntax Highlighter for Classic editor OR Gutenberg

Post by rev273 »

pbnet wrote:
Mon May 10, 2021 5:10 am
Any chance you could fix the icon for inserting code?
I press Ctrl+F5 few times in text editor and this button appears. But after saving it's removed again.

pbnet
Posts: 3
Joined: Thu May 06, 2021 12:17 pm

Re: Crayon Syntax Highlighter for Classic editor OR Gutenberg

Post by pbnet »

Nope, doesn't work for me :(

Post Reply