Skip to content

Commit

Permalink
add node attributes in VerbatimNode html converter
Browse files Browse the repository at this point in the history
  • Loading branch information
sivukhin committed Feb 24, 2024
1 parent 6c6256e commit 0c4d54d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
8 changes: 5 additions & 3 deletions djot_parser/djot_html.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,21 +106,23 @@ var DefaultConversionRegistry = map[DjotNode]Conversion{
},
VerbatimNode: func(s ConversionState, n func(c Children)) {
if _, ok := s.Node.Attributes.TryGet(djot_tokenizer.InlineMathKey); ok {
s.Writer.InTag("span", tokenizer.AttributeEntry{Key: "class", Value: "math inline"})(func() {
attributes := append([]tokenizer.AttributeEntry{{Key: "class", Value: "math inline"}}, s.Node.Attributes.Entries()...)
s.Writer.InTag("span", attributes...)(func() {
s.Writer.WriteString("\\(")
n(nil)
s.Writer.WriteString("\\)")
})
} else if _, ok := s.Node.Attributes.TryGet(djot_tokenizer.DisplayMathKey); ok {
s.Writer.InTag("span", tokenizer.AttributeEntry{Key: "class", Value: "math display"})(func() {
attributes := append([]tokenizer.AttributeEntry{{Key: "class", Value: "math display"}}, s.Node.Attributes.Entries()...)
s.Writer.InTag("span", attributes...)(func() {
s.Writer.WriteString("\\[")
n(nil)
s.Writer.WriteString("\\]")
})
} else if rawFormat := s.Node.Attributes.Get(RawInlineFormatKey); rawFormat == s.Format {
n(nil)
} else {
s.Writer.InTag("code")(func() { n(nil) })
s.Writer.InTag("code", s.Node.Attributes.Entries()...)(func() { n(nil) })
}
},
HeadingNode: func(s ConversionState, n func(c Children)) {
Expand Down
1 change: 1 addition & 0 deletions djot_parser/examples/inline-code-attributes.djot
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
inline `code`{#test}
1 change: 1 addition & 0 deletions djot_parser/examples/inline-code-attributes.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>inline <code id="test">code</code></p>

0 comments on commit 0c4d54d

Please sign in to comment.