Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Remove whitespace at line end when adding \n before new block

  • Loading branch information...
commit 5959734c4e3768d1b4853e97bc98322772a71c5c 1 parent baecbac
@Cocoanetics authored
Showing with 16 additions and 0 deletions.
  1. +16 −0 Core/Source/DTHTMLAttributedStringBuilder.m
View
16 Core/Source/DTHTMLAttributedStringBuilder.m
@@ -744,6 +744,22 @@ - (void)parser:(DTHTMLParser *)parser didEndElement:(NSString *)elementName
if (nodeString)
{
+ // if this is a block element then we need a paragraph break before it
+ if (_currentTag.displayStyle != DTHTMLElementDisplayStyleInline)
+ {
+ if ([_tmpString length] && ![[_tmpString string] hasSuffix:@"\n"])
+ {
+ // trim off whitespace
+ while ([[_tmpString string] hasSuffixCharacterFromSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]])
+ {
+ [_tmpString deleteCharactersInRange:NSMakeRange([_tmpString length]-1, 1)];
+ }
+
+ [_tmpString appendString:@"\n"];
+ }
+ }
+
+
[_tmpString appendAttributedString:nodeString];
_currentTag.didOutput = YES;
}
Please sign in to comment.
Something went wrong with that request. Please try again.