evilstreak / markdown-js

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

compatibility with InDesign-flavored Javascript #39

Closed richardharrington closed 12 years ago

richardharrington commented 12 years ago

Hello,

I'm trying to port your script to InDesign-flavored Javascript. I think it would be really useful for a lot of people who are working in publishing contexts where they have to translate stuff back and forth between web and print.

I found to my delight that in basic cases, your script actually works out of the box, with one very tiny change: equals signs need to be escaped in regular expressions.

Then all that is necessary is to implement the ES5 forEach and isArray methods (easiest is to take the versions from the Mozilla Developer Network site) and then create a simple wrapper script, like

var exports = {};   
#include markdown.js   
var Markdown = exports.Markdown;

Then simple paragraphs are parsed fine. More complicated edge cases fail, unfortunately. The fixing of these bugs will probably necessitate changing your code so that it will break for users of the web and Node, and then I'd have to maintain a separate version, but hopefully not. I'll let you know.

In the meantime, if you could put this little change in with the equals signs, then other InDesign users who came across it would be able to tinker with it easily. I'll also send them your way.

Richard

ashb commented 12 years ago

So InDesign is doing The Wrong Thing somewhere, but escaping that for all other platforms doesn't do any harm.

You might be able to get away without the var exports = {}; since if exports is not defined we create a Markdown property on the window (a.k.a. global) object. This will depend on InDesign a bit.

richardharrington commented 12 years ago

Thanks!

Yes, InDesign does The Wrong Thing quite a lot. I was really surprised that those were the only changes I had to make.

The reason I created the exports object in the wrapper script is that there is no global window object in InDesign. I'm not sure if the global object has a name and can be referenced. Within each application (InDesign, Photoshop, etc.), there is an object called app, but they're not the same as the browser's window object.

I'll get to work on the edge-case discrepancies and see if I can fix them.

-- Richard