xoofx / xoofx/markdig

HtmlInlineRenderer escape

Open
#707 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
Dominant language
C#
Stars
5.3k
Forks
510
Avg merge
8d 5h
Merged PRs (30d)
5

Description

Default implementation not using EnableHtmlEscape in HtmlInlineRenderer and HtmlBlockRenderer. I have a markdown like this:

This code defines a static class Connections that contains the following fields and methods:

- The NewCommand field, which is an EventHandler<Command> event. This event is raised when a new command is received from an IoT device.
- The Things field, which is a list of IoT objects. This list stores all connected IoT devices.

After default Markdown.ToHtml() <Command> is not escaped.

So I have to do a custom HtmlInlineRenderer that does renderer.WriteEscape


Why HtmlRenderer is not reusable? I would like to have a class member render to reuse it on each incoming text instead of creating 4 objects each time:

public string MakeMessage(string text)
        {
            var Writer = new StringWriter();
            var Render = new HtmlRenderer(Writer);

            Render.ObjectRenderers.Replace<HtmlBlockRenderer>(new CustomHtmlBlockRenderer());
            Render.ObjectRenderers.Replace<HtmlInlineRenderer>(new CustomHtmlInlineRenderer());

            Markdown.Convert(text, Render, Pipeline);

            return Writer.ToString();
        }

It would be nice to have Render.Reset()

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading HtmlInlineRenderer and HtmlBlockRenderer around EnableHtmlEscape, then inspect HtmlRenderer and Markdown.Convert for how renderer state is managed. Reproduce the unescaped example and examine whether renderer reuse is a separate concern. Done means the requested escaping behavior is defined and covered, with any reset or reuse behavior validated.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.