Render Container - Only one class rendered #336

Open
opened 2026-01-29 14:34:08 +00:00 by claunia · 4 comments
Owner

Originally created by @LukeTOBrien on GitHub (Nov 23, 2019).

Hello,

It seems that when I create a container with more than one class, only the first class is rendered.

The following Markdown:

::: a-class another-class
:::

I would expect the following:

<div class="a-class another-class"></div>

Instead I am getting only the first class rendered.
I have created a .Net Fiddle to demo

I guess this is an issue with HtmlRenderer.WriteAttributes ?

Thanks

Originally created by @LukeTOBrien on GitHub (Nov 23, 2019). Hello, It seems that when I create a container with more than one class, only the first class is rendered. The following Markdown: ```markdown ::: a-class another-class ::: ``` I would expect the following: ```html <div class="a-class another-class"></div> ``` Instead I am getting only the first class rendered. I have created a [.Net Fiddle to demo](https://dotnetfiddle.net/hDyuZ3) I guess this is an issue with HtmlRenderer.WriteAttributes ? Thanks
claunia added the enhancementPR Welcome! labels 2026-01-29 14:34:08 +00:00
Author
Owner

@xoofx commented on GitHub (Nov 23, 2019):

It is currently by design, not an issue with WriteAttributes, but it is similar to code fence where the only first element is taken and the following are extra arguments, but in the case of container they are probably not used. I don't remember the full details, but feel free to open a PR with appropriate tests if you want this behavior (and I don't remember if it could bring another issue)

@xoofx commented on GitHub (Nov 23, 2019): It is currently by design, not an issue with WriteAttributes, but it is similar to code fence where the only first element is taken and the following are extra arguments, but in the case of container they are probably not used. I don't remember the full details, but feel free to open a PR with appropriate tests if you want this behavior (and I don't remember if it could bring another issue)
Author
Owner

@MihaZupan commented on GitHub (Nov 23, 2019):

As Alexandre said only the first item (the Info) is added as a class. The rest are added to the Arguments property, which is ignored when rendering HTML (but is exposed on the AST).

You can add them to the attributes like so:

foreach (var container in document.Descendants<CustomContainer>())
{
    if (!string.IsNullOrEmpty(container.Arguments))
    {
        var attributes = container.GetAttributes();
        foreach (var argument in container.Arguments.Split(' '))
        {
            if (argument.Length != 0)
            {
                attributes.AddClass(argument);
            }
        }
    }
}

An option to render arguments as classes could ofc be exposed if you think it is commonly desired behavior.

@MihaZupan commented on GitHub (Nov 23, 2019): As Alexandre said only the first item (the Info) is added as a class. The rest are added to the Arguments property, which is ignored when rendering HTML (but is exposed on the AST). You can add them to the attributes like so: ```c# foreach (var container in document.Descendants<CustomContainer>()) { if (!string.IsNullOrEmpty(container.Arguments)) { var attributes = container.GetAttributes(); foreach (var argument in container.Arguments.Split(' ')) { if (argument.Length != 0) { attributes.AddClass(argument); } } } } ``` An option to render arguments as classes could ofc be exposed if you think it is commonly desired behavior.
Author
Owner

@LukeTOBrien commented on GitHub (Nov 23, 2019):

Okay understood, thanks for the code snippet.
I could possibly have a go at adding this feature, it seems a shame to waste arguments.

@LukeTOBrien commented on GitHub (Nov 23, 2019): Okay understood, thanks for the code snippet. I could possibly have a go at adding this feature, it seems a shame to waste arguments.
Author
Owner

@xoofx commented on GitHub (Nov 23, 2019):

I could possibly have a go at adding this feature, it seems a shame to waste arguments.

Yeah, the rationale of the name of a container is like a method name, and the arguments are on the side. You could develop a renderer that interprets them differently of generate a different HTML. The fact that the name of the container is put as a class attribute is a default behavior for practical convenience. In case of adding arguments as class arguments as well is fine (for a default behavior), as long as we can switch it off by extension options.

@xoofx commented on GitHub (Nov 23, 2019): > I could possibly have a go at adding this feature, it seems a shame to waste arguments. Yeah, the rationale of the name of a container is like a method name, and the arguments are on the side. You could develop a renderer that interprets them differently of generate a different HTML. The fact that the name of the container is put as a `class` attribute is a default behavior for practical convenience. In case of adding arguments as class arguments as well is fine (for a default behavior), as long as we can switch it off by extension options.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/markdig#336