chrisdevereux/Slash

Syntax error when calling attributedStringWithMarkup:style:error:

Closed this issue · 1 comments

Hello,

I need to create an attributed text with the following string : "> blabla <" with '>' and '<' in white and the rest in grey. So I tried to do it with the following code:

NSDictionary *style = @{@"$default" : @{NSFontAttributeName : myFont, NSForegroundColorAttributeName : UIColorFromRGB(0x414141)},
@"ch" : @{NSFontAttributeName : myFont, NSForegroundColorAttributeName :
UIColorFromRGB(0xFFFFFF)},};
NSString *markup = [NSString stringWithFormat:@">%@<", @"blabla"];
NSError *error;
_tapOnTheQuestionLabel.attributedText = [SLSMarkupParser attributedStringWithMarkup:markup style:style error:&error];
NSLog(@"ERROR : %@", error);

The printed error is the following: ERROR : Error Domain=SLSErrorDomain Code=1 "Syntax error" UserInfo=0xc16b7a0 {NSLocalizedDescription=Syntax error}

I guess the '<' and '>' characters are the root of the syntax error but I didn't manage to find to make it works. I tried escaping them but it's the same.

I also tried with the following :
const UniChar ch1 = 0x003e;
const UniChar ch2 = 0x003c;
NSString *markup = [NSString stringWithFormat:@"%C%@%C", ch1, @"blabla", ch2];

but it is still the same.

Do you have an idea how to fix that? Thanks a lot!

Looks like the lexer was sometimes treating unescaped backslashes as ordinary text. You should be able to escape properly using a backslash now.