Parsing Markdown on iOS

Is there any way (commercial or free) to convert Markdown to HTML on iOS?

I know of Christian’s MarkdownMBS plugin which works great for desktop but I need to do the same on iOS (my entire app idea hinges on it). The MBS plugins don’t work on iOS since there is no plugin architecture.

I’ve been trying to write my own Markdown parser in native Xojo to overcome this (source code of the work in progress here but essentially it’s not going to work for two reasons:

1). Markdown is insanely complex to parse
2). My native parser relies on RegEx (which itself is not available on iOS)

There are a million third party libraries for iOS that rapidly convert Markdown to HTML already available (e.g. in ObjC url=https://github.com/mdiep/MMMarkdown[/url], url=https://github.com/indragiek/CocoaMarkdown[/url] and in Swift).

Is it possible to use a static library on iOS somehow with Xojo or is there any way to port a Markdown library to one of the Xojo iOS libraries like iOSKit?

Thanks guys,

Maybe with ioshtmlviewer

Opening a html file with some javascript that paraes the markdown to html.

Markdown-js

@Garry Pettet: I’m not sure if this is an option for you, but you’re welcome to use it:

http://timdietrich.me/markdown/

It’s a simple API that you can use to convert Markdown to HTML. You just HTTP POST some Markdown to it and it returns the HTML.

It’s based on Parsedown, which was written in PHP. I’d love to convert it to Xojo at some point.

Anyway, it’s something to consider, and I hope this helps.

We have been told back in 2014 that Xojo could not link static libraries because of iOS 7 support. Since then, no news.

As far as I know iOS 7 has been abandoned… So ?

[quote=306431:@Michel Bujardet]We have been told back in 2014 that Xojo could not link static libraries because of iOS 7 support. Since then, no news.

As far as I know iOS 7 has been abandoned… So ?[/quote]

You know, the usual. We’ll have to wait for next year…sice that’s in about 2.5 hours from now…(in my timezone)…

[quote=306427:@Derk Jochems]Maybe with ioshtmlviewer

Opening a html file with some javascript that paraes the markdown to html.

Markdown-js[/quote]
Whilst that’s a hack - I really like the ingenuity of it. I think I’ll try and put some test code together to see if it’s possible…

[quote=306429:@Tim Dietrich]@Garry Pettet: I’m not sure if this is an option for you, but you’re welcome to use it:

http://timdietrich.me/markdown/

It’s a simple API that you can use to convert Markdown to HTML. You just HTTP POST some Markdown to it and it returns the HTML.

It’s based on Parsedown, which was written in PHP. I’d love to convert it to Xojo at some point.

Anyway, it’s something to consider, and I hope this helps.[/quote]
Thanks Tim. An equally valid solution but I’m hoping to be able to use the app offline as well as online so server parsing is not realistic. Nice implementation of Parsedown though. Be warned about parsing Markdown with Xojo though - my MarkdownKit is almost there (just a few more nasty regexes to write) but it is insanely mind-bendingly tricky to parse!

[quote=306431:@Michel Bujardet]We have been told back in 2014 that Xojo could not link static libraries because of iOS 7 support. Since then, no news.

As far as I know iOS 7 has been abandoned… So ?[/quote]

I dislike the two year silence on this. I’m sure it’s difficult to implement but allowing the inclusion of static libraries to iOS would open up a whole host of possibilities for Xojo development.

@Derk Jochems Looks like there’s no way to get the contents of the page with iOSHTMLViewer so a clever use of Javascript won’t help.

Looks like I’m SOL until Xojo get their act together and let us include static libraries on iOS…

[quote=306507:@Garry Pettet]@Derk Jochems Looks like there’s no way to get the contents of the page with iOSHTMLViewer so a clever use of Javascript won’t help.
[/quote]

Fortunately, Jason King has added cancelLoad and ExecuteJavaScript based on EvaluateJavaScript that returns a value, so you can indeed take advantage of that.

https://forum.xojo.com/19271-ios-what-we-want-roadmap/20

[quote=306507:@Garry Pettet]@Derk Jochems Looks like there’s no way to get the contents of the page with iOSHTMLViewer so a clever use of Javascript won’t help.

Looks like I’m SOL until Xojo get their act together and let us include static libraries on iOS…[/quote]

You should be able to get the content using a declare, i might have read that on the forums. Remember that js has the possibility to write files. You have the possibility to read files in xojo.

Have a good new year!

I have been using Jason’s declares in my last iOS app for all sorts of UI elements in an iOSHTMLViewer, such as a grid, image picker, and so on.

[quote=306514:@Michel Bujardet]Fortunately, Jason King has added cancelLoad and ExecuteJavaScript based on EvaluateJavaScript that returns a value, so you can indeed take advantage of that.

https://forum.xojo.com/19271-ios-what-we-want-roadmap/20[/quote]

@Michel Bujardet. Dumb question - the ExecuteJavaScript method returns a Text object. How do you get a Javascript script to return a value?

JavaScript does not have strong type. A numeric value is seen as a string as well.

When you expect a value, simply use Integer.FromText() or Double.FromText().

Thanks for all your help guys.

I’ve just put up a module on GitHub to convert Markdown to HTML and HTML back to Markdown. It uses Javascript embedded in an iOSHTMLViewer. It’s actually pretty fast (10 ms for a large document) and seems robust.

It’s currently iOS only although I have a working solution for desktops which I’m also about to publish.

I’ve also blogged about it here.