leeoniya / reMarked.js

client-side HTML > markdown
http://leeoniya.github.io/reMarked.js/
396 stars 97 forks source link

Breaks on simple markdown #10

Closed bootstraponline closed 12 years ago

bootstraponline commented 12 years ago

Attempting to convert example.md produces many JavaScript errors. I've tried patching the library a bit, however it just uncovers more problems.

    function nodeName(e) {
// .nodeName can be undefined and with out this check nodeName breaks
    if (e.nodeName == undefined)
      return '';
    initK: function()
        {
            var i;
            if (this.e.hasChildNodes()) {  // has no method 'hasChildNodes'
leeoniya commented 12 years ago

Perhaps you are confused what this library is designed to do - it converts an existing DOM structure into markdown, not the other way around. If you want to convert markdown into DOM, you should look at another lib, like https://github.com/chjj/marked/

bootstraponline commented 12 years ago

Thanks for your response. I was passing in a string of HTML to convert to markdown instead of a DOM element.

leeoniya commented 12 years ago

This gave me a good idea, I should allow an html-string to be passed into reMarked.js and set that as the innerHtml of a dummy div to quickly parse it and produce the same markdown output. Low effort, high reward. Maybe a 3-liner patch tonight :D

bootstraponline commented 12 years ago

That'd be amazing.

bootstraponline commented 12 years ago

I tested out the change and it's so much better than what I was using before. The code examples now translate properly.

The only missing feature is GitHub Flavored Markdown tables as seen in example.md.

leeoniya commented 12 years ago

interesting. i haven't touched this project for a few months and they must have added a few more GFM features, including tables and some other stuff that wasn't there before: https://raw.github.com/suan/github-flavored-markdown-test/master/README.md

i was using this one for testing/reference previously: https://raw.github.com/mojombo/github-flavored-markdown/gh-pages/_site/sample_content.md http://github.github.com/github-flavored-markdown/sample_content.html

the tables look pretty quick to implement, i'll add them over the weekend.

bootstraponline commented 12 years ago

One aspect of tables that's not in those links is omitting leading pipes.

leeoniya commented 12 years ago

cool, thanks. do you have a link to the actual spec for this, or some official test markdown and output html samples? please link them under issue #12

bootstraponline commented 12 years ago

The spec is from PHP Markdown Extra. I've added a link to #12.