Expose enabled block types in CorePlugin
This commit is contained in:
parent
ab83dad618
commit
a135e07f16
@ -6,6 +6,7 @@
|
|||||||
* `HtmlEmptyTagReplacement` now is configurable by `HtmlPlugin`, `iframe` handling ([#235])
|
* `HtmlEmptyTagReplacement` now is configurable by `HtmlPlugin`, `iframe` handling ([#235])
|
||||||
* `AsyncDrawableLoader` now uses `TextView` width without padding instead of width of canvas
|
* `AsyncDrawableLoader` now uses `TextView` width without padding instead of width of canvas
|
||||||
* Support for images inside table cells (`ext-tables` module)
|
* Support for images inside table cells (`ext-tables` module)
|
||||||
|
* expose `enabledBlockTypes` in `CorePlugin`
|
||||||
|
|
||||||
[#235]: https://github.com/noties/Markwon/issues/235
|
[#235]: https://github.com/noties/Markwon/issues/235
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ import androidx.annotation.NonNull;
|
|||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
|
|
||||||
|
import org.commonmark.node.Block;
|
||||||
import org.commonmark.node.BlockQuote;
|
import org.commonmark.node.BlockQuote;
|
||||||
import org.commonmark.node.BulletList;
|
import org.commonmark.node.BulletList;
|
||||||
import org.commonmark.node.Code;
|
import org.commonmark.node.Code;
|
||||||
@ -16,6 +17,7 @@ import org.commonmark.node.Emphasis;
|
|||||||
import org.commonmark.node.FencedCodeBlock;
|
import org.commonmark.node.FencedCodeBlock;
|
||||||
import org.commonmark.node.HardLineBreak;
|
import org.commonmark.node.HardLineBreak;
|
||||||
import org.commonmark.node.Heading;
|
import org.commonmark.node.Heading;
|
||||||
|
import org.commonmark.node.HtmlBlock;
|
||||||
import org.commonmark.node.Image;
|
import org.commonmark.node.Image;
|
||||||
import org.commonmark.node.IndentedCodeBlock;
|
import org.commonmark.node.IndentedCodeBlock;
|
||||||
import org.commonmark.node.Link;
|
import org.commonmark.node.Link;
|
||||||
@ -30,7 +32,10 @@ import org.commonmark.node.Text;
|
|||||||
import org.commonmark.node.ThematicBreak;
|
import org.commonmark.node.ThematicBreak;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import io.noties.markwon.AbstractMarkwonPlugin;
|
import io.noties.markwon.AbstractMarkwonPlugin;
|
||||||
import io.noties.markwon.MarkwonConfiguration;
|
import io.noties.markwon.MarkwonConfiguration;
|
||||||
@ -90,6 +95,23 @@ public class CorePlugin extends AbstractMarkwonPlugin {
|
|||||||
return new CorePlugin();
|
return new CorePlugin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return a set with enabled by default block types
|
||||||
|
* @since $nap;
|
||||||
|
*/
|
||||||
|
@NonNull
|
||||||
|
public static Set<Class<? extends Block>> enabledBlockTypes() {
|
||||||
|
return new HashSet<>(Arrays.asList(
|
||||||
|
BlockQuote.class,
|
||||||
|
Heading.class,
|
||||||
|
FencedCodeBlock.class,
|
||||||
|
HtmlBlock.class,
|
||||||
|
ThematicBreak.class,
|
||||||
|
ListBlock.class,
|
||||||
|
IndentedCodeBlock.class
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
// @since 4.0.0
|
// @since 4.0.0
|
||||||
private final List<OnTextAddedListener> onTextAddedListeners = new ArrayList<>(0);
|
private final List<OnTextAddedListener> onTextAddedListeners = new ArrayList<>(0);
|
||||||
|
|
||||||
|
@ -8,8 +8,14 @@ import android.widget.Toast;
|
|||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
import org.commonmark.node.Block;
|
||||||
|
import org.commonmark.node.BlockQuote;
|
||||||
import org.commonmark.node.Node;
|
import org.commonmark.node.Node;
|
||||||
|
import org.commonmark.parser.Parser;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import io.noties.markwon.AbstractMarkwonPlugin;
|
||||||
import io.noties.markwon.Markwon;
|
import io.noties.markwon.Markwon;
|
||||||
import io.noties.markwon.core.CorePlugin;
|
import io.noties.markwon.core.CorePlugin;
|
||||||
import io.noties.markwon.sample.ActivityWithMenuOptions;
|
import io.noties.markwon.sample.ActivityWithMenuOptions;
|
||||||
@ -26,7 +32,8 @@ public class CoreActivity extends ActivityWithMenuOptions {
|
|||||||
return MenuOptions.create()
|
return MenuOptions.create()
|
||||||
.add("simple", this::simple)
|
.add("simple", this::simple)
|
||||||
.add("toast", this::toast)
|
.add("toast", this::toast)
|
||||||
.add("alreadyParsed", this::alreadyParsed);
|
.add("alreadyParsed", this::alreadyParsed)
|
||||||
|
.add("enabledBlockTypes", this::enabledBlockTypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -132,4 +139,28 @@ public class CoreActivity extends ActivityWithMenuOptions {
|
|||||||
// apply parsed markdown
|
// apply parsed markdown
|
||||||
markwon.setParsedMarkdown(textView, spanned);
|
markwon.setParsedMarkdown(textView, spanned);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void enabledBlockTypes() {
|
||||||
|
|
||||||
|
final String md = "" +
|
||||||
|
"# Head\n\n" +
|
||||||
|
"> and disabled quote\n\n" +
|
||||||
|
"```\n" +
|
||||||
|
"yep\n" +
|
||||||
|
"```";
|
||||||
|
|
||||||
|
final Set<Class<? extends Block>> blocks = CorePlugin.enabledBlockTypes();
|
||||||
|
blocks.remove(BlockQuote.class);
|
||||||
|
|
||||||
|
final Markwon markwon = Markwon.builder(this)
|
||||||
|
.usePlugin(new AbstractMarkwonPlugin() {
|
||||||
|
@Override
|
||||||
|
public void configureParser(@NonNull Parser.Builder builder) {
|
||||||
|
builder.enabledBlockTypes(blocks);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.build();
|
||||||
|
|
||||||
|
markwon.setMarkdown(textView, md);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user