Skip to content

Instantly share code, notes, and snippets.

@AndyG
Last active March 2, 2018 02:28
Show Gist options
  • Save AndyG/912456bf61a444c4799172d12020bcd7 to your computer and use it in GitHub Desktop.
Save AndyG/912456bf61a444c4799172d12020bcd7 to your computer and use it in GitHub Desktop.
New Bold Rule
// **This text should be bold.**
val PATTERN_BOLD = Pattern.compile("^\\*\\*([\\s\\S]+?)\\*\\*(?!\\*)")
class BoldRule : Rule(PATTERN_BOLD) {
override fun parse(matcher: Matcher, parser: Parser): ParseSpec {
val boldNode = StyleNode(StyleSpan(Typeface.BOLD))
val innerParseStartIndex = matcher.start(1)
val innerParseEndIndex = matcher.end(1)
// Don't actually recursively parse, just return a ParseSpec that informs the Parser
// what work remains to be done
return ParseSpec.createNonterminal(boldNode, innerParseStartIndex, innerParseEndIndex)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment