Looking to create a custom renderer for unity TextMeshPro #322

Closed
opened 2026-01-29 14:33:46 +00:00 by claunia · 4 comments
Owner

Originally created by @tylkomat on GitHub (Sep 7, 2019).

I'm trying to create a custom renderer for unity TextMeshPro. Somehow I'm already failing at the beginning. Could you give me some hints why don't see any output from the parser?

I was looking at the HtmlRenderer and created a TextMeshProRenderer.

using System;
using System.IO;
using Markdig.Renderers;

public class TextMeshProRenderer: TextRendererBase<TextMeshProRenderer> {

  public TextMeshProRenderer(TextWriter writer): base(writer) {

    // Block renderers
    ObjectRenderers.Add(new HeadingRenderer());
    ObjectRenderers.Add(new ListRenderer());
    ObjectRenderers.Add(new ParagraphRenderer());

    // Inline renderers
  }
}

I was starting with the HeadingRenderer:

using UnityEngine;
using Markdig.Syntax;

public class HeadingRenderer : TextMeshProObjectRenderer<HeadingBlock> {

  protected override void Write(TextMeshProRenderer renderer, HeadingBlock obj) {

    int sizeIncrease = obj.Level * 2;

    renderer.Write("<size=+" + sizeIncrease.ToString() + ">");
    renderer.WriteLeafInline(obj);
    renderer.Write("</size>");

    renderer.EnsureLine();
  }
}

TextMeshProObjectRenderer:

using Markdig.Syntax;
using Markdig.Renderers;

public abstract class TextMeshProObjectRenderer<TObject>: MarkdownObjectRenderer<TextMeshProRenderer, TObject> where TObject: MarkdownObject {

}

When I parse a string like ## test. I only see <size=+4></size>.

Originally created by @tylkomat on GitHub (Sep 7, 2019). I'm trying to create a custom renderer for unity TextMeshPro. Somehow I'm already failing at the beginning. Could you give me some hints why don't see any output from the parser? I was looking at the HtmlRenderer and created a TextMeshProRenderer. ```c# using System; using System.IO; using Markdig.Renderers; public class TextMeshProRenderer: TextRendererBase<TextMeshProRenderer> { public TextMeshProRenderer(TextWriter writer): base(writer) { // Block renderers ObjectRenderers.Add(new HeadingRenderer()); ObjectRenderers.Add(new ListRenderer()); ObjectRenderers.Add(new ParagraphRenderer()); // Inline renderers } } ``` I was starting with the HeadingRenderer: ```c# using UnityEngine; using Markdig.Syntax; public class HeadingRenderer : TextMeshProObjectRenderer<HeadingBlock> { protected override void Write(TextMeshProRenderer renderer, HeadingBlock obj) { int sizeIncrease = obj.Level * 2; renderer.Write("<size=+" + sizeIncrease.ToString() + ">"); renderer.WriteLeafInline(obj); renderer.Write("</size>"); renderer.EnsureLine(); } } ``` TextMeshProObjectRenderer: ```c# using Markdig.Syntax; using Markdig.Renderers; public abstract class TextMeshProObjectRenderer<TObject>: MarkdownObjectRenderer<TextMeshProRenderer, TObject> where TObject: MarkdownObject { } ``` When I parse a string like `## test`. I only see `<size=+4></size>`.
claunia added the question label 2026-01-29 14:33:46 +00:00
Author
Owner

@MihaZupan commented on GitHub (Sep 7, 2019):

What was the expected output?

## test parses to a single heading, so only the heading renderer will be used.

Try testing with different input.

@MihaZupan commented on GitHub (Sep 7, 2019): What was the expected output? `## test` parses to a single heading, so only the heading renderer will be used. Try testing with different input.
Author
Owner

@tylkomat commented on GitHub (Sep 7, 2019):

The expected output would be <size=+4>test</size>

@tylkomat commented on GitHub (Sep 7, 2019): The expected output would be `<size=+4>test</size>`
Author
Owner

@MihaZupan commented on GitHub (Sep 7, 2019):

Ah, you don't have any inline renderers attached.
If you parse the markdown and look at the AST, you can check the .Inline collection on the heading block.
You need to add a LiteralInlineRenderer for basic text.

@MihaZupan commented on GitHub (Sep 7, 2019): Ah, you don't have any inline renderers attached. If you parse the markdown and look at the AST, you can check the `.Inline` collection on the heading block. You need to add a `LiteralInlineRenderer` for basic text.
Author
Owner

@tylkomat commented on GitHub (Sep 7, 2019):

I figured I would be something like this. Thanks.
If you don't want me to ask more questions without opening a new issue you may close it.

@tylkomat commented on GitHub (Sep 7, 2019): I figured I would be something like this. Thanks. If you don't want me to ask more questions without opening a new issue you may close it.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/markdig#322