Support » Plugin: SyntaxHighlighter Evolved » Bug with ampersand being converted to & in Gutenberg

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support Gabriel Maldonado

    (@gma992)

    Hi!

    I was able to replicate this error on a test site as well. While I cannot provide an ETA of when this will be fixed in the plugin, I added the snippet shared by another user at https://github.com/Automattic/syntaxhighlighter/issues/98#issuecomment-633230821 and this resolves the problem temporarily:

    /*@ Resolve & issue of syntax highlighter */
    add_filter('syntaxhighlighter_htmlresult', function($html) {
        return preg_replace('/&([^;]+;)/', '&$1', $html);
    });

    This will replace any string instance from & to &.

    For this you can add it directly into your functions.php, or use a plugin like Code Snippets: https://wordpress.org/plugins/code-snippets/ . Be sure to “Save and Activate” for this to work properly.

    Best,

    @gma992 You’re the man! You should sticky this for now as I’m sure many others have this issue. Thank you for the great plugin and support.

    @gma992 thanks for help!

    Unfortunately this code doesn’t help me. May be it destroed by site? So I changed it a bit and it works, Site destroes my code too, so here is a picture

    Thanks for great plugin and help!

    • This reply was modified 1 year, 1 month ago by ruhuker.

    Similar to this, I had found this issue for some time but never reported it until now as it had gotten more and more annoying. Namely, < and > signs are converted to &amp;amp;amp;lt; or &amp;gt;, respectively. The visual WP editor subsequently attaches more and more “amp;” as I continue editing the post. This does not happen in the Text editor.

    Image: https://ibb.co/kg6hwn1

    This only happens when the code is between CODE and /CODE tags. In the screenshot above, the top part is not enclosed between CODE and /CODE. Note that the < and > signs remain untouched. Then at the bottom, you will see < and > changed to &amp;amp;…

    This tells me that the Syntax Highlighter is responsible for the character conversion.

    [ EDIT: This solution seems to have fixed the issue. Change the last “return $content;” of the shortcode_hack function to “return htmlspecialchars_decode($content);” in syntaxhighlighter.php as described here – https://github.com/Automattic/syntaxhighlighter/issues/108 ]

    • This reply was modified 10 months, 1 week ago by Mikey_.
    • This reply was modified 10 months, 1 week ago by Mikey_.
    • This reply was modified 10 months, 1 week ago by Mikey_.
    • This reply was modified 10 months, 1 week ago by Mikey_.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Bug with ampersand being converted to & in Gutenberg’ is closed to new replies.