Skip to content

Commit

Permalink
Allow Markdown parser to recognize <aside> as an infobox declaration.
Browse files Browse the repository at this point in the history
  • Loading branch information
cassierecher committed Jul 21, 2020
1 parent 286d7d8 commit 578cb8a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
12 changes: 12 additions & 0 deletions claat/parser/md/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,18 @@ Negative
: This will appear in a negative info box.
```

`<aside>` elements work as well:

```
<aside class="positive">
This will appear in a positive info box.
</aside>
<aside class="negative">
This will appear in a negative info box.
</aside>
```

#### Download Buttons

Codelabs sometimes contain links to SDKs or sample code. The codelab renderer
Expand Down
4 changes: 4 additions & 0 deletions claat/parser/md/html.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ func isButton(hn *html.Node) bool {
return hn.DataAtom == atom.Button
}

func isAside(hn *html.Node) bool {
return hn.DataAtom == atom.Aside
}

func isInfobox(hn *html.Node) bool {
if hn.DataAtom != atom.Dt {
return false
Expand Down
23 changes: 23 additions & 0 deletions claat/parser/md/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,8 @@ func parseNode(ds *docState) (types.Node, bool) {
return code(ds, true), true
case isCode(ds.cur):
return code(ds, false), true
case isAside(ds.cur):
return aside(ds), true
case isInfobox(ds.cur):
return infobox(ds), true
case isSurvey(ds.cur):
Expand Down Expand Up @@ -535,6 +537,27 @@ func header(ds *docState) types.Node {
return n
}

// aside produces an infobox.
func aside(ds *docState) types.Node {
kind := types.InfoboxPositive
for _, v := range ds.cur.Attr {
// If class "negative" is given, set the infobox type.
if v.Key == "class" && v.Val == "negative" {
kind = types.InfoboxNegative
}
}

ds.push(nil)
nn := parseSubtree(ds)
nn = blockNodes(nn)
nn = compactNodes(nn)
ds.pop()
if len(nn) == 0 {
return nil
}
return types.NewInfoboxNode(kind, nn...)
}

// infobox doesn't have a block parent.
func infobox(ds *docState) types.Node {
negativeInfoBox := isInfoboxNegative(ds.cur)
Expand Down

0 comments on commit 578cb8a

Please sign in to comment.