Skip to content
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

Use markdown frontmatter to provide Table of contents, language and frontmatter rendering #11047

Merged
merged 18 commits into from
Apr 24, 2020
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 15 additions & 32 deletions modules/markup/html.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,40 +356,23 @@ func (ctx *postProcessCtx) visitNode(node *html.Node, visitText bool) {
if attr.Key != "class" {
continue
}
// Got a class
from := 0

for idx := strings.Index(attr.Val[from:], "icon") + from; idx >= from; {
if (idx != 0 && attr.Val[idx-1] != ' ') ||
(len(attr.Val) > idx+4 && attr.Val[idx+4] != ' ') {
from = idx + 4
continue
classes := strings.Split(attr.Val, " ")
for i, class := range classes {
if class == "icon" {
classes[0], classes[i] = classes[i], classes[0]
attr.Val = strings.Join(classes, " ")

// Remove all children of icons
child := node.FirstChild
for child != nil {
node.RemoveChild(child)
child = child.NextSibling
}
node.FirstChild = nil
node.LastChild = nil
break
}
// We should be an icon
end := idx + 4

// now need to move the icon class first...
if idx != 0 && attr.Val[idx-1] == ' ' {
idx--
}
class := "icon " + attr.Val[:idx]
if len(attr.Val) > end+1 && attr.Val[end] == ' ' {
class += " " + attr.Val[end:]
}
attr.Val = class

// Remove all children of icons
child := node.FirstChild
for child != nil {
node.RemoveChild(child)
child = child.NextSibling
}
node.FirstChild = nil
node.LastChild = nil

break
}
break
}
}
for n := node.FirstChild; n != nil; n = n.NextSibling {
Expand Down