leeoniya / reMarked.js

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

Bug with prototype.js #30

Closed SchumacherFM closed 10 years ago

SchumacherFM commented 10 years ago

Hi!

running the latest reMarked.js with prototype.js I'll get that error:

image

console.log in code:

image

My suggestion for a bugfix:

image

Would be nice if you can provide a fix ASAP as I want to release a new version of https://github.com/SchumacherFM/Magento-Markdown/

Thanks & Cheers!

leeoniya commented 10 years ago

it looks like you might be passing some Prototype-wrapped nodes rather than vanilla DOM, so the initial parsing gets screwed up. reMarked only accepts a plain DOM structure or HTML string, so you should first convert whatever you're passing to one of those. for example, jQuery has http://api.jquery.com/html/ to get an html string out of any jQuery-wrapped structure.

SchumacherFM commented 10 years ago

As you can see in this fiddle http://jsfiddle.net/schumacherfm/97HmX/3/ I'm passing a plain HTML string to reMarked.js.

Prototype extends all vanilla JavaScript functions.

So removing prototype.js will solve this bug. But because it is Magento I cannot remove prototype.js.

leeoniya commented 10 years ago

i suspect there would be additional places in the lib where this would break (as well as countless other libs). constructs like this are all over the web:

for (var i in someArray) {
    // whatever
}

there are a few options.

for (var key in p) {
    if (p.hasOwnProperty(key)) {
        // whatever
    }
}

while i hate to cater to libs which abusively extend native prototypes, i'll probably end up switching to regular for loops everywhere, since it's the most concise solution.

SchumacherFM commented 10 years ago

Thanks in advance for fixing :-)