From 587822d951aa8fbbcc46b8bae61dcaf78fc161d6 Mon Sep 17 00:00:00 2001 From: Claire Reynaud Date: Tue, 18 Apr 2017 15:42:28 +0200 Subject: [PATCH 1/2] Prepare to add missing support for tags is also a tag that should be interpreted as strikethrough. With strncmp, when a "s" tag is compared with "strong", it returns 0 because only 1 character is compared -> use strcmp instead. --- .../NSAttributedString+DDHTML.m | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/NSAttributedString+DDHTML/NSAttributedString+DDHTML.m b/NSAttributedString+DDHTML/NSAttributedString+DDHTML.m index 24f5d19..c4da7a3 100755 --- a/NSAttributedString+DDHTML/NSAttributedString+DDHTML.m +++ b/NSAttributedString+DDHTML/NSAttributedString+DDHTML.m @@ -125,33 +125,33 @@ + (NSAttributedString *)attributedStringFromNode:(xmlNodePtr)xmlNode normalFont: } // Bold Tag - if (strncmp("b", (const char *)xmlNode->name, strlen((const char *)xmlNode->name)) == 0 || - strncmp("strong", (const char *)xmlNode->name, strlen((const char *)xmlNode->name)) == 0) { + if (strcmp("b", (const char *)xmlNode->name) == 0 || + strcmp("strong", (const char *)xmlNode->name) == 0) { if (boldFont) { [nodeAttributedString addAttribute:NSFontAttributeName value:boldFont range:nodeAttributedStringRange]; } } // Italic Tag - else if (strncmp("i", (const char *)xmlNode->name, strlen((const char *)xmlNode->name)) == 0 || - strncmp("em", (const char *)xmlNode->name, strlen((const char *)xmlNode->name)) == 0) { + else if (strcmp("i", (const char *)xmlNode->name) == 0 || + strcmp("em", (const char *)xmlNode->name) == 0) { if (italicFont) { [nodeAttributedString addAttribute:NSFontAttributeName value:italicFont range:nodeAttributedStringRange]; } } // Underline Tag - else if (strncmp("u", (const char *)xmlNode->name, strlen((const char *)xmlNode->name)) == 0) { + else if (strcmp("u", (const char *)xmlNode->name) == 0) { [nodeAttributedString addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:nodeAttributedStringRange]; } // Stike Tag - else if (strncmp("strike", (const char *)xmlNode->name, strlen((const char *)xmlNode->name)) == 0) { + else if (strcmp("strike", (const char *)xmlNode->name) == 0) { [nodeAttributedString addAttribute:NSStrikethroughStyleAttributeName value:@(YES) range:nodeAttributedStringRange]; } // Stoke Tag - else if (strncmp("stroke", (const char *)xmlNode->name, strlen((const char *)xmlNode->name)) == 0) { + else if (strcmp("stroke", (const char *)xmlNode->name) == 0) { UIColor *strokeColor = [UIColor purpleColor]; NSNumber *strokeWidth = @(1.0); @@ -170,7 +170,7 @@ + (NSAttributedString *)attributedStringFromNode:(xmlNodePtr)xmlNode normalFont: } // Shadow Tag - else if (strncmp("shadow", (const char *)xmlNode->name, strlen((const char *)xmlNode->name)) == 0) { + else if (strcmp("shadow", (const char *)xmlNode->name) == 0) { #if __has_include() NSShadow *shadow = [[NSShadow alloc] init]; shadow.shadowOffset = CGSizeMake(0, 0); @@ -192,7 +192,7 @@ + (NSAttributedString *)attributedStringFromNode:(xmlNodePtr)xmlNode normalFont: } // Font Tag - else if (strncmp("font", (const char *)xmlNode->name, strlen((const char *)xmlNode->name)) == 0) { + else if (strcmp("font", (const char *)xmlNode->name) == 0) { NSString *fontName = nil; NSNumber *fontSize = nil; UIColor *foregroundColor = nil; @@ -230,7 +230,7 @@ + (NSAttributedString *)attributedStringFromNode:(xmlNodePtr)xmlNode normalFont: } // Paragraph Tag - else if (strncmp("p", (const char *)xmlNode->name, strlen((const char *)xmlNode->name)) == 0) { + else if (strcmp("p", (const char *)xmlNode->name) == 0) { NSMutableParagraphStyle *paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; if ([attributeDictionary objectForKey:@"align"]) { @@ -311,7 +311,7 @@ + (NSAttributedString *)attributedStringFromNode:(xmlNodePtr)xmlNode normalFont: // Links - else if (strncmp("a href", (const char *)xmlNode->name, strlen((const char *)xmlNode->name)) == 0) { + else if (strcmp("a href", (const char *)xmlNode->name) == 0) { xmlChar *value = xmlNodeListGetString(xmlNode->doc, xmlNode->xmlChildrenNode, 1); if (value) @@ -323,12 +323,12 @@ + (NSAttributedString *)attributedStringFromNode:(xmlNodePtr)xmlNode normalFont: } // New Lines - else if (strncmp("br", (const char *)xmlNode->name, strlen((const char *)xmlNode->name)) == 0) { + else if (strcmp("br", (const char *)xmlNode->name) == 0) { [nodeAttributedString appendAttributedString:[[NSAttributedString alloc] initWithString:@"\n"]]; } // Images - else if (strncmp("img", (const char *)xmlNode->name, strlen((const char *)xmlNode->name)) == 0) { + else if (strcmp("img", (const char *)xmlNode->name) == 0) { #if __has_include() NSString *src = attributeDictionary[@"src"]; NSString *width = attributeDictionary[@"width"]; From 6737ff00d13daf341ba7375d475c4d0f8ec704f8 Mon Sep 17 00:00:00 2001 From: Claire Reynaud Date: Tue, 18 Apr 2017 15:45:25 +0200 Subject: [PATCH 2/2] Add missing support for tags for strikethrough --- NSAttributedString+DDHTML/NSAttributedString+DDHTML.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/NSAttributedString+DDHTML/NSAttributedString+DDHTML.m b/NSAttributedString+DDHTML/NSAttributedString+DDHTML.m index c4da7a3..933467e 100755 --- a/NSAttributedString+DDHTML/NSAttributedString+DDHTML.m +++ b/NSAttributedString+DDHTML/NSAttributedString+DDHTML.m @@ -146,7 +146,8 @@ + (NSAttributedString *)attributedStringFromNode:(xmlNodePtr)xmlNode normalFont: } // Stike Tag - else if (strcmp("strike", (const char *)xmlNode->name) == 0) { + else if (strcmp("strike", (const char *)xmlNode->name) == 0 || + strcmp("s", (const char *)xmlNode->name) == 0) { [nodeAttributedString addAttribute:NSStrikethroughStyleAttributeName value:@(YES) range:nodeAttributedStringRange]; }