We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Display EE tags through Markdown

How Do I?

TIADigital's avatar
TIADigital
6 posts
9 years ago
TIADigital's avatar TIADigital

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.

       
Derek Jones's avatar
Derek Jones
7,561 posts
9 years ago
Derek Jones's avatar Derek Jones

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?

       
TIADigital's avatar
TIADigital
6 posts
9 years ago
TIADigital's avatar TIADigital

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.

       
Derek Jones's avatar
Derek Jones
7,561 posts
9 years ago
Derek Jones's avatar Derek Jones

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.

       
TIADigital's avatar
TIADigital
6 posts
9 years ago
TIADigital's avatar TIADigital

Thanks Derek, how would I go about outputting the code without any syntax highlighting?

       
Derek Jones's avatar
Derek Jones
7,561 posts
9 years ago
Derek Jones's avatar Derek Jones

You can just include it with whatever markup you like., e.g.:

<div class="code-sample">
    <pre>
        ... your code sample here...
    </pre>

<p></div>
</pre>

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.

       
TIADigital's avatar
TIADigital
6 posts
9 years ago
TIADigital's avatar TIADigital

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>
</pre>

But Markdown detected the indent and converted it into a code block, if that makes sense.

Edit: Detected the indent for the divs

       
Derek Jones's avatar
Derek Jones
7,561 posts
9 years ago
Derek Jones's avatar Derek Jones

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.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.