EllisLab text mark
Advanced Search
     
Markdown plugin doesn’t work for comments
Posted: 10 September 2008 02:54 PM
Avatar
Joined: 2003-09-24
166 posts

I would really like to use the WMD Markdown editor for comments on my site.  Markdown works great for stories and wiki entries, where it can be set as a default text format. I think Markdown is especially desirable for comments, because most commenters don’t know HTML.

To use Markdown for comments, you must put the following in your template:

{exp:markdown}{comment}{/exp:markdown} 

The problem is that there is no combination of comment preferences I can find that will result in correct HTML output from Markdown in a comment.

Here’s what you can tweak, as far as I can tell:

* Autolink URL’s and Email: ON/OFF

* HTML accepted: All/Safe/Convert to entities

* Comment text formatting: none/XHTML/</br>

So, there are at least 18 combinations of settings. I tested all that made sense and here is what I found.

1. The only combination that results in all Markdown working is: Autolinking OFF, HTML ALL, Formatting NONE

However, any raw URL’s input in this combination get processed by Markdown and turned into mush if they contain Markdown characters, such as underlines.

2. If I set HTML to “Convert to entities”, All Markdown except blockquote (important for comments) is OK, but URL’s are still processed.

3. In all other combinations of those settings, various Markdown features (blockquotes, links, images, lists) get turned off in what appears to be a pretty arbitrary fashion.

Are there any settings I’m missing, or should I just be waiting for EE to support Markdown in comments way that it does in other fields?

 
Posted: 10 September 2008 04:25 PM   [ # 1 ]   [ Rating: 0 ]
Joined: 2006-05-16
156 posts

Try Mark Huot’s Markypants plugin (http://ellislab.com/forums/viewthread/38866/), instead of simply Markdown. Markypants relies on you having the Markdown plugin and the SmartyPants (provides typography conversion) plugin installed.

Essentially, Markypants converts the text to HTML-safe entities using SmartyPants, then processes the results as Markdown. It works pretty well for me.

 
Posted: 10 September 2008 04:57 PM   [ # 2 ]   [ Rating: 0 ]
Avatar
Joined: 2003-09-24
166 posts

Markypants also seems to process what it sees as markdown code in raw URL’s, so this:

  http://coastsider.com/index.php/site/news/outsiders_are_not_to_blame_for_the_beachwood_bailout_failure/#6421

becomes this:

  http://coastsider.com/index.php/site/news/outsidersarenottoblameforthebeachwoodbailout_failure/#6421

 
Posted: 10 September 2008 05:36 PM   [ # 3 ]   [ Rating: 0 ]
Joined: 2006-05-16
156 posts

That’ll happen regardless of where the text is (comment or entry). You can use Markdown’s auto-URL making format:

<http://test.com/a_test_entry> 

…or escape the underlines with a backslash:

[http://test.com/a\_test\_entry](http://test.com/a_test_entry) 

From what I can tell, Markdown only converts the link text, not the link itself. Hope that helps…

 
Posted: 10 September 2008 08:33 PM   [ # 4 ]   [ Rating: 0 ]
Avatar
Joined: 2003-09-24
166 posts

Ah, so if the URL is enclosed in angle brackets, it should be linked, not parsed, by Markdown:

<http://coastsider.com/index.php/site/news/outsiders_are_not_to_blame_for_the_beachwood_bailout_failure/> 

This is confirmed by the parser on John Gruber’s site:

  http://daringfireball.net/projects/markdown/dingus

However, the EE Markdown plugin does not behave this way. It parses the characters inside the URL. You can see the result on the following wiki page:

  http://coastsider.com/index.php/insider/Markdown_Test/

Its processing of photos and blockquotes is also suboptimal or broken.

I don’t know if it’s the plugin or the original PHP code that’s at fault.  It’s beginning to feel like I will have to disable Markdown on my site.

Is the plugin working correctly for anyone?

 
Posted: 10 September 2008 09:43 PM   [ # 5 ]   [ Rating: 0 ]
Joined: 2006-05-16
156 posts

Placing a link with underscores in angle brackets works for me on my installation, using Markypants. I.e., this:

<http://test.com/a_test_entry/> 

…gets converted to this:

<a href="http://test.com/a_test_entry/">http://test.com/a_test_entry/</a> 

The text on your page hasn’t been converted to a link, which it should have, regardless if the underscores are parsed or not. Not sure what’s going on there. I use Markdown (Markypants) on most of my sites, but not on comments.

Have you tried escaping the underscores with a backslash, or even using another text formatting plugin like Textile?

 
Posted: 10 September 2008 11:11 PM   [ # 6 ]   [ Rating: 0 ]
Avatar
Joined: 2003-09-24
166 posts

Escaping the underscores would defeat my twin purposes of having easily-typed and more-readable text, so it’s a non-starter.

And I agree that angle-bracketing the url should create a linked version. This is a problem not just in comments, but in my wiki, which uses markdown as the default format. As you can see, the markdown blockquote parsing isn’t working either.

[I’m using the current versions of EE and the markdown pi.]

I may try Textile, but I’d really like to get Markdown working if I can.

 
Posted: 11 September 2008 04:42 AM   [ # 7 ]   [ Rating: 0 ]
Joined: 2006-05-16
156 posts

This code works fine on my website, again, using Markypants:

Here is a [test link](<http://test.com/a_test_entry_goes_here>). 

It produces:

Here is a <a href="http://test.com/a_test_link_goes_here">test link</a>. 

The gist of it all is that Markdown should ignore all formatting in the angle brackets, and if it’s a URL alone in angle brackets, it should create a link. Since your website is not creating a link at all when the URL is encapsulated in angle brackets, my guess is that something else is going on. But at the least I can confirm that the Markypants plugin works well for me in entries.

For comments, marking up a link in that manner (using Markdown only) leaves the entities, like so (the spaces are there to prevent EE from converting them back to angle brackets):

3Chttp://test.com/a_test_link_goes_here% 3E 

You could use the find/replace plugin to remove the entities.

Myself, I would just see about using the find/replace plugin and a regular expression to replace any <em> tags with underscores when found in a link.