Code Monkey home page Code Monkey logo

dctextengine's Introduction

DCTextEngine

An engine that convert text to attributed strings and attributed strings to text. Supports HTML and markdown by default. It is cross platform for iOS and OSX.

Dependencies

Requires CoreText.

Examples

NSString *string = @"#Dalton Cherry\n##Dalton Cherry\n*Lorem Ipsum* is simply _dummy_ text of the **printing** and typesetting industry. Lorem Ipsum has been the industry's standard *dummy* text ever since the 1500s. Here is a link to test with [Google](http://www.google.com/), should work fine. Here is a raw link: https://github.com. Hello at @austin, here is that email [email protected]. youtube video: http://www.youtube.com/watch?v=XibDfYd83Zg here is more text. Some more text";

DCTextEngine *engine = [DCTextEngine engineWithMarkdown];
__weak blockEngine = engine;
[engine addPattern:@"more text." found:^DCTextOptions*(NSString *regex, NSString *text){
    DCTextOptions *opts = [DCTextOptions new];
    NSTextAttachment *attach = [[NSTextAttachment alloc] init];
    attach.image = [UIImage imageNamed:@"subways.png"];
    attach.bounds = CGRectMake(0, 0, self.view.frame.size.width, 100);
    opts.attachment = attach;
    return opts;
}];
[engine addPattern:@"(^|\\s)@\\w+" found:^DCTextOptions*(NSString *regex, NSString *text){
    DCTextOptions *opts = [DCTextOptions new];
    opts.color = [UIColor redColor];
    opts.font = [blockEngine boldFont];
    return opts;
}];

alt tag

Notes

As the example shows, the engine has a very powerful parsing via regex, yet still being very simple to create the proper style. This engine will work on iOS 6, but you will be very limited on the style that can be applied. I strongly recommend using iOS 7 or above or at least 10.7 or above.

Contact

Dalton Cherry

dctextengine's People

Contributors

daltoniam avatar thorfroelich avatar heiberg avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.