Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

line break tag replacement #40

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions RTLabelProject/Classes/RTLabel.m
Original file line number Diff line number Diff line change
Expand Up @@ -765,14 +765,14 @@ - (void)setHighlighted:(BOOL)highlighted

- (void)setHighlightedText:(NSString *)text
{
_highlightedText = [text stringByReplacingOccurrencesOfString:@"<br>" withString:@"\n"];
_highlightedText = [self replaceLineBreakTag:text];
RTLabelExtractedComponent *component = [RTLabel extractTextStyleFromText:_highlightedText paragraphReplacement:self.paragraphReplacement];
[self setHighlightedTextComponents:component.textComponents];
}

- (void)setText:(NSString *)text
{
_text = [text stringByReplacingOccurrencesOfString:@"<br>" withString:@"\n"];
_text = [self replaceLineBreakTag:text];
RTLabelExtractedComponent *component = [RTLabel extractTextStyleFromText:_text paragraphReplacement:self.paragraphReplacement];
[self setTextComponents:component.textComponents];
[self setPlainText:component.plainText];
Expand All @@ -781,15 +781,15 @@ - (void)setText:(NSString *)text

- (void)setText:(NSString *)text extractedTextComponent:(RTLabelExtractedComponent*)extractedComponent
{
_text = [text stringByReplacingOccurrencesOfString:@"<br>" withString:@"\n"];
_text = [self replaceLineBreakTag:text];
[self setTextComponents:extractedComponent.textComponents];
[self setPlainText:extractedComponent.plainText];
[self setNeedsDisplay];
}

- (void)setHighlightedText:(NSString *)text extractedTextComponent:(RTLabelExtractedComponent*)extractedComponent
{
_highlightedText = [text stringByReplacingOccurrencesOfString:@"<br>" withString:@"\n"];
_highlightedText = [self replaceLineBreakTag:text];
[self setHighlightedTextComponents:extractedComponent.textComponents];
}

Expand Down Expand Up @@ -1063,11 +1063,17 @@ - (NSString*)visibleText
return text;
}

- (NSString *)replaceLineBreakTag:(NSString *)text {
text = [text stringByReplacingOccurrencesOfString:@"<br>" withString:@"\n"];
text = [text stringByReplacingOccurrencesOfString:@"<br/>" withString:@"\n"];
return text;
}

#pragma mark deprecated methods

- (void)setText:(NSString *)text extractedTextStyle:(NSDictionary*)extractTextStyle
{
_text = [text stringByReplacingOccurrencesOfString:@"<br>" withString:@"\n"];
_text = [self replaceLineBreakTag:text];
[self setTextComponents:[extractTextStyle objectForKey:@"textComponents"]];
[self setPlainText:[extractTextStyle objectForKey:@"plainText"]];
[self setNeedsDisplay];
Expand Down