Permalink
Browse files

fix whitespace handling for pre

  • Loading branch information...
odrobnik committed Dec 29, 2012
1 parent 8765391 commit 06764d7f09485bc75f3bdc16f8664bcc967021e2
Showing with 16 additions and 0 deletions.
  1. +16 −0 Core/Source/DTHTMLElementText.m
@@ -32,6 +32,22 @@ - (NSAttributedString *)attributedString
if (self.preserveNewlines)
{
text = _text;
+
+ // PRE ignores the first \n
+ if ([text hasPrefix:@"\n"])
+ {
+ text = [text substringFromIndex:1];
+ }
+
+ // PRE ignores the last \n
+ if ([text hasSuffix:@"\n"])
+ {
+ text = [text substringWithRange:NSMakeRange(0, [text length]-1)];
+ }
+
+ // replace paragraph breaks with line breaks
+ // useing \r as to not confuse this with line feeds, but still get a single paragraph
+ text = [text stringByReplacingOccurrencesOfString:@"\n" withString:@"\r"];
}
else
{

0 comments on commit 06764d7

Please sign in to comment.