MDHTMLLabel
MDHTMLLabel copied to clipboard
problems with certain HTML entities (ex: <)
MDHTMLLabel doesn't handle HTML entities, for example < and >
Say I want to display this exact string in MDHTMLLabel:
"1 < 2, I <3 MDHTMLLabel, 2 > 1"
label.htmlText = @"1 < 2, I <3 MDHTMLLabel, 2 > 1";
You can't. You'll end up with "1 1", see the attached screen shot.
It'd expected this to work:
label.htmlText = @"1 < 2, I <3 MDHTMLLabel, 2 > 1";
But it will appear the same!
The issue is here:
https://github.com/mattdonnelly/MDHTMLLabel/blob/master/MDHTMLLabel/MDHTMLLabel.m#L1339
The code is decoding the HTML entities before it finds styles and extract links.
I think the correct fix is to move the code to decode the HTML entities to after it finds styles and extract links. But just moving the code in MDHTMLLabel to decode the HTML after we do the detection won't work, as the offsets for all the links and style components will be incorrect.
Note that RTLabel seems to have a similar bug, see https://github.com/honcheng/RTLabel/pull/47
Keeping @aprato in the loop.
Sorry for not acknowledging this issue until now. I've got some exams coming up soon but will be happy to take a look in to this afterwards
@sspitzer @aprato @mattdonnelly I did a quick hack by replacing "<" and ">" to "≪" and "≫" before the link detection and then replacing them back later into "<" and ">".
Also in my use case i would like to disable auto link detection and let the class only detect links that i embeded in my NSString. So i added @property (nonatomic) BOOL autoDetectUrl; (default to NO in commonInit) and check if (self.autoDetectUrl) _htmlText = [self detectURLsInText:_htmlText];
@yinsee we ended up doing the same hack, but used "〈" and "〉"
@sspitzer nice :)
@yinsee thanks for the tip about disabling auto link detection, I think we will want that, too.
@yinsee created a PR with your idea, as we wanted the same thing, see https://github.com/mattdonnelly/MDHTMLLabel/pull/27
In our code, we do:
label.autoDetectUrls = NO;