Last active
March 2, 2018 02:28
-
-
Save AndyG/912456bf61a444c4799172d12020bcd7 to your computer and use it in GitHub Desktop.
New Bold Rule
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// **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