@@ -120,67 +120,66 @@ - (NSString *)htmlString
120120 [htmlString appendString: @" \" >" ];
121121
122122 [self enumerateAttributesInRange: range
123- options: NSAttributedStringEnumerationLongestEffectiveRangeNotRequired
124- usingBlock: ^(NSDictionary *dictionary, NSRange range, BOOL *stop){
123+ options: NSAttributedStringEnumerationLongestEffectiveRangeNotRequired
124+ usingBlock: ^(NSDictionary *dictionary, NSRange range, BOOL *stop){
125125
126- NSMutableString *fontString = [NSMutableString string ];
127- UIFont *font = [dictionary objectForKey: NSFontAttributeName ];
128- UIColor *foregroundColor = [dictionary objectForKey: NSForegroundColorAttributeName ];
129- UIColor *backGroundColor = [dictionary objectForKey: NSBackgroundColorAttributeName ];
130- NSNumber *underline = [dictionary objectForKey: NSUnderlineStyleAttributeName ];
131- BOOL hasUnderline = (!underline || underline.intValue == NSUnderlineStyleNone) ? NO :YES ;
132- NSNumber *strikeThrough = [dictionary objectForKey: NSStrikethroughStyleAttributeName ];
133- BOOL hasStrikeThrough = (!strikeThrough || strikeThrough.intValue == NSUnderlineStyleNone) ? NO :YES ;
134-
135- [fontString appendFormat: @" <font " ];
136- [fontString appendFormat: @" face=\" %@ \" " , font.familyName];
137-
138- // Begin style
139- [fontString appendString: @" style=\" " ];
140-
141- [fontString appendFormat: @" font-size:%.0f px; " , font.pointSize];
142-
143- if (foregroundColor && [foregroundColor isKindOfClass: [UIColor class ]])
144- [fontString appendFormat: @" color:%@ ; " , [self htmlRgbColor: foregroundColor]];
145-
146- if (backGroundColor && [backGroundColor isKindOfClass: [UIColor class ]])
147- [fontString appendFormat: @" background-color:%@ ; " , [self htmlRgbColor: backGroundColor]];
148-
149- [fontString appendString: @" \" " ];
150- // End Style
151-
152- [fontString appendString: @" >" ];
153- [fontString appendString: [[self .string substringFromIndex: range.location] substringToIndex: range.length]];
154- [fontString appendString: @" </font>" ];
155-
156- if ([font isBold ])
157- {
158- [fontString insertString: @" <b>" atIndex: 0 ];
159- [fontString insertString: @" </b>" atIndex: fontString.length];
160- }
161-
162- if ([font isItalic ])
163- {
164- [fontString insertString: @" <i>" atIndex: 0 ];
165- [fontString insertString: @" </i>" atIndex: fontString.length];
166- }
167-
168- if (hasUnderline)
169- {
170- [fontString insertString: @" <u>" atIndex: 0 ];
171- [fontString insertString: @" </u>" atIndex: fontString.length];
172- }
173-
174- if (hasStrikeThrough)
175- {
176- [fontString insertString: @" <strike>" atIndex: 0 ];
177- [fontString insertString: @" </strike>" atIndex: fontString.length];
178- }
179-
180-
181- [htmlString appendString: fontString];
182-
183- }];
126+ NSMutableString *fontString = [NSMutableString string ];
127+ UIFont *font = [dictionary objectForKey: NSFontAttributeName ];
128+ UIColor *foregroundColor = [dictionary objectForKey: NSForegroundColorAttributeName ];
129+ UIColor *backGroundColor = [dictionary objectForKey: NSBackgroundColorAttributeName ];
130+ NSNumber *underline = [dictionary objectForKey: NSUnderlineStyleAttributeName ];
131+ BOOL hasUnderline = (!underline || underline.intValue == NSUnderlineStyleNone) ? NO :YES ;
132+ NSNumber *strikeThrough = [dictionary objectForKey: NSStrikethroughStyleAttributeName ];
133+ BOOL hasStrikeThrough = (!strikeThrough || strikeThrough.intValue == NSUnderlineStyleNone) ? NO :YES ;
134+
135+ [fontString appendFormat: @" <font " ];
136+ [fontString appendFormat: @" face=\" %@ \" " , font.familyName];
137+
138+ // Begin style
139+ [fontString appendString: @" style=\" " ];
140+
141+ [fontString appendFormat: @" font-size:%.0f px; " , font.pointSize];
142+
143+ if (foregroundColor && [foregroundColor isKindOfClass: [UIColor class ]])
144+ [fontString appendFormat: @" color:%@ ; " , [self htmlRgbColor: foregroundColor]];
145+
146+ if (backGroundColor && [backGroundColor isKindOfClass: [UIColor class ]])
147+ [fontString appendFormat: @" background-color:%@ ; " , [self htmlRgbColor: backGroundColor]];
148+
149+ [fontString appendString: @" \" " ];
150+ // End Style
151+
152+ [fontString appendString: @" >" ];
153+ [fontString appendString: [[self .string substringFromIndex: range.location] substringToIndex: range.length]];
154+ [fontString appendString: @" </font>" ];
155+
156+ if ([font isBold ])
157+ {
158+ [fontString insertString: @" <b>" atIndex: 0 ];
159+ [fontString insertString: @" </b>" atIndex: fontString.length];
160+ }
161+
162+ if ([font isItalic ])
163+ {
164+ [fontString insertString: @" <i>" atIndex: 0 ];
165+ [fontString insertString: @" </i>" atIndex: fontString.length];
166+ }
167+
168+ if (hasUnderline)
169+ {
170+ [fontString insertString: @" <u>" atIndex: 0 ];
171+ [fontString insertString: @" </u>" atIndex: fontString.length];
172+ }
173+
174+ if (hasStrikeThrough)
175+ {
176+ [fontString insertString: @" <strike>" atIndex: 0 ];
177+ [fontString insertString: @" </strike>" atIndex: fontString.length];
178+ }
179+
180+
181+ [htmlString appendString: fontString];
182+ }];
184183
185184 [htmlString appendString: @" </p>" ];
186185 }
0 commit comments