An Objective-C framework for converting Markdown to HTML.

Overview

MMMarkdown

MMMarkdown is an Objective-C framework for converting Markdown to HTML. It is compatible with OS X 10.7+, iOS 8.0+, tvOS, and watchOS.

Unlike other Markdown libraries, MMMarkdown implements an actual parser. It is not a port of the original Perl implementation and does not use regular expressions to transform the input into HTML. MMMarkdown tries to be efficient and minimize memory usage.

API

Using MMMarkdown is simple. The main API is a single class method:

#import <MMMarkdown/MMMarkdown.h>

NSError  *error;
NSString *markdown   = @"# Example\nWhat a library!";
NSString *htmlString = [MMMarkdown HTMLStringWithMarkdown:markdown error:&error];
// Returns @"<h1>Example</h1>\n<p>What a library!</p>"

The markdown string that is passed in must be non-nil.

MMMarkdown also supports a number of Markdown extensions:

#import <MMMarkdown/MMMarkdown.h>

NSString *markdown   = @"~~Mistaken~~";
NSString *htmlString = [MMMarkdown HTMLStringWithMarkdown:markdown extensions:MMMarkdownExtensionsGitHubFlavored error:NULL];
// Returns @"<p><del>Mistaken</del></p>"

Setup

Adding MMMarkdown to your project is easy.

If you’d like to use Carthage, add the following line to your Cartfile:

github "mdiep/MMMarkdown"

