markdown icon indicating copy to clipboard operation
markdown copied to clipboard

Code Block classes overwriting when language is annotated

Open ghost opened this issue 4 years ago • 1 comments

Hello guys! I found a bug with CodeBlock rendering. I want to add my own Class to the CodeBlock node so I add it like this:

node.Attribute = &ast.Attribute{
		Classes: [][]byte{[]byte("my-class")},
	}

But when a specific language is annotated in the code block in the md

```yml
text: something
another-text:
    depth: asd

Renderer overwrite my class and final result is this :

<pre><code class="language-yml">
text: something
another-text:
    depth: asd
</code></pre>

But should be this or something similar

<pre><code class="language-yml  my-class">
text: something
another-text:
    depth: asd
</code></pre>

ghost avatar Nov 25 '21 13:11 ghost

known bug - but should be fixed at some point:

// CodeBlock writes ast.CodeBlock node
func (r *Renderer) CodeBlock(w io.Writer, codeBlock *ast.CodeBlock) {
	var attrs []string
	// TODO(miek): this can add multiple class= attribute, they should be coalesced into one.
	// This is probably true for some other elements as well
	attrs = appendLanguageAttr(attrs, codeBlock.Info)

see html/renderer.go

miekg avatar Nov 30 '21 10:11 miekg