Parsing text from plist to NSAttributedString

I download the text from plist and show it in my application. Ideally, I want to be able to specify more complex formatting, such as italics, bold, and superscript text, and display it on a custom label such as TTTAttributedLabel .

Are there libraries available to parse strings in a given format (preferably a plain text format such as Markdown or Textile) in NSAttributedString? I know that RTF and HTML parsing solutions are available, but this is too much for my needs - plus I would like the text to be easily written by hand.

Edit: this is for iOS / UIKit

+4
source share
2 answers

I just added the lightweight NSString to NSAttributedString markup NSAttributedString to MGBoxKit . It is not Markdown or Textile, but it is very similar. While it supports bold, italics, underlining, monospaced, and color text.

The MGMushParser class can be used autonomously and is fairly easy to extend.

 NSString *markup = @"**bold**, //italics//, __underlining__, and `monospacing`, and {#0000FF|coloured text}"; UIFont *baseFont = [UIFont fontWithName:@"HelveticaNeue" size:18]; UIColor *textColor = UIColor.whiteColor; myLabel.attributedString = [MGMushParser attributedStringFromMush:markup font:baseFont color:textColor]; 

OHAttributedLabel also has a similar markup parser.

+1
source

Caught your editing. For iOS / UIKit, there is a project called NSAttributedString + HTML that tries to simulate the functionality available in OS X. In OS X, you just use some small HTML format to format the string and then parse it into NSAttributedString (or objects, or the web sites, or files, etc.).

The project I mentioned above is trying to offer the same extensions on iOS. I don’t know why, after 6 major releases of iOS, it still doesn’t have such rich tools and pushes all the weight towards UIWebView (on top of WebKit), but like that.

+3
source

Source: https://habr.com/ru/post/944238/


All Articles