Hey, I’m trying to display some EE tags in my entry content but it’s converting the curly braces into their entities. The content field is is a textarea with the formatting set to Markdown and I’m using {exp:markdown} to generate the HTML.
I’ve tried converting them to their entities directly into the entry, I’ve tried adding a backslash to escape the braces. I’ve tried using {exp:markdown encode_ee_tags="no" smartypants="no"}
.
The only thing that seems to work is wrapping the block in [ code ]
blocks but then that modifies the HTML and adds a load of spans with inline color styles.
The braces have to be turned into entities so that tags do not get parsed in user input. Both the BBCode blocks and GitHub style code fences will allow you to legibly and safely display code samples in technical content. But it sounds like you are using your own syntax and highlighting method. Those should handle HTML entities in content, for example Rainbow.js.
Also if your field is already set with its formatting to be parsed with Markdown, you do not need to use the Markdown plugin tag in your template—you’ll be performing Markdown typography twice, which might be double-encoding your content.
Can you share your method of display and where it’s failing?
Thanks Derek, the issue with the encoding was to do with me performing the markdown typography twice. Although the issue still remains with ExpressionEngine inserting span tags with custom color styles.
I could just override the styles with !important
but that feels kind of hacky, I would rather EE just display the code as I wrote it if that’s possible without any syntax highlighting.
ExpressionEngine uses PHP’s highlight_string()
to perform syntax highlighting of code samples, so the output will depend on your environment. You can override PHP’s colors in your .htaccess
by modifying the related INI directives for syntax highlighting.
Alternatively, you do not have to use the syntax highlighting at all, and can output your code sample without a code fence or BBcode code block, which will let you use any syntax highlighting method you prefer.
You can just include it with whatever markup you like., e.g.:
<div class="code-sample">
<pre>
... your code sample here...
</pre>
<p></div>
ExpressionEngine won’t modify your markup or content in this instance, so essentially you’d be doing it exactly as you would if writing a static HTML page.
Thanks Derek, so I can’t used Markdown if I don’t want syntax highlighting?
I tried what you suggested with the following code:
<pre>
<div>
</div>
</pre>
<p>
But Markdown detected the indent and converted it into a code block, if that makes sense.
Edit: Detected the indent for the divs
It does make sense, but Markdown should leave your HTML intact. If you’re not seeing that, please put in a bug report with steps to reproduce.
FWIW, we have plans to remove the legacy PHP-based syntax highlighting, which should improve this all around.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.