From bfae5291a9f11fb6f0a5f18dc512481d5d3d6aa9 Mon Sep 17 00:00:00 2001 From: Wim Haanstra Date: Fri, 7 Feb 2014 09:04:35 +0100 Subject: [PATCH] Options for HTML Render HTML with options. --- Core/Source/DTAttributedTextCell.h | 9 +++++++++ Core/Source/DTAttributedTextCell.m | 9 +++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Core/Source/DTAttributedTextCell.h b/Core/Source/DTAttributedTextCell.h index 1adc57f0f..23a4c5fdb 100644 --- a/Core/Source/DTAttributedTextCell.h +++ b/Core/Source/DTAttributedTextCell.h @@ -47,6 +47,15 @@ */ - (void)setHTMLString:(NSString *)html; +/** + This method allows to set HTML text directly as content of the receiver. + + This will be converted to an attributed string. + @param html The HTML string to set as the receiver's text content + @param options The options used for rendering the HTML + */ +- (void) setHTMLString:(NSString *)html options:(NSDictionary*) options; + /** @name Getting Information diff --git a/Core/Source/DTAttributedTextCell.m b/Core/Source/DTAttributedTextCell.m index 744b3fc4e..8d34d99e2 100644 --- a/Core/Source/DTAttributedTextCell.m +++ b/Core/Source/DTAttributedTextCell.m @@ -194,7 +194,11 @@ - (void)setSelected:(BOOL)selected animated:(BOOL)animated - (void)setHTMLString:(NSString *)html { - // we don't preserve the html but compare it's hash + [self setHTMLString:html options:nil]; +} + +- (void) setHTMLString:(NSString *)html options:(NSDictionary*) options { + NSUInteger newHash = [html hash]; if (newHash == _htmlHash) @@ -205,10 +209,11 @@ - (void)setHTMLString:(NSString *)html _htmlHash = newHash; NSData *data = [html dataUsingEncoding:NSUTF8StringEncoding]; - NSAttributedString *string = [[NSAttributedString alloc] initWithHTMLData:data documentAttributes:NULL]; + NSAttributedString *string = [[NSAttributedString alloc] initWithHTMLData:data options:options documentAttributes:NULL]; self.attributedString = string; [self setNeedsLayout]; + } - (void)setAttributedString:(NSAttributedString *)attributedString