Skip to content

Commit

Permalink
Add support for Reader to default implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
DeDiamondPro committed Jul 21, 2024
1 parent 5e30551 commit b1733d6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,26 @@ import gg.essential.elementa.dsl.pixels
import gg.essential.universal.UMatrixStack
import org.commonmark.ext.gfm.strikethrough.StrikethroughExtension
import org.commonmark.ext.gfm.tables.TablesExtension
import java.io.Reader


/**
* A component to rendering markdown powered by MineMark
*/
class MineMarkComponent(
markdown: String,
style: MarkdownStyle = MarkdownStyle(),
core: MineMarkCore<MarkdownStyle, UMatrixStack> = defaultCore
) : UIComponent() {
val parsedMarkdown: MineMarkElement<MarkdownStyle, UMatrixStack> = core.parse(style, markdown).apply {
class MineMarkComponent(markdown: MineMarkElement<MarkdownStyle, UMatrixStack>) : UIComponent() {
constructor(
markdown: String,
style: MarkdownStyle = MarkdownStyle(),
core: MineMarkCore<MarkdownStyle, UMatrixStack> = defaultCore
) : this(core.parse(style, markdown))

constructor(
markdown: Reader,
style: MarkdownStyle = MarkdownStyle(),
core: MineMarkCore<MarkdownStyle, UMatrixStack> = defaultCore
) : this(core.parse(style, markdown))

val parsedMarkdown: MineMarkElement<MarkdownStyle, UMatrixStack> = markdown.apply {
addLayoutCallback(this@MineMarkComponent::layoutCallback)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
//#endif

import java.io.IOException;
import java.io.Reader;

public class MineMarkDrawable {
public static final MineMarkCore<MarkdownStyle, MarkdownRenderer> DEFAULT_CORE = addMinecraftExtensions(MineMarkCore.builder())
Expand All @@ -60,6 +61,18 @@ public MineMarkDrawable(String markdown) throws IOException, SAXException {
this(markdown, new MarkdownStyle());
}

public MineMarkDrawable(Reader markdown, MarkdownStyle style, MineMarkCore<MarkdownStyle, MarkdownRenderer> core) throws IOException, SAXException {
this(core.parse(style, markdown));
}

public MineMarkDrawable(Reader markdown, MarkdownStyle style) throws IOException, SAXException {
this(markdown, style, DEFAULT_CORE);
}

public MineMarkDrawable(Reader markdown) throws IOException, SAXException {
this(markdown, new MarkdownStyle());
}

public void draw(float x, float y, float width, float mouseX, float mouseY,
//#if MC >= 12000
DrawContext drawContext
Expand Down

0 comments on commit b1733d6

Please sign in to comment.