
* 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
76 lines
2.5 KiB
Java
76 lines
2.5 KiB
Java
package ru.noties.markwon.syntax;
|
|
|
|
import android.support.annotation.ColorInt;
|
|
import android.support.annotation.NonNull;
|
|
import android.support.annotation.Nullable;
|
|
import android.text.SpannableStringBuilder;
|
|
import android.text.Spanned;
|
|
import android.text.style.BackgroundColorSpan;
|
|
|
|
import ru.noties.markwon.spans.EmphasisSpan;
|
|
import ru.noties.markwon.spans.StrongEmphasisSpan;
|
|
|
|
public class Prism4jThemeDefault extends Prism4jThemeBase {
|
|
|
|
@NonNull
|
|
public static Prism4jThemeDefault create() {
|
|
return new Prism4jThemeDefault();
|
|
}
|
|
|
|
@Override
|
|
public int background() {
|
|
return 0xFFf5f2f0;
|
|
}
|
|
|
|
@Override
|
|
public int textColor() {
|
|
return 0xdd000000;
|
|
}
|
|
|
|
@NonNull
|
|
@Override
|
|
protected ColorHashMap init() {
|
|
return new ColorHashMap()
|
|
.add(0xFF708090, "comment", "prolog", "doctype", "cdata")
|
|
.add(0xFF999999, "punctuation")
|
|
.add(0xFF990055, "property", "tag", "boolean", "number", "constant", "symbol", "deleted")
|
|
.add(0xFF669900, "selector", "attr-name", "string", "char", "builtin", "inserted")
|
|
.add(0xFF9a6e3a, "operator", "entity", "url")
|
|
.add(0xFF0077aa, "atrule", "attr-value", "keyword")
|
|
.add(0xFFDD4A68, "function", "class-name")
|
|
.add(0xFFee9900, "regex", "important", "variable");
|
|
}
|
|
|
|
@Override
|
|
protected void applyColor(
|
|
@NonNull String language,
|
|
@NonNull String type,
|
|
@Nullable String alias,
|
|
@ColorInt int color,
|
|
@NonNull SpannableStringBuilder builder,
|
|
int start,
|
|
int end) {
|
|
|
|
if ("css".equals(language) && isOfType("string", type, alias)) {
|
|
super.applyColor(language, type, alias, 0xFF9a6e3a, builder, start, end);
|
|
builder.setSpan(new BackgroundColorSpan(0x80ffffff), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
return;
|
|
}
|
|
|
|
if (isOfType("namespace", type, alias)) {
|
|
color = applyAlpha(.7F, color);
|
|
}
|
|
|
|
super.applyColor(language, type, alias, color, builder, start, end);
|
|
|
|
if (isOfType("important", type, alias)
|
|
|| isOfType("bold", type, alias)) {
|
|
builder.setSpan(new StrongEmphasisSpan(), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
}
|
|
|
|
if (isOfType("italic", type, alias)) {
|
|
builder.setSpan(new EmphasisSpan(), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
}
|
|
}
|
|
}
|