evilstreak / markdown-js

A Markdown parser for javascript
7.7k stars 863 forks source link

v0.6.0-beta1 don't run in browser #180

Closed fliiiix closed 10 years ago

fliiiix commented 10 years ago

I think this is mainly because exports is somewhere used. The error I got in my browser console is:

ReferenceError: exports is not defined

ashb commented 10 years ago

Can you confirm you used markdown-browser-0.6.0-beta1.tgz and not the non browser version?

fliiiix commented 10 years ago

Ups sorry, never mind :unamused: I got the wrong file in my first try.

kwisatz commented 10 years ago

I had the same issue with the markdown-browser-0.6.0-beta1.tgz package. It would seem that the non-minified version is not the correct one. The minified file works though.

SimplGy commented 10 years ago

http://cdnjs.com/libraries/markdown.js

The cdnjs version of this is the node version, not the browser version, so exports comes up as not defined.

ashb commented 10 years ago

@SimpleAsCouldBe I'm not sure who uploaded the version to cdnjs.com - it wasn't me or one of the other authors. Do you know who/how to contact to find out?

SimplGy commented 10 years ago

It looks like a fork+pull+request operation: https://github.com/cdnjs/cdnjs#adding-a-new-or-updating-an-existing-library

SimplGy commented 10 years ago

Any reason you don't use UMD or similar so that the builds are the same between node and browser? I imagine there are other blockers besides the module pattern used?

SimplGy commented 10 years ago

Didn't know there was a ritual roasters in London, @ashb

ashb commented 10 years ago

There isn't - I was out in SF when I snapped the pic and I liked it so much it became my avatar. Not least in part to mess with people I know in SF ;)

Hmm might be that a release to npm is all that is needed...?

As for UMD: I gave up years ago trying to figure out what module loaders work where and what the syntax was. Node worked, and including the file directly in a browser worked - that filled my need. If you can come up with a pull request that does UMD tidily without extra deps then we'll take it.

But mainly I despair at having to change my library to support another module loading format when module exports already exists and works :(

SimplGy commented 10 years ago

All the module formats can be annoying. I remember loving AMD while I was using it, but now I'm on Angular and that's a sloppy fit. Can't wait for ES6 and some standardization in the module space.

I think the only thing blocking the node version from working in browser is the exports keyword, isn't it? That UMD page is intimidatingly large, but I think it pretty much just shims define and exports so that AMD, CommonJS, and vanilla all work. Might be this simple:

if (typeof exports === 'object') {
    module.exports = MarkdownJS;
} else {
    window.MarkdownJS = MarkdownJS;
}

I'm sorry I don't PR it, but I don't have any immediate pain here, lack the server-side test case and experience, and won't get to share in the glory, fame, and riches that core contributors enjoy :)

Jakobud commented 9 years ago

What is the solution here? Where is the version that works in browsers? The CDNJS version still doesn't work in browsers after all this time.....

jaredatron commented 9 years ago

I added this version to my app on October 5th. Happy hunting