Skip to content
Browse files

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

  • Loading branch information...
1 parent baecbac commit 5959734c4e3768d1b4853e97bc98322772a71c5c @odrobnik odrobnik committed Dec 30, 2012
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;
}

0 comments on commit 5959734

Please sign in to comment.
Something went wrong with that request. Please try again.