Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seems to not work with Gutenberg Wordpress Editor #441

Open
The-Judge opened this issue Aug 6, 2018 · 6 comments
Open

Seems to not work with Gutenberg Wordpress Editor #441

The-Judge opened this issue Aug 6, 2018 · 6 comments

Comments

@The-Judge
Copy link

In the current version of Wordpress (4.9.8) the WP team introduced a preview of the will-become-default - Editor called Gutenberg (https://wordpress.org/plugins/gutenberg/).
Crayon Syntax Highlighter seems not to be compatible with it; when a code-block is inserted, it doesn't get rendered by CSH as it is with the legacy WordPress editor.

@alexwhittemore
Copy link

I'm noticing this also: When I edited an old post with the new editor, I clicked the "code" toolbar item on an existing block of code, and the crayon editor popped up as expected. But when I paste my code, and render the whole post in preview, some unescaped HTML comes through inside the block. And subsequent attempts to pull up the crayon editor haven't worked.

when I go to the bottom of the page and add a new block with gutenberg of type Formatting>Code, the Crayon editor similarly doesn't work. But the output page gets rendered as Crayon would by default, and without unescaped HTML.

@mipon
Copy link

mipon commented Nov 10, 2018

I'm not sure if it is a fault of Gutenberg but it seems when Gutenberg saves a post and the save_post action hook is triggered, is_admin() returns false as opposed to the classic editor which returns true.

The part which needs to be fixed is in crayon_wp.class.php:
https://github.com/aramk/crayon-syntax-highlighter/blob/2.8.3/crayon_wp.class.php#L1277-L1325

The line 1323 add_action('save_post', 'CrayonWP::save_post', 10, 2); is not read when Gutenberg updates a post as it is in a conditional block of is_admin(). Moving the line to outside the conditional block solves the problem.

Changing

    } else {
        // Update between versions
        CrayonWP::update();
        // For marking a post as containing a Crayon
        add_action('update_post', 'CrayonWP::save_post', 10, 2);
        add_action('save_post', 'CrayonWP::save_post', 10, 2);
        add_filter('wp_insert_post_data', 'CrayonWP::filter_post_data', '99', 2);
    }

to

    } else {
        // Update between versions
        CrayonWP::update();
        // For marking a post as containing a Crayon
        add_action('update_post', 'CrayonWP::save_post', 10, 2);
        add_filter('wp_insert_post_data', 'CrayonWP::filter_post_data', '99', 2);
    }
    add_action('save_post', 'CrayonWP::save_post', 10, 2);

would solve the problem. I haven't fully tested it thoroughly so not sure about any side effects.

[edit]
Found an relevant issue there in the Gutenberg issue tracker. WordPress/gutenberg#11138 So they clearly say that it uses REST API and is_admin() returns false when save_post is fired.

@EXL
Copy link

EXL commented Dec 26, 2018

Thank you, @mipon

I wonder if Crayon Syntax Highlighter developers will fix this problem.

@EXL
Copy link

EXL commented Dec 26, 2018

P.S. Inline code insertion also does not work, e.g.:

Test <pre class="inline:1">preformatted</pre> text.

Gutenberg result:
screenshot_20181226_112941

Classic editor result:
screenshot_20181226_112721

@mipon
Copy link

mipon commented Dec 26, 2018

@EXL try this plugin.

@EXL
Copy link

EXL commented Dec 27, 2018

@mipon thanks!
But while I switched to using the Classic Editor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants