Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HtmlRender.Render() not equivalent to Markdown.ToHtml() #595

Closed
jo3w4rd opened this issue Feb 8, 2022 · 2 comments
Closed

HtmlRender.Render() not equivalent to Markdown.ToHtml() #595

jo3w4rd opened this issue Feb 8, 2022 · 2 comments

Comments

@jo3w4rd
Copy link

jo3w4rd commented Feb 8, 2022

Are these expected to produce the same results? When using the PipeTables extension, Render() simply wraps the table cells in p tags (without and table, tbody, etc.). ToHtml() produces the full HTML table, as expected.

HtmlRender.Render() never hits a breakpoint in the HtmlTableRender.Write() method, whereas ToHtml() does. Am I missing a step for setting up the renderer object?

        public static void ParseMarkdown(string markdown)
        {
            var pipeline = new MarkdownPipelineBuilder().UsePipeTables().Build();
            MarkdownDocument md = Markdown.Parse(markdown, pipeline);
            var testStringA = md.ToHtml(pipeline);
            
            var stWriter = new StringWriter();
            var renderer = new HtmlRenderer(stWriter);
            renderer.Render(md);
            var testStringB = stWriter.ToString();
            
            Console.WriteLine(testStringA);
            Console.WriteLine(testStringB);
        }

(For context, I am exploring writing a different renderer.)

ToHTML() output (testStringA)

<h1>Table</h1>
<table>
<thead>
<tr>
<th><strong>Property</strong></th>
<th><strong>Description</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>Interaction Manager</strong></td>
<td>The <a href="xr-interaction-manager.md">XRInteractionManager</a> that this Interactable will communicate with (will find one if <strong>None</strong>).</td>
</tr>
<tr>
<td><strong>Interaction Layer Mask</strong></td>
<td>Allows interaction with Interactors whose <a href="interaction-layers.md">Interaction Layer Mask</a> overlaps with any Layer in this Interaction Layer Mask.</td>
</tr>
<tr>
<td><strong>Colliders</strong></td>
<td>Colliders to use for interaction with this Interactable (if empty, will use any child Colliders).</td>
</tr>
</tbody>
</table>

Render() (testStringB):

<h1>Table</h1>
<p><strong>Property</strong></p>
<p><strong>Description</strong></p>
<p><strong>Interaction Manager</strong></p>
<p>The <a href="xr-interaction-manager.md">XRInteractionManager</a> that this Interactable will communicate with (will find one if <strong>None</strong>).</p>
<p><strong>Interaction Layer Mask</strong></p>
<p>Allows interaction with Interactors whose <a href="interaction-layers.md">Interaction Layer Mask</a> overlaps with any Layer in this Interaction Layer Mask.</p>
<p><strong>Colliders</strong></p>
<p>Colliders to use for interaction with this Interactable (if empty, will use any child Colliders).</p>

Input markdown:

# Table

| **Property**               | **Description**                                                                                                                                   |
| -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Interaction Manager**    | The [XRInteractionManager](xr-interaction-manager.md) that this Interactable will communicate with (will find one if **None**).                   |
| **Interaction Layer Mask** | Allows interaction with Interactors whose [Interaction Layer Mask](interaction-layers.md) overlaps with any Layer in this Interaction Layer Mask. |
| **Colliders**              | Colliders to use for interaction with this Interactable (if empty, will use any child Colliders).                                                 |
@MihaZupan
Copy link
Collaborator

MihaZupan commented Feb 8, 2022

You were very close :)

var renderer = new HtmlRenderer(stWriter);
+pipeline.Setup(renderer);
renderer.Render(md);

Effectively, you weren't adding an HtmlTableRenderer to the HtmlRenderer, so there was no renderer accepting a Table element.

So if you were to write a custom table renderer, you most likely want to setup the HtmlRenderer and then replace the HtmlTableRenderer:

var renderer = new HtmlRenderer(stWriter);

pipeline.Setup(renderer);
renderer.ObjectRenderers.ReplaceOrAdd<HtmlTableRenderer>(MyNewTableRenderer);

renderer.Render(md);

@jo3w4rd
Copy link
Author

jo3w4rd commented Feb 8, 2022

Great, thank you!

@jo3w4rd jo3w4rd closed this as completed Feb 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants