Skip to content
This repository was archived by the owner on Dec 16, 2025. It is now read-only.

Commit 6ab8fb3

Browse files
authored
Merge pull request #436 from cassierecher/aside
Allow Markdown parser to recognize <aside> as an infobox declaration.
2 parents 286d7d8 + 578cb8a commit 6ab8fb3

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

claat/parser/md/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,18 @@ Negative
9292
: This will appear in a negative info box.
9393
```
9494

95+
`<aside>` elements work as well:
96+
97+
```
98+
<aside class="positive">
99+
This will appear in a positive info box.
100+
</aside>
101+
102+
<aside class="negative">
103+
This will appear in a negative info box.
104+
</aside>
105+
```
106+
95107
#### Download Buttons
96108

97109
Codelabs sometimes contain links to SDKs or sample code. The codelab renderer

claat/parser/md/html.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ func isButton(hn *html.Node) bool {
9292
return hn.DataAtom == atom.Button
9393
}
9494

95+
func isAside(hn *html.Node) bool {
96+
return hn.DataAtom == atom.Aside
97+
}
98+
9599
func isInfobox(hn *html.Node) bool {
96100
if hn.DataAtom != atom.Dt {
97101
return false

claat/parser/md/parse.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,8 @@ func parseNode(ds *docState) (types.Node, bool) {
354354
return code(ds, true), true
355355
case isCode(ds.cur):
356356
return code(ds, false), true
357+
case isAside(ds.cur):
358+
return aside(ds), true
357359
case isInfobox(ds.cur):
358360
return infobox(ds), true
359361
case isSurvey(ds.cur):
@@ -535,6 +537,27 @@ func header(ds *docState) types.Node {
535537
return n
536538
}
537539

540+
// aside produces an infobox.
541+
func aside(ds *docState) types.Node {
542+
kind := types.InfoboxPositive
543+
for _, v := range ds.cur.Attr {
544+
// If class "negative" is given, set the infobox type.
545+
if v.Key == "class" && v.Val == "negative" {
546+
kind = types.InfoboxNegative
547+
}
548+
}
549+
550+
ds.push(nil)
551+
nn := parseSubtree(ds)
552+
nn = blockNodes(nn)
553+
nn = compactNodes(nn)
554+
ds.pop()
555+
if len(nn) == 0 {
556+
return nil
557+
}
558+
return types.NewInfoboxNode(kind, nn...)
559+
}
560+
538561
// infobox doesn't have a block parent.
539562
func infobox(ds *docState) types.Node {
540563
negativeInfoBox := isInfoboxNegative(ds.cur)

0 commit comments

Comments
 (0)