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 markdown syntax is easy to extend.
Example
To run the example project, clone the repo, and run pod install
from the Example directory first.
Requirements
- iOS 8.0+
- Xcode 8.0+
Installation
CocoaPods 1.0.0+ is required to build MarkyMark
To integrate MarkyMark into your Xcode project using CocoaPods, specify it in your Podfile
:
Alternatively, add MarkyMark to your project using Swift Package Manager using:
Simple usage
View with default styling
View with modified styling
Markymark has many styling options, please check the examples in the styling section of this readme. A simple example:
Supported tags in the Default Flavor
Note: Different tags can be supported by either extending the ContentfulFlavor (default) or by implementing a class that comforms to Flavor
and implement the required Rule
's
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```
Customizing default style
Default Styling instance
Paragraphs (regular text)
Markdown example: Some text
Headings
Markdown example: # Title
or ## Subtitle
etc.
linkStyling
Markdown Example [Google](http://www.google.com)
List styling
Markdown Example:
- List item 1
- List item 2
- Nested List item
Styling is also possible for:
styling.paragraphStyling
styling.italicStyling
styling.boldStyling
styling.strikeThroughStyling
styling.imageStyling
styling.linkStyling
styling.horizontalLineStyling
styling.codeBlockStyling
styling.inlineCodeBlockStyling
styling.quoteStyling
Please check the DefaultStyling
class for more information
Advanced usage
Advanced usage is only needed for very specific cases. Making subsets of styling, making different styling combinations, supporting different Markdown rules (syntax) or modifying certain views after that have been generated.
Custom styling objects
You can implement CustomHeaderStyling
by checking how other Styling
objects have been implemented, like ``HeaderStyling. Make sure your
CustomHeaderStylingcomforms to all styling rules you'd like your custom styling to support. i.e. comform to
TextColorStylingRule` to support textStyle of your custom styling.
Each styling rule can be applied to a markDownItem by comforming to ItemStyling
and implement the required method like this:
public func isApplicableOn(_ markDownItem: MarkDownItem) -> Bool {
return markDownItem is HeaderMarkDownItem
}
This will let the mechanism know it should apply your styling to a HeaderMarkDownItem
You can inject your new styling object by passing it to the constructor of the MarkdownTextView
MarkDownTextView(styling: CustomMarkyMarkStyling())
Adding your own rules
Adding a new rule requires three new classes of based on the following protocol:
Rule
that can recoginizes the desired markdown syntaxMarkDownItem
for your new element that will be created by your new ruleLayoutBlockBuilder
that can convert your MarkDownItem to layout
Add the rule to MarkyMark
Or when using the MarkdownTextView:
Add the block builder to your layout converter
Or when using the MarkdownTextView use either of these options (depending on the configuration view or attributedString):
If needed you can also add a custom styling class to the default styling
Converter hook
The converter has a callback method which is called every time a MarkDownItem
is converted to layout.
When using the MarkdownTextView
Link behavior
By default Markymark opens URL's using UIApplication.shared.delegate.open(_:open:options)
. links will only be openened when this method is implemented. Markymark allows changing this behavior by passing a custom URLOpener, an object that conforms to the URLOpener
protocol.
Using Markymark in Extensions
Markymark also supports usage the a Today extension. By default tapping url's is not working, since Extensions don't have access to UIApplication.shared, in order to support links you can pass a different url opener to a MarkyDownTextView. See the Example project for a working example:
Author
M2mobi, info@m2mobi.com
License
MarkyMark is available under the MIT license. See the LICENSE file for more info.