Now that NSAttributedString is fully supported in iOS 6, is there a library that will take an NSString with markdown, and convert it to NSAttributedString?
7 Answers
I've just added an NSString
to NSAttributedString
lightweight markup parser to MGBoxKit. It's not Markdown but it's very similar. So far it supports bold, italics, underline, monospacing, text colour, background colour, and kerning.
The MGMushParser class is now a standalone pod, so can easily be used independent of MGBoxKit.
NSString *markup = @"**bold**, //italics//, __underlining__, `monospacing`, and {#0000FF|text colour}";
UIFont *baseFont = [UIFont fontWithName:@"HelveticaNeue" size:18];
UIColor *textColor = UIColor.whiteColor;
myLabel.attributedString = [MGMushParser attributedStringFromMush:markup
font:baseFont color:textColor];

- 1,626
- 15
- 28
-
1Thanks! Something like this is just what I was looking for. – adevine Mar 27 '13 at 16:12
-
1This looks to be it's new home: https://github.com/sobri909/MGMushParser – danfordham Mar 19 '15 at 09:54
-
Thanks @danfordham. I've edited the reply to use the correct link now. – sobri Mar 20 '15 at 08:35
I just open-sourced a project that takes raw markdown and converts it into an NSAttributedString:
https://github.com/dreamwieber/AttributedMarkdown
It's a work-in-progress and includes a demo application which shows how to assign attributes to the various markdown elements.

- 422
- 5
- 10
-
Very interesting. Is there also a function for doing the opposite: NSAttributedString to Markdown String? – Daniel Nordh Jan 21 '13 at 11:27
-
Thanks. Not at this time, but it is certainly something that could be added. – Dreamwieber Jan 21 '13 at 17:58
DTCoreText converts html to NSAttributedString, also OHAttributedLabel have some basic markdown support.

- 1,123
- 11
- 18
-
1Just a note if you need high performance do not use DTCoreText for HTML, it's still really inefficient for rendering/parsing. Use Bypass (ObjC) or Cocoa Markdown (swift) – Allison Feb 18 '18 at 16:36
For future reference, since this was the first post I found, you can now use NSAttributedString initWithData & NSDocumentTypeDocument to parse simple html on iOS 7
It seems easy enough to use a Markdown parser to HTML, then initWithData to do the rest. See http://initwithfunk.com/blog/2013/09/29/easy-markdown-rendering-with-nsattributedstring-on-ios-7.
For the HTML conversion, see my answer in ios7 font size change when create nsattributedstring from html

- 1
- 1

- 101
- 1
- 4
You can also have a look at https://github.com/xing/XNGMarkdownParser, works fast and reliably

- 467
- 3
- 13
-
This seemed like a great option, but links when formatted for markdown, did not work. – myData Feb 02 '15 at 19:24
-
[Reference-style links that is.](http://daringfireball.net/projects/markdown/basics) – myData Feb 02 '15 at 19:32
I was struggling a lot to fine full-Markdown library that it's easy to use and finally I found CocoaMarkdown.
It's really great, supports most of the syntax and have easy to use API. The only thing that was missing was image support, so I forked it and add full-image support, along with cacheing and enabling to use images wrapped in URLs, hope it will solve the problem I had for someone else:

- 1,493
- 14
- 21