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

Escaping characters (angle brackets, etc.) in code blocks/snippets #400

Closed
devEngine opened this issue Jun 10, 2017 · 3 comments
Closed
Assignees

Comments

@devEngine
Copy link

devEngine commented Jun 10, 2017

I'm certain this has been asked elsewhere and/or described in some bit of documentation but I'm missing the solution and can't find it (I plead forgiveness in advance).

I've got template content which I load into a div as follows for which I use showdownjs to convert to html as follows:

<script>        
    (function (){
        var conv = new showdown.Converter();
        var txt = document.getElementById('article').innerHTML;              
        document.getElementById('article').innerHTML = conv.makeHtml(txt);
    })();
</script> 

This works pretty well except that any/all code snippets containing angle brackets for greater-than or less-than signs get HTML-escaped, thus:

< becomes &lt;
> becomes &gt;

and so on. Just for the record, such sections appear in markdown-compliant code outtakes (between the '```' markers) but these get escaped anyway. Would some kind soul please point me in the right direction as to how to workaround this?

Apologies as I don't want to create an issue where it's not warranted, but I can't seem to find the answer anywhere (don't think it's related to the HTML tag escaping issue: #374) but not sure.

Thanks in advance for any help.

@tivie tivie self-assigned this Jun 12, 2017
@tivie
Copy link
Member

tivie commented Jun 12, 2017

Hi @devEngine

It's like this by design and required by markdown spec, or else code snippets could end up messing the generated html.

All markdown implementations do this (check babelmark2

For instance:

```
</code></pre>
```

This would generate:

<pre><code>
</code></pre>
</code></pre>

In fact, it is required by HTML spec that, at least, < symbols should be escaped, even inside code blocks.

@devEngine
Copy link
Author

Thanks very much for your response - and I'm sure it's me missing something so apologies once again.

I have this in my original markdown content (between the 3 backticks):

{
     accountNum          =>    "$ENV/{HOME}/acct"
   , configFile               =>    "$ENV{HOME}/config"    
},

and no matter how I escape the brackets, I always end up getting from the converter:

{
     accountNum          =&gt;    "$ENV/{HOME}/acct"
   , configFile               =&gt;    "$ENV{HOME}/config"    
},

Any ideas how I should escape these to display the actual brackets?

@devEngine
Copy link
Author

Sorry, got it with reference to your helpful link. Thanks for your assistance!

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

No branches or pull requests

2 participants