Skip to content

Instantly share code, notes, and snippets.

@shibafu528
Created February 14, 2021 17:28
Show Gist options
  • Save shibafu528/521a58c652baf328b9ea7c755bc68aa5 to your computer and use it in GitHub Desktop.
Save shibafu528/521a58c652baf328b9ea7c755bc68aa5 to your computer and use it in GitHub Desktop.
@implementation Hoge
- (NSAttributedString *)expandAttributedContent {
DONStatusContentParser *parser = [[DONStatusContentParser alloc] initWithString:self.content];
[parser parse];
NSMutableAttributedString *body = [[NSMutableAttributedString alloc] initWithString:parser.textContent];
[parser.linkRanges enumerateObjectsUsingBlock:^(NSValue * _Nonnull value, NSUInteger idx, BOOL * _Nonnull stop) {
NSRange range = value.rangeValue;
[body addAttribute:NSLinkAttributeName value:[parser.textContent substringWithRange:range] range:range];
}];
if (self.spoilerText.length) {
[body insertAttributedString:[[NSAttributedString alloc] initWithString:self.spoilerText] atIndex:0];
return body;
} else {
return body;
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment