dingus problems

(Comments)

Yesterday, I ran into a small, but confusing issue converting from markdown to html for a post. A markdown process will convert html in a code block to html escaped entities. That way, when you use the resulting html, your html example code doesn't get interpreted as html.

For example:

<p>This is a <strong>strong</strong> example.</p>

Gets converted to:

<pre><code>&lt;p&gt;This is a &lt;strong&gt;strong&lt;/strong&gt; example.&lt;/p&gt;
</code></pre>

In the "dingus" I made, this didn't appear to be happening. The above example rendered as:

<pre><code>This is a <strong>strong</strong> example.</p></code></pre>

Furthermore, it worked perfectly fine using the "official" php-markdown dingus. I was using their library, and it's incredibly simple to implement. After some digging, I discovered that in my dingus, the code was being converted properly in my preview section, but not in my HTML Source textarea. I was printing the same $render variable in both sections, but getting different results in my browser.

As it turns out, most html elements are "CDATA" and a textarea is "PCDATA". When all is said and done, this means that instead of needing to send <, I need to send &lt to the browser. Fortunately, php has a function called htmlspecialchars() that does this for me. For my HTML Output, I just needed to change print $render to print htmlspecialchars($render).

20120920

Currently unrated

Comments

Recent Posts

Archive

2017
2016
2015
2014
2013
2012
2011
2010
2009

Categories

Authors

Feeds

RSS / Atom