Improve latex entension plugin module
This commit is contained in:
parent
82fe43a921
commit
ba5bb9bfc7
@ -4,6 +4,7 @@ import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.Px;
|
||||
|
||||
import org.commonmark.node.Image;
|
||||
import org.commonmark.parser.Parser;
|
||||
@ -26,28 +27,56 @@ import ru.noties.markwon.image.MediaDecoder;
|
||||
import ru.noties.markwon.image.SchemeHandler;
|
||||
import ru.noties.markwon.priority.Priority;
|
||||
|
||||
/**
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public class JLatexMathPlugin extends AbstractMarkwonPlugin {
|
||||
|
||||
public interface BuilderConfigure {
|
||||
void configureBuilder(@NonNull Builder builder);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static JLatexMathPlugin create(float textSize) {
|
||||
return new JLatexMathPlugin(builder(textSize).build());
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static JLatexMathPlugin create(@NonNull Config config) {
|
||||
return new JLatexMathPlugin(config);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static JLatexMathPlugin create(float textSize, @NonNull BuilderConfigure builderConfigure) {
|
||||
final Builder builder = new Builder(textSize);
|
||||
builderConfigure.configureBuilder(builder);
|
||||
return new JLatexMathPlugin(builder.build());
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static JLatexMathPlugin.Builder builder(float textSize) {
|
||||
return new Builder(textSize);
|
||||
}
|
||||
|
||||
public static class Config {
|
||||
|
||||
protected final float textSize;
|
||||
private final float textSize;
|
||||
|
||||
protected Drawable background;
|
||||
private final Drawable background;
|
||||
|
||||
@JLatexMathDrawable.Align
|
||||
protected int align = JLatexMathDrawable.ALIGN_CENTER;
|
||||
private final int align;
|
||||
|
||||
protected boolean fitCanvas = true;
|
||||
private final boolean fitCanvas;
|
||||
|
||||
protected int padding;
|
||||
private final int padding;
|
||||
|
||||
public Config(float textSize) {
|
||||
this.textSize = textSize;
|
||||
Config(@NonNull Builder builder) {
|
||||
this.textSize = builder.textSize;
|
||||
this.background = builder.background;
|
||||
this.align = builder.align;
|
||||
this.fitCanvas = builder.fitCanvas;
|
||||
this.padding = builder.padding;
|
||||
}
|
||||
}
|
||||
|
||||
@ -144,4 +173,51 @@ public class JLatexMathPlugin extends AbstractMarkwonPlugin {
|
||||
public Priority priority() {
|
||||
return Priority.after(ImagesPlugin.class);
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
private final float textSize;
|
||||
|
||||
private Drawable background;
|
||||
|
||||
@JLatexMathDrawable.Align
|
||||
private int align = JLatexMathDrawable.ALIGN_CENTER;
|
||||
|
||||
private boolean fitCanvas = true;
|
||||
|
||||
private int padding;
|
||||
|
||||
Builder(float textSize) {
|
||||
this.textSize = textSize;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Builder background(@NonNull Drawable background) {
|
||||
this.background = background;
|
||||
return this;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Builder align(@JLatexMathDrawable.Align int align) {
|
||||
this.align = align;
|
||||
return this;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Builder fitCanvas(boolean fitCanvas) {
|
||||
this.fitCanvas = fitCanvas;
|
||||
return this;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Builder padding(@Px int padding) {
|
||||
this.padding = padding;
|
||||
return this;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Config build() {
|
||||
return new Config(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,9 @@ import ru.noties.markwon.AbstractMarkwonPlugin;
|
||||
import ru.noties.markwon.MarkwonVisitor;
|
||||
import ru.noties.markwon.SpannableBuilder;
|
||||
|
||||
/**
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public class TablePlugin extends AbstractMarkwonPlugin {
|
||||
|
||||
public interface ThemeConfigure {
|
||||
|
@ -2,7 +2,9 @@ package ru.noties.markwon.ext.tables;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Paint;
|
||||
import android.support.annotation.ColorInt;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Px;
|
||||
|
||||
import ru.noties.markwon.utils.ColorUtils;
|
||||
import ru.noties.markwon.utils.Dip;
|
||||
@ -121,37 +123,37 @@ public class TableTheme {
|
||||
private int tableHeaderRowBackgroundColor; // @since 1.1.1
|
||||
|
||||
@NonNull
|
||||
public Builder tableCellPadding(int tableCellPadding) {
|
||||
public Builder tableCellPadding(@Px int tableCellPadding) {
|
||||
this.tableCellPadding = tableCellPadding;
|
||||
return this;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Builder tableBorderColor(int tableBorderColor) {
|
||||
public Builder tableBorderColor(@ColorInt int tableBorderColor) {
|
||||
this.tableBorderColor = tableBorderColor;
|
||||
return this;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Builder tableBorderWidth(int tableBorderWidth) {
|
||||
public Builder tableBorderWidth(@Px int tableBorderWidth) {
|
||||
this.tableBorderWidth = tableBorderWidth;
|
||||
return this;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Builder tableOddRowBackgroundColor(int tableOddRowBackgroundColor) {
|
||||
public Builder tableOddRowBackgroundColor(@ColorInt int tableOddRowBackgroundColor) {
|
||||
this.tableOddRowBackgroundColor = tableOddRowBackgroundColor;
|
||||
return this;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Builder tableEvenRowBackgroundColor(int tableEvenRowBackgroundColor) {
|
||||
public Builder tableEvenRowBackgroundColor(@ColorInt int tableEvenRowBackgroundColor) {
|
||||
this.tableEvenRowBackgroundColor = tableEvenRowBackgroundColor;
|
||||
return this;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Builder tableHeaderRowBackgroundColor(int tableHeaderRowBackgroundColor) {
|
||||
public Builder tableHeaderRowBackgroundColor(@ColorInt int tableHeaderRowBackgroundColor) {
|
||||
this.tableHeaderRowBackgroundColor = tableHeaderRowBackgroundColor;
|
||||
return this;
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ import android.support.annotation.Nullable;
|
||||
import android.widget.TextView;
|
||||
|
||||
import ru.noties.markwon.Markwon;
|
||||
import ru.noties.markwon.core.CorePlugin;
|
||||
import ru.noties.markwon.ext.latex.JLatexMathPlugin;
|
||||
import ru.noties.markwon.image.ImagesPlugin;
|
||||
import ru.noties.markwon.sample.R;
|
||||
@ -40,17 +39,12 @@ public class LatexActivity extends Activity {
|
||||
// latex += "\\doublebox{\\text{A double framed box}}&\\ovalbox{\\text{An oval framed box}}\\cr";
|
||||
// latex += "\\end{array}";
|
||||
|
||||
|
||||
final JLatexMathPlugin.Config config = new JLatexMathPlugin.Config(textView.getTextSize()) {{
|
||||
// align = JLatexMathDrawable.ALIGN_RIGHT;
|
||||
}};
|
||||
|
||||
final String markdown = "# Example of LaTeX\n\n$$"
|
||||
+ latex + "$$\n\n something like **this**";
|
||||
|
||||
final Markwon markwon = Markwon.builder(this)
|
||||
.usePlugin(ImagesPlugin.create(this))
|
||||
.usePlugin(JLatexMathPlugin.create(config))
|
||||
.usePlugin(JLatexMathPlugin.create(textView.getTextSize()))
|
||||
.build();
|
||||
|
||||
markwon.setMarkdown(textView, markdown);
|
||||
|
Loading…
x
Reference in New Issue
Block a user