daltoniam/bumblebee

Style Markdown syntax *itself* [Question]

SHxKM opened this issue · 3 comments

SHxKM commented

A swift newbie so this more of a question than a bug/enhancement. This plugin is a potential life-saver for me, so thanks for making it!

Suppose I want to highlight an asterisk if there's at least one character between it and another asterisk. I'm talking about highlighting the Markdown syntax elements themselves. So in the case of the word "themselves" in the last sentence I want to style the asterisks in *themselves*, not the word itself.

I'm also wondering whether it's possible, after applying said filter, to also style the word afterwards.

Edit:

Just to be 100% clear, I might need those caluses to be independent: For example, *goo* would appear as the word goo in bold, and the asterisks would be in the color blue, not-emphasized.

Interesting use case. I thinking that would take some changes to how bumblebee works in order to achieve this. bumblebee does compound changes, but too independent actions on the same match isn't something it can do now. Would have to change the text manipulation to all ranged changes inside a match, would might be a cool feature to add.

SHxKM commented

Would have to change the text manipulation to all ranged changes inside a match, would might be a cool feature to add.

Thank you. I would obviously attempt to contribute if my knowledge wasn't so negligble.

Assuming I won't need the 2nd clause, meaning I only want to highlight the syntax elements (as long as they're valid), can that be done? so *hello would appear as *hello in the same color, but *hello* would have the asterisks in (say) red (and the word in regular colors)

Yeah, I think that should be easily doable with a small modification to the example code:

let bee = BumbleBee()

//our red text pattern
bee.add("*?*", recursive: false) { (pattern: String, text: String, start: Int) -> (String, [NSObject : AnyObject]?) in
    let replace = pattern[advancedBy(pattern.startIndex, 1)...advancedBy(pattern.endIndex, -2)]
    return (pattern,[NSForegroundColorAttributeName: UIColor.redColor()])
}

That should ignore something like *hello but turn *hello* turn (and not remove the asterisks).