-
Notifications
You must be signed in to change notification settings - Fork 262
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
Additional <thead>, <tr>, <th>, <td> attributes render #78
Conversation
@yuin This is right. This allows a user to override "align" attribute. But if they don't, "align" is rendered as before. |
Hi @zzwx |
I actually don't see that it's possible to remove this attribute easily, or block from final rendering. I add necessary to me func (c *globalMarkdownClassTransformer) Transform(node *ast.Document, reader text.Reader, pc parser.Context) {
ast.Walk(node, func(n ast.Node, entering bool) (status ast.WalkStatus, err error) {
if tableCell, ok := n.(*extAst.TableCell); ok {
if entering {
//tableCell.SetAttributeString("align", []byte(""))
if tableCell.Parent().Kind() == extAst.KindTableHeader || tableCell.Parent().Kind() == extAst.KindTableRow {
switch tableCell.Alignment {
case extAst.AlignRight:
tableCell.SetAttributeString("class", []byte("text-right"))
case extAst.AlignCenter:
tableCell.SetAttributeString("class", []byte("text-center"))
case extAst.AlignLeft:
tableCell.SetAttributeString("class", []byte("text-left"))
}
}
}
}
return ast.WalkContinue, nil
})
} The Any thoughts, @yuin? |
Thanks a lot for your answer. |
You can remove align attributes by replacing Currently, goldmark renders But it is sound better for me that built-in HTML renderer renders |
This is awesome @yuin, thank you! So basically this one of the ways to substitute align with class: func (c *globalMarkdownClassTransformer) Transform(node *ast.Document, reader text.Reader, pc parser.Context) {
ast.Walk(node, func(n ast.Node, entering bool) (status ast.WalkStatus, err error) {
if tableCell, ok := n.(*extAst.TableCell); ok {
if entering {
if tableCell.Parent().Kind() == extAst.KindTableHeader || tableCell.Parent().Kind() == extAst.KindTableRow {
switch tableCell.Alignment {
case extAst.AlignRight:
tableCell.SetAttributeString("class", []byte("text-right"))
case extAst.AlignCenter:
tableCell.SetAttributeString("class", []byte("text-center"))
case extAst.AlignLeft:
tableCell.SetAttributeString("class", []byte("text-left"))
}
//tableCell.SetAttributeString("align", []byte("")) // Won't work, still renders the "align", just without value
tableCell.Alignment = extAst.AlignNone // Make renderer forget about default "align" attribute
}
}
}
return ast.WalkContinue, nil
})
} |
Bumped into a couple of issues with table headers rendering and it required adding these attributes render.
In particular,
align
used in<tr>
misbehaved in my use case while working fine in<td
>.So I have to pass
class
attribute instead when necessary.Also
align
is marked as deprecated, although I don't think it was the reason for my issue.