Forum

Thread tagged as: Question, Problem, Ace

Ace Editor code snippet html tag escape

I have opted to use the Ace Editor for blog posts as it seemed to be the best way to keep code clean & add classes (editor="ace" html="true"). Now I'm trying to incorporate code snippets in a potential post. I'm having trouble with html tag escaping.

<pre><code>
&lt;h1&gt;This is an h1 element!&lt;/h1&gt;
</code></pre>

When I put this into the ace textarea and save, the bracket codes turn into the actual brackets "<" and ">". At the moment it seems to render out on the actual web post correctly but if I go back and save the post again, it will output an actual h1 element. I've looked into the Ace page a bit, and asked the internet but I can't readily find an option to tell Ace to NOT to format html special charaters or does this happen to be a Perch interaction?

Conversely, is there a textarea option that will add no extra html and not effect what is written in the text area?

Nicholas Nelson

Nicholas Nelson 0 points

  • 7 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Have you set html="true" on the template tag?

Yessir

<perch:blog id="postDescHTML" type="textarea" label="Post" editor="ace" html="true" size="xxl autowidth" required="true"  suppress="true" />
Drew McLellan

Drew McLellan 2638 points
Perch Support

Are you outputting the post using the same template?

Oh sorry, yes.

<perch:blog id="postDescHTML" html="true" />
Drew McLellan

Drew McLellan 2638 points
Perch Support

Make sure you have the type attribute set.

Okie dokie.

<perch:blog id="postDescHTML" type="textarea" html="true" />

This doesn't affect my output. It's the admin area that is changing "<" to "<". I'm not sure if it's an interaction of the js editor or Perch.

I just tried removing the editor="ace" option to use the default editor and the problem persists.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Which version are you running?

Here's an excerpt of diagnostics

Perch: 2.5.4, PHP: 5.5.3, MySQL: 5.5.33, with PDO
Server OS: Darwin, apache2handler
Installed apps: content (2.5.4), assets (2.5.4), perch_blog (4.1)
Drew McLellan

Drew McLellan 2638 points
Perch Support

Looks fine to me. Does the same happen with a new post now that Ace has been taken out of the equation?

Yep, same behavior.

Drew McLellan

Drew McLellan 2638 points
Perch Support

I'll see if I can reproduce this here.

Any luck?

For better or worse I can work around the problem like this:

$('code.html').each( function () {
      $(this).text( $(this).html());
});