• Resolved jakramer

    (@jakramer)


    Greetings,

    This is a bit of an edge case. We’re using the classic editor block (within the block editor), and the logic that decides when to encode/decode contents doesn’t appear to cover this case correctly.

    The linked page includes an example. The first (working) content on the page shows a simple example of html code that was added to the page using the SyntaxHighlighter Code block. The examples after that were all added by adding the Classic Block, then using various versions of the shortcode [code], [code lang="html"], and [sourcecode language="plain"]

    No matter how many times I edit the page, the first example works flawlessly (thanks!!) but each time I've used a shortcode within the classic block, < > and & all get re-encoded into &lt;, &gt; and &amp; every time the page is edited.

    • This topic was modified 10 months, 2 weeks ago by jakramer.

    The page I need help with: [log in to see the link]

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

    (@bluejay77)

    Hi @jakramer,

    In cases like this, we generally suggest either adding the block as a shortcode on its own or as a block.

    But if you have to use classic block, then the workaround is to go to the classic block dropdown and select ‘Edit as HTML’. Then you can delete the encoded characters and write it as a shortcode.

    Here’s an example:

    Screenshot Link: https://d.pr/i/K0sirV

    This display correctly on the frontend:

    Screenshot Link: https://d.pr/i/BCwEU7

    I hope that helps! Let us know if you have any other questions.

    Thread Starter jakramer

    (@jakramer)

    Hi,
    Thanks for the response. This is exactly the issue. I can do what you suggest above, and have, but then if I ever edit the page again, the content gets re-encoded, which basically means the page can never be edited after it has been created.

    What I need is for the plugin to correctly identify whether the content needs to be encoded/decoded in the context of the classic block.

    I did find that if I comment out the encoding step in this function:

      // The callback function for SyntaxHighlighter::encode_shortcode_contents()
      function encode_shortcode_contents_callback( $atts, $code = '', $tag = false ) {
        $this->encoded = true;
    // Commenting out the following line fixes bug with classic block (but probably breaks things for other cases)  
      //$code = str_replace( array_keys( $this->specialchars ), array_values( $this->specialchars ), htmlspecialchars( $code ) );
        return '[' . $tag . $this->atts2string( $atts ) . "]{$code}[/$tag]";
      }
    

    I am then able to edit the content within the classic block without the characters being re-encoded every time, but the display in the visual editor doesn’t show the characters correctly.

    Given that additional context, can you give me any pointers on where to look for the conditions under which that encode function is called, so that I can carve out an exception to make classic editor work correctly (rather than just commenting it out completely)?

    Thanks!

    Plugin Support Stef (a11n)

    (@erania-pinnera)

    Hello @jakramer,

    Thanks for bearing with us while our developers worked on this issue.

    Upon extensive testing, our tech team weren’t able to pinpoint the root of the issue, which appears to be pretty specific (and hard to figure out!)

    At this point, our best recommendation is to walk away from the Classic Editor and switch to Blocks, as anything involving Classic Editor is being discontinued — therefore support is getting limited if no supported completely.

    Hope that helps even if it’s not the answer you were expecting!

    Thread Starter jakramer

    (@jakramer)

    Thanks for looking into this. We would love to walk away from the classic block, but unfortunately not an option for this use case. We’ve found a different approach that will work with classic though, so we’ll go that way.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[code] in classic block re-encode , & on every edit’ is closed to new replies.