kmikael/KMMarkdownParser

语言: Objective-C

git: https://github.com/kmikael/KMMarkdownParser

一个简单的迷你降价归因于字符串转换器
A simple mini-markdown to attributed string converter
README.md (中文)

KMMarkdownParser

KMMarkdownParser是NSAttributedString转换器的一个非常简单的迷你降价。 span元素粗体(**),斜体(*),下划线(_),等宽 和链接(<url>和[title](url)变体),以及标题(#,##等) 目前支持。

用法

创建KMMarkdownParser的实例,可选择设置字体名称和大小, 然后调用attributionStringFromString:。 您的NSAttributedString已准备好在UILabel,UITextView等中使用。

KMMarkdownParser markdownParser = [[KMMarkdownParser alloc] init];
markdownParser.fontName = @"AvenirNext-Regular";
markdownParser.fontSize = 20.0;

NSString *markdownString = @"A `markdown` string with **bold** and *italic* text.";
self.textView.attributedText = [markdownParser attributedStringFromString:markdownString];

有关详细信息,请参阅示例项目,代码非常详细。

这是一些降价:

**Metamorphosis**

*Franz Kafka*

_Translated by David Wyllie_

**I**

One morning, when *Gregor Samsa* woke from _troubled dreams_,
he found himself *transformed* in his bed into **a horrible vermin**.
He lay on his armour-like back, and if he lifted his head a little **he could see his brown belly**,
slightly domed and divided by arches into stiff sections.
The bedding was hardly able to cover it and seemed ready to slide off any moment. **His many legs**,
pitifully thin compared with the size of the rest of him, waved about helplessly as he looked.

以下是使用KMMarkdownParser转换为NSAttributedString后的样子 并设置为UITextView的attributedText:

特约

  1. 叉吧
  2. 创建您的功能分支(git checkout -b my-new-feature)
  3. 提交你的更改(git commit -am'添加一些功能')
  4. 推送到分支(git push origin my-new-feature)
  5. 创建新的Pull请求

本文使用googletrans自动翻译,仅供参考, 原文来自github.com

en_README.md

KMMarkdownParser

KMMarkdownParser is a really simple mini-markdown to NSAttributedString converter.
The span elements bold (**), italic (*), underline (_), monospace
and links (both the <url> and [title](url) variants), as well as headers (#, ##, etc.)
are supported at the moment.

Usage

Create an instance of KMMarkdownParser, optionally set a font name and size,
then call attributedStringFromString:.
Your NSAttributedString is ready for use in a UILabel, UITextView etc.

KMMarkdownParser markdownParser = [[KMMarkdownParser alloc] init];
markdownParser.fontName = @"AvenirNext-Regular";
markdownParser.fontSize = 20.0;

NSString *markdownString = @"A `markdown` string with **bold** and *italic* text.";
self.textView.attributedText = [markdownParser attributedStringFromString:markdownString];

See the example project for more information, the code is extremely well-documented.

Example

Here is some markdown:

**Metamorphosis**

*Franz Kafka*

_Translated by David Wyllie_

**I**

One morning, when *Gregor Samsa* woke from _troubled dreams_,
he found himself *transformed* in his bed into **a horrible vermin**.
He lay on his armour-like back, and if he lifted his head a little **he could see his brown belly**,
slightly domed and divided by arches into stiff sections.
The bedding was hardly able to cover it and seemed ready to slide off any moment. **His many legs**,
pitifully thin compared with the size of the rest of him, waved about helplessly as he looked.

And here is what it looks like after converted into an NSAttributedString using KMMarkdownParser
and set as the attributedText of a UITextView:

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request