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

Angle brackets get transformed into htmlentities #127

Closed
AndreaBarghigiani opened this issue Mar 16, 2020 · 4 comments · Fixed by #139
Closed

Angle brackets get transformed into htmlentities #127

AndreaBarghigiani opened this issue Mar 16, 2020 · 4 comments · Fixed by #139

Comments

@AndreaBarghigiani
Copy link

AndreaBarghigiani commented Mar 16, 2020

I am facing a wired issue because the angle brackets get transformed into htmlentities only if I switch between visual and text editor while using the Classic Editor and only on PHP open and close tags.

syntaxhighlight-php

If I save the post the code gets back to normal, but I would like to understand why is this happening. I've tried the solution proposed in #108 and I do not think that is related to #98 because I am not using Gutenberg.

I found that maybe the problem is in some replace in syntaxhighlighter_mce-4.js but I still have to find my way out.

If you have any suggestion I am all hearing.

I am using the latest version of the plugin (3.5.2) and I am on the latest WordPress (5.3.2).

Thank you for the future help.

-- Updates --
Deactivated all plugins but nothing has changed.
Moved "new line issue" to #128

@AndreaBarghigiani
Copy link
Author

AndreaBarghigiani commented Mar 16, 2020

Found a solution, but it wasn't:
My problem here was in the first replace .replace(/&/g, "&") in syntaxhighlighter_mce-4.js I am not a master in regex but I've compared the code that I had in the visual editor and then the one transformed from the text editor.

My workflow to see the issue is as follow:

  • insert PHP code via the [php] shortcode in the visual editor
  • switch to Text editor and nothing happens
  • switch back to Visual editor and my angle brackets are gone because the < get transformed in <

Now my solution is not ideal because I have to edit a core plugin file in order to fix this little issue, I could dequeue the ones added via the plugin and add my own but I would like to know if you plan to solve this issue with a next update before to chose how to implement my solution.

@alexsanford
Copy link
Contributor

I'm certain that I've seen this happen before, but I'm unable to reproduce.

I'm on version 3.5.2 of this plugin, version 5.3.2 of WordPress.

I have no plugin active except for this one and Classic Editor (version 1.5).

I am following these steps:

  • Go to "Posts > Add New".
  • Input a post title.
  • Switch to "Text" tab of editor.
  • Paste the following text:
[php]
<?php get_header(); ?>
 
  <div id="primary" class="site-content">
    <div id="content" role="main">
 
      <?php while ( have_posts() ) : the_post(); ?>
 
          <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
 
            <header class="entry-header">
              <h1 class="entry-title"><?php the_title(); ?></h1>
            </header>
 
            <div class="entry-content">
              <?php the_content(); ?>
            </div><!-- .entry-content -->
 
          </article><!-- #post -->
 
      <?php endwhile; // end of the loop. ?>
 
    </div><!-- #content -->
  </div><!-- #primary -->
 
<?php get_sidebar(); ?>
<?php get_footer(); ?>
[/php]
  • Switch to the "Visual" tab of the editor.

I do not see any escaping of the angle bracket characters.

Could you look at my steps above and let me know if there is something I'm missing? I'm sure I've seen this before, and would like to be able to reproduce it so we can add it to our queue.

@AndreaBarghigiani
Copy link
Author

Yes on a fresh installation the behaviour is as you describe, there is no angle brackets that get translated into &amp;lt; or &amp;gt; but still #128 is present (I am going to upload a video to update the issue).

Anyway I confirm what I wrote, if I edit the syntaxhighlighter_mce-4.js file and remove .replace(/&/g, "&amp;") at line 16 the problem get solved.

I tried to dequeue this file and load one of my own but since is loaded as plugin I am unable to replace it properly.

@alexsanford
Copy link
Contributor

Yes on a fresh installation the behaviour is as you describe, there is no angle brackets that get translated into &amp;lt; or &amp;gt; but still #128 is present (I am going to upload a video to update the issue).

Ok, so it sounds like this issue is not reproducible anymore? Can we close this and focus on #128? Or am I misunderstanding?

I tried to dequeue this file and load one of my own but since is loaded as plugin I am unable to replace it properly.

Maybe try using the mce_external_plugins filter?

https://github.com/Automattic/syntaxhighlighter/blob/master/syntaxhighlighter.php#L64

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