Skip to content
Fetching contributors…
Cannot retrieve contributors at this time
61 lines (46 sloc) 1.63 KB
// NSAttributedString+HTML.m
// CoreTextExtensions
// Created by Oliver Drobnik on 1/9/11.
// Copyright 2011 All rights reserved.
#import <CoreText/CoreText.h>
#import <ApplicationServices/ApplicationServices.h>
#import "DTCoreText.h"
@implementation NSAttributedString (HTML)
- (id)initWithHTMLData:(NSData *)data documentAttributes:(NSDictionary **)docAttributes
return [self initWithHTMLData:data options:nil documentAttributes:docAttributes];
- (id)initWithHTMLData:(NSData *)data baseURL:(NSURL *)base documentAttributes:(NSDictionary **)docAttributes
NSDictionary *optionsDict = nil;
if (base)
optionsDict = [NSDictionary dictionaryWithObject:base forKey:NSBaseURLDocumentOption];
return [self initWithHTMLData:data options:optionsDict documentAttributes:docAttributes];
- (id)initWithHTMLData:(NSData *)data options:(NSDictionary *)options documentAttributes:(NSDictionary **)docAttributes
// only with valid data
if (![data length])
return nil;
DTHTMLAttributedStringBuilder *stringBuilder = [[DTHTMLAttributedStringBuilder alloc] initWithHTML:data options:options documentAttributes:docAttributes];
void (^callBackBlock)(DTHTMLElement *element) = [options objectForKey:DTWillFlushBlockCallBack];
if (callBackBlock)
[stringBuilder setWillFlushCallback:callBackBlock];
// This needs to be on a seprate line so that ARC can handle releasing the object properly
// return [stringBuilder generatedAttributedString]; shows leak in instruments
id string = [stringBuilder generatedAttributedString];
return string;
Jump to Line
Something went wrong with that request. Please try again.