Otherwise, you can:

  1. Add MMMarkdown as a git submodule. (git submodule add https://github.com/mdiep/MMMarkdown <path>)

  2. Add MMMarkdown.xcodeproj to your project or workspace

  3. Add MMMarkdown.framework to the ”Link Binary with Libraries" section of your project's “Build Phases”.

  4. Add MMMarkdown.framework to a ”Copy Files” build phase that copies it to the Frameworks destination.

License

MMMarkdown is available under the MIT License.

Comments
  • Cocoapods Support

    Cocoapods Support

    It would be great if there was a public podspec available in order to include the library in a project.

    I lean towards avoiding git submodules.

    Many thanks in advance

    opened by a1cooke 11
  • GitHub Flavored Markdown

    GitHub Flavored Markdown

    Add support for GitHub Flavored Markdown.

    • [x] Autolinked URLs
    • [x] Fenced code blocks
    • [x] Hard newlines
    • [x] Strikethroughs
    • [x] Tables
    • [x] Underscores in words
    • [x] Inline word boundaries
    • [x] Update README
    opened by mdiep 11
  • Added Cocoapods podspec

    Added Cocoapods podspec

    Added from Specs-master/Specs/MMMarkdown/0.3/MMMarkdown.podspec.json.

    This allows those of us using cocoapods to manage dependencies to pull in the latest master commit of MMMarkdown. In order to to do that, the pod spec needs to be in the root of the repo as per http://guides.cocoapods.org/using/the-podfile.html#from-a-podspec-in-the-root-of-a-library-repo

    All I did was copy the existing pod spec from the Cocoapods master spec repo and put it in the root of the MMMarkdown repo. This allows me to use MMMarkdown in my project in one of two ways:

    # Use the latest GM release from cocoapods (currently version 0.3)
    pod 'MMMarkdown'
    
    # or use the latest commit to master
    pod 'MMMarkdown', :git => 'https://github.com/mdiep/MMMarkdown.git'
    

    I have tested both after the change and they both work so this is a low-risk merge.

    Thanks for MMMarkdown - I'm really enjoying using it! :-)

    opened by iosdev-republicofapps 9
  • Performance on iOS 8

    Performance on iOS 8

    It's taking to me rendering a simple markdown like 5 seconds on iOS 8. I've not tested it yet on previous iOS versions, but I guess this a performance leak on iOS 8, maybe NSAttributedString is kinda tricky now.

    I mean, not rendering it, but generating the NSAttributedString from the HTML. The conversion from raw Markdown to HTML is working fine, is quick. But when you have to get the NSAttributedString, oh boy, it takes like forever.

    Could you please look into it?

    Regards.

    opened by AlvaroFranco 9
  • Not converting markdown to html for Table

    Not converting markdown to html for Table

    Hello, I am using XCode 7.0 & using this library. I am trying to convert markdown to HTML string for Table. I am passing markdown tag for table as per the following.

    | Tables | Are | Cool | | --- | :-: | --: | | col 3 is | right-aligned | $1600 | | col 2 is | centered | $12 | | zebra stripes | are neat | $1 |

    But, Its not giving me proper HTML Output as per the following

    <table><thead><tr></tr></thead><tbody><tr></tr></tbody></table><p>|Tables|Are|Cool|<br />
    | ------------- | : ------------- : | ----- : |<br />
    | col 3 is | right-aligned | $1600 |<br />
    | col 2 is | centered | $12 |</p>
    
    opened by hardikpithadia 8
  • Lack of support for image links

    Lack of support for image links

    The following markdown should produce an image link:

    [![Werewolf Cop](http://ecx.images-amazon.com/images/I/51UENmW1sgL._SL175_.jpg)](http://www.amazon.com/exec/obidos/ASIN/1605986984/ref=nosim/founders-20)
    

    Like so: Werewolf Cop

    Instead, it produces the following: Werewolf Cop

    bug 
    opened by albertbori 8
  • not support objective-c block

    not support objective-c block

    @mdiep this framework doesn't support objective-c block. For example, I try to parse the following block with MMMarkdown, however it doesn't work.

    @interface ViewController ()
    @property (nonatomic, weak) IBOutlet UITextView *blockTextView;
    @end
    

    Could you please add this feature? GitHub support that. Thanks

    opened by xuguojun 6
  • Line breaks weird behavior.

    Line breaks weird behavior.

    Input: Lorem ipsum.\n \n Lorem ipsum. Output: <"p>Lorem ipsum.<"/p> <"p>Lorem ipsum.<"/p>

    Input: Lorem ipsum.\n \n \n Lorem ipsum. Output: <"p>Lorem ipsum.<"/p> <"p>Lorem ipsum.<"/p>

    So regardless of how much line breaks are entered, output is markdown without empty line.

    P.S There're no quotes inside paragraph tags in output, I've put them there to prevent github markdown parsing.

    opened by njuri 6
  • MMMarkdownExtensionsUnderscoresInWords should allow asterisks within words to still bold, italicize and bold italicize

    MMMarkdownExtensionsUnderscoresInWords should allow asterisks within words to still bold, italicize and bold italicize

    MMMarkdown diverges a bit from GFM with respect to underscores vs asterisks in words.

    In GFM, e.g. what I'm using to edit this issue notice that underscores are not italicized or bolded within a word:

    Hello__world__today is not bolded.
    // produces:
    

    Hello__world__today is not bolded.

    Whereas GFM does italicize or bold with asterisks within a word:

    Hello**world**today is bolded.
    // produces:
    

    Helloworldtoday is bolded.

    In the GitHub Flavored Markdown Reference they mention that underscores within words are not used for emphasis but that intra-word emphasis can still be achieved using asterisks.

    However, the MMMarkdown option MMMarkdownExtensionsUnderscoresInWords turns off both underscores and asterisks within words, whereas based on the name of the option and for consistency with GFM it seems like it should only turn off underscores and not asterisks within words.

    This impacts MMSpanParser._parseEmAndStrongWithScanner in a few places.

    I like the fact that underscores don't italicize/bold within words: that makes sense for variable names in text. But it would be nice if asterisks still worked. :-)

    Thoughts? :-)

    Thanks!

    bug 
    opened by iosdev-republicofapps 6
  • libMMMarkdown-iOS.a is showing red in Xcode

    libMMMarkdown-iOS.a is showing red in Xcode

    Hi, When I add libMMMarkdown-iOS.a in include libraries in my project ---> It appears as red. it means there is not library like this. Please help me how to include "libMMMarkdown-iOS.a" library in my project.

    In your MMMarkdown github folder also I am unable to find "libMMMarkdown-iOS.a" library. Please help me!!

    opened by amitch001 5
  • Add test for mathjax markup

    Add test for mathjax markup

    Some Markdown parsers I've found incorrectly convert _ to <em> and various other things. MMMarkdown doesn't (great!) but I thought it would be worth having a test to keep it this way

    http://www.mathjax.org/

    opened by techiaith 5
  • How to change font size?

    How to change font size?

    NSString *htmlString = [MMMarkdown HTMLStringWithMarkdown:article.text extensions:MMMarkdownExtensionsGitHubFlavored error:nil];

    The font size is too small. I want to make it larger by 5 points.

    opened by NikKovIos 0
  • Request ability to disable html pass through

    Request ability to disable html pass through

    I would like to ensure that the resulting output is strict and safe, and so would like to have an option which just eats all html (whether inline or block) in the source without passing it through to the result.

    opened by jpgoldberg 0
  • Confirm: versions of OSes

    Confirm: versions of OSes

    Hi,

    I just pushed version 0.5.5 of the podspec. While I was doing that I noticed that the README says:

    It is compatible with OS X 10.6+, iOS 8.0+, tvOS, and watchOS.

    Would it make sense to add the versions for tvOS and watchOS as in:

    It is compatible with OS X 10.6+, iOS 8.0+, tvOS 9.0+, and watchOS 2.0+.

    Just a thought.

    Cheers!

    opened by iosdev-republicofapps 1
Releases(0.5.5)
Owner
Matt Diephouse
Matt Diephouse
Convert text with HTML tags, links, hashtags, mentions into NSAttributedString. Make them clickable with UILabel drop-in replacement.

Atributika is an easy and painless way to build NSAttributedString. It is able to detect HTML-like tags, links, phone numbers, hashtags, any regex or

Pavel Sharanda 1.1k Jan 8, 2023
Easily show RichText(html) in SwiftUI

RichText LightMode DarkMode Code import SwiftUI

null 82 Jan 7, 2023
Methods to allow using HTML code with CoreText

DTCoreText This project aims to duplicate the methods present on Mac OSX which allow creation of NSAttributedString from HTML code on iOS. The project

Cocoanetics 6.2k Jan 6, 2023
A simple and customizable Markdown Parser for Swift

MarkdownKit MarkdownKit is a customizable and extensible Markdown parser for iOS and macOS. It supports many of the standard Markdown elements through

Bruno Oliveira 687 Dec 18, 2022
MarkdownView is a WKWebView based UI element, and internally use bootstrap, highlight.js, markdown-it.

MarkdownView is a WKWebView based UI element, and internally use bootstrap, highlight.js, markdown-it.

Keita Oouchi 1.8k Dec 21, 2022
Marky Mark is a parser written in Swift that converts markdown into native views.

Marky Mark is a parser written in Swift that converts markdown into native views. The way it looks it highly customizable and the supported markdown syntax is easy to extend.

M2mobi 287 Nov 29, 2022
Notepad - A fully themeable iOS markdown editor with live syntax highlighting.

Notepad is just like any other UITextView, but you need to use the convenience initializer in order to use the themes. To create a new theme, copy one of the existing themes and edit the JSON.

Rudd Fawcett 802 Dec 31, 2022
Markdown in SwiftUI, and some other interesting components.

RoomTime RoomTime is a bundle of tools developed in my app RoomTime Lite. ( ?? RoomTime Lite is still in development) Features TextArea AutoWrap Markd

Chen SiWei 56 Dec 20, 2022
Markdown parser for iOS

Marky Mark Marky Mark is a parser written in Swift that converts markdown into native views. The way it looks it highly customizable and the supported

M2mobi 254 Jun 11, 2021
Swift markdown library

Markdown ![Swift version](https://img.shields.io/badge/Swift-2.1 | 2.2-blue.svg) ![GitHub license](https://img.shields.io/badge/license-LGPL v3-green.

Crossroad Labs 79 Oct 9, 2022
A Pure Swift implementation of the markdown mark-up language

SmarkDown A pure Swift markdown implementation consistent with Gruber's 1.0.1 version. It is released under the BSD license so please feel free to use

Swift Studies 67 Jan 24, 2022
`resultBuilder` support for `swift-markdown`

SwiftMarkdownBuilder resultBuilder support for swift-markdown. The default way to build Markdown in swift-markdown is to use varargs initializers, e.g

DocZ 9 May 31, 2022
Leverages Apple's Swift-based Markdown parser to output NSAttributedString.

Markdownosaur ?? Markdownosaur uses Apple's excellent and relatively new Swift Markdown library to analyze a Markdown source, and then takes that anal

Christian Selig 232 Dec 20, 2022
AttributedString Markdown initializer with custom styling

AttributedString Markdown initializer with custom styling AttributedString in iOS 15 and macOS 12 comes with a Markdown initializer. But: There is no

Frank Rausch 41 Dec 19, 2022
Markdown syntax highlighter for iOS

Marklight Markdown syntax highlighter for iOS and macOS. Description Marklight is a drop in component to easily add realtime Markdown syntax highlight

Matteo Gavagnin 539 Dec 29, 2022
Rich Markdown editing control for iOS

MarkdownTextView Rich Markdown Editing for iOS MarkdownTextView is an iOS framework for adding rich Markdown editing capabilities. Support for Markdow

Indragie Karunaratne 676 Dec 7, 2022
Converts Markdown files and strings into NSAttributedStrings with lots of customisation options.

SwiftyMarkdown 1.0 SwiftyMarkdown converts Markdown files and strings into NSAttributedStrings using sensible defaults and a Swift-style syntax. It us

Simon Fairbairn 1.5k Dec 22, 2022
Markdown parsing and rendering for iOS and OS X

CocoaMarkdown Markdown parsing and rendering for iOS and macOS CocoaMarkdown is a cross-platform framework for parsing and rendering Markdown, built o

Indragie Karunaratne 1.2k Dec 12, 2022
Blazing fast Markdown / CommonMark rendering in Swift, built upon cmark.

Down Blazing fast Markdown (CommonMark) rendering in Swift, built upon cmark v0.29.0. Is your app using it? Let us know! If you're looking for iwasrob

John Nguyen 2k Dec 19, 2022