mirror of
https://github.com/rwinkhart/glamour-temp-MUTN.git
synced 2026-09-06 00:47:15 -04:00
Support rendering definition lists
This commit is contained in:
+27
@@ -299,6 +299,33 @@ func (tr *TermRenderer) NewElement(node ast.Node, source []byte) Element {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Definition Lists
|
||||||
|
case astext.KindDefinitionList:
|
||||||
|
e := &BlockElement{
|
||||||
|
Block: &bytes.Buffer{},
|
||||||
|
Style: cascadeStyle(ctx.blockStack.Current().Style, ctx.style[DefinitionList], true),
|
||||||
|
Margin: true,
|
||||||
|
}
|
||||||
|
return Element{
|
||||||
|
Entering: "\n",
|
||||||
|
Renderer: e,
|
||||||
|
Finisher: e,
|
||||||
|
}
|
||||||
|
|
||||||
|
case astext.KindDefinitionTerm:
|
||||||
|
return Element{
|
||||||
|
Renderer: &BaseElement{
|
||||||
|
Style: ctx.style[DefinitionTerm],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
case astext.KindDefinitionDescription:
|
||||||
|
return Element{
|
||||||
|
Renderer: &BaseElement{
|
||||||
|
Style: ctx.style[DefinitionDescription],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
// Handled by parents
|
// Handled by parents
|
||||||
case astext.KindTaskCheckBox:
|
case astext.KindTaskCheckBox:
|
||||||
// handled by KindListItem
|
// handled by KindListItem
|
||||||
|
|||||||
@@ -91,7 +91,10 @@ func (tr *TermRenderer) Render(in string) string {
|
|||||||
// RenderBytes returns the markdown rendered into a byte slice.
|
// RenderBytes returns the markdown rendered into a byte slice.
|
||||||
func (tr *TermRenderer) RenderBytes(in []byte) []byte {
|
func (tr *TermRenderer) RenderBytes(in []byte) []byte {
|
||||||
md := goldmark.New(
|
md := goldmark.New(
|
||||||
goldmark.WithExtensions(extension.GFM),
|
goldmark.WithExtensions(
|
||||||
|
extension.GFM,
|
||||||
|
extension.DefinitionList,
|
||||||
|
),
|
||||||
goldmark.WithParserOptions(
|
goldmark.WithParserOptions(
|
||||||
parser.WithAutoHeadingID(),
|
parser.WithAutoHeadingID(),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -54,6 +54,11 @@ const (
|
|||||||
TableBody
|
TableBody
|
||||||
TableRow
|
TableRow
|
||||||
|
|
||||||
|
// Definition Lists
|
||||||
|
DefinitionList
|
||||||
|
DefinitionTerm
|
||||||
|
DefinitionDescription
|
||||||
|
|
||||||
// HTML styles
|
// HTML styles
|
||||||
HTMLBlock
|
HTMLBlock
|
||||||
HTMLSpan
|
HTMLSpan
|
||||||
@@ -310,6 +315,12 @@ func keyToType(key string) (StyleType, error) {
|
|||||||
return TableBody, nil
|
return TableBody, nil
|
||||||
case "table_row":
|
case "table_row":
|
||||||
return TableRow, nil
|
return TableRow, nil
|
||||||
|
case "definition_list":
|
||||||
|
return DefinitionList, nil
|
||||||
|
case "definition_term":
|
||||||
|
return DefinitionTerm, nil
|
||||||
|
case "definition_description":
|
||||||
|
return DefinitionDescription, nil
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return 0, fmt.Errorf("invalid style element type: %s", key)
|
return 0, fmt.Errorf("invalid style element type: %s", key)
|
||||||
|
|||||||
Reference in New Issue
Block a user