
* Update build configuration * Update commonmark to 0.11.0 and android-gif to 1.2.14 * Add module `library-syntax` * Add default prism4j theme implementation * Add syntax highlight to sample app * Update syntax highlight to use SpannableStringBuilder * Working with syntax rendering * Add darkula theme to syntax highlight * Add attribute for image-loader module * Update version to 1.1.0-SNAPSHOT * Updating build configuration for snapshot publish * Add headingTypeface, headingTextSizes to SpannableTheme (#51) * Add headingTypeface to SpannableTheme, use a custom heading typeface in the sample app * Add headingTextSizes * Switching to headingTextSizeMultipliers, adding validating annotations, adding example * Consolidate logic, add crash if header index is out of bounds * Add small version clarifications * Introduce MediaDecoder abstraction for image-loader module * Switch to use SpannableFactory * Switch to use SpannableFactory for html parsing * Update sample application to add play-pause functionality for gifs * Small cleanup * Update prism4j version 1.1.0 * Update build configuration * Add README to library-syntax module * Update README
Markwon-syntax
This is a simple module to add syntax-highlight functionality to your markdown rendered with Markwon library. It is based on Prism4j so lead there to understand how to configure Prism4j
instance.
First, we need to obtain an instance of Prism4jSyntaxHighlight
which implements Markwon's SyntaxHighlight
:
final SyntaxHighlight highlight =
Prism4jSyntaxHighlight.create(Prism4j, Prism4jTheme);
we also can obtain an instance of Prism4jSyntaxHighlight
that has a fallback option (if a language is not defined in Prism4j
instance, fallback language can be used):
final SyntaxHighlight highlight =
Prism4jSyntaxHighlight.create(Prism4j, Prism4jTheme, String);
Generally obtaining a Prism4j
instance is pretty easy:
final Prism4j prism4j = new Prism4j(new GrammarLocatorDef());
Where GrammarLocatorDef
is a generated grammar locator (if you use prism4j-bundler
annotation processor)
Prism4jTheme
is a specific type that is defined in this module (prism4j
doesn't know anything about rendering). It has 2 implementations:
Prism4jThemeDefault
Prism4jThemeDarkula
Both of them can be obtained via factory method create
:
Prism4jThemeDefault.create()
Prism4jThemeDarkula.create()
But of cause nothing is stopping you from defining your own theme:
public interface Prism4jTheme {
@ColorInt
int background();
@ColorInt
int textColor();
void apply(
@NonNull String language,
@NonNull Prism4j.Syntax syntax,
@NonNull SpannableStringBuilder builder,
int start,
int end
);
}
You can extend
Prism4jThemeBase
which has some helper methods