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.
To run the example project, clone the repo, and run pod install from the Example directory first.
- iOS 8.0+
- Xcode 7.3+
CocoaPods 1.0.0+ is required to build MarkyMark
To integrate MarkyMark into your Xcode project using CocoaPods, specify it in your Podfile:
pod "markymark"let markyMark = MarkyMark(build: {
$0.setFlavor(ContentfulFlavor())
})
let markDownItems = markyMark.parseMarkDown("# Header\nParagraph")
var styling = DefaultStyling()
let configuration = MarkdownToViewConverterConfiguration(styling : styling)
let converter = MarkDownConverter(configuration:configuration)
let markDownView = converter.convert(markDownItems)
Headings
# H1
## H2
### H3
#### H4
##### H5
###### H6
Lists
- item
- item
* item
* item
+ item
+ item
a. item
b. item
1. item
2. item
Emphasis
*Em*
_Em_
**Strong**
__Strong__
~~Strike through~~
Images

Links
[Link text](https://www.example.net)
Code
`code`
```code```
Default Styling instance
var styling = DefaultStyling()
Changing the color of links
styling.linkStyling.textColor = .blueColor()
Setting fonts for headers
styling.headingStyling.fontsForLevels = [
UIFont.boldSystemFontOfSize(24), //H1
UIFont.systemFontOfSize(18), //H2
UIFont.systemFontOfSize(16) //H3
]
Adding margins
styling.paragraphStyling.contentInsets.bottom = 20
struct MarkDownStyling: Styling {
var headerStyling = HeaderStyling()
var paragraphStyling = ParagraphStyling()
var linkStyling = ListStyling()
}
Adding a new rule requires three new classes of based on the following protocol:
Rulethat can recoginizes the desired markdown syntaxMarkDownItemfor your new element that will be created by your new ruleLayoutBlockBuilderthat can convert your MarkDownItem to layout
Add the rule to MarkyMark
markyMark.addRule(MyCustomRule())
Add the block builder to your layout converter
converter.addLayoutBlockBuilder(MyCustomLayoutBlockBuilder())
If needed you can also add a custom styling class to the default styling
styling.addStyling(MyCustomStyling())
The converter has a callback method which is called every time a MarkDownItem is converted to layout.
converter.didConvertElement = {
markDownItem, view in
}
M2mobi, info@m2mobi.com
MarkyMark is available under the MIT license. See the LICENSE file for more info.


