GitNex/app/src/main/java/org/mian/gitnex/helpers/codeeditor/markwon/MarkwonHighlighter.java
qwerty287 211fdab250 Move syntax highligting to codeview components (#1196)
TODO

- Issues of https://codeberg.org/gitnex-garage/useLangDefs

https://codeberg.org/gitnex/GitNex/issues/1180

Also see https://codeberg.org/gitnex-garage/useLangDefs

Co-authored-by: qwerty287 <ndev@web.de>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/1196
Reviewed-by: M M Arif <mmarif@noreply.codeberg.org>
Co-authored-by: qwerty287 <qwerty287@noreply.codeberg.org>
Co-committed-by: qwerty287 <qwerty287@noreply.codeberg.org>
2022-09-30 05:04:01 +02:00

48 lines
1.5 KiB
Java

package org.mian.gitnex.helpers.codeeditor.markwon;
import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import io.noties.markwon.AbstractMarkwonPlugin;
import io.noties.markwon.MarkwonConfiguration;
import io.noties.markwon.core.MarkwonTheme;
import org.mian.gitnex.helpers.codeeditor.theme.Theme;
/**
* @author qwerty287
*/
public class MarkwonHighlighter extends AbstractMarkwonPlugin {
private final Theme theme;
private final Context context;
private final String fallbackLanguage;
public MarkwonHighlighter(
Context context, @NonNull Theme theme, @Nullable String fallbackLanguage) {
this.theme = theme;
this.context = context;
this.fallbackLanguage = fallbackLanguage;
}
@NonNull public static MarkwonHighlighter create(Context context, @NonNull Theme theme) {
return create(context, theme, null);
}
@NonNull public static MarkwonHighlighter create(
Context context, @NonNull Theme theme, @Nullable String fallbackLanguage) {
return new MarkwonHighlighter(context, theme, fallbackLanguage);
}
@Override
public void configureTheme(@NonNull MarkwonTheme.Builder builder) {
builder.codeTextColor(context.getResources().getColor(theme.getDefaultColor(), null))
.codeBackgroundColor(
context.getResources().getColor(theme.getBackgroundColor(), null));
}
@Override
public void configureConfiguration(@NonNull MarkwonConfiguration.Builder builder) {
builder.syntaxHighlight(SyntaxHighlighter.create(context, theme, fallbackLanguage));
}
}