Skip to content

Commit 55c3e48

Browse files
committed
as per @guillep2k
Signed-off-by: Andrew Thornton <art27@cantab.net>
1 parent 1b1e7d9 commit 55c3e48

File tree

1 file changed

+16
-32
lines changed

1 file changed

+16
-32
lines changed

modules/markup/html.go

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -356,40 +356,24 @@ func (ctx *postProcessCtx) visitNode(node *html.Node, visitText bool) {
356356
if attr.Key != "class" {
357357
continue
358358
}
359-
// Got a class
360-
from := 0
361-
362-
for idx := strings.Index(attr.Val[from:], "icon") + from; idx >= from; {
363-
if (idx != 0 && attr.Val[idx-1] != ' ') ||
364-
(len(attr.Val) > idx+4 && attr.Val[idx+4] != ' ') {
365-
from = idx + 4
366-
continue
359+
classes := strings.Split(attr.Val, " ")
360+
for i, class := range classes {
361+
if class == "icon" {
362+
icon = true
363+
classes[0], classes[i] = classes[i], classes[0]
364+
attr.Val = strings.Join(classes, " ")
365+
366+
// Remove all children of icons
367+
child := node.FirstChild
368+
for child != nil {
369+
node.RemoveChild(child)
370+
child = child.NextSibling
371+
}
372+
node.FirstChild = nil
373+
node.LastChild = nil
374+
break
367375
}
368-
// We should be an icon
369-
end := idx + 4
370-
371-
// now need to move the icon class first...
372-
if idx != 0 && attr.Val[idx-1] == ' ' {
373-
idx--
374-
}
375-
class := "icon " + attr.Val[:idx]
376-
if len(attr.Val) > end+1 && attr.Val[end] == ' ' {
377-
class += " " + attr.Val[end:]
378-
}
379-
attr.Val = class
380-
381-
// Remove all children of icons
382-
child := node.FirstChild
383-
for child != nil {
384-
node.RemoveChild(child)
385-
child = child.NextSibling
386-
}
387-
node.FirstChild = nil
388-
node.LastChild = nil
389-
390-
break
391376
}
392-
break
393377
}
394378
}
395379
for n := node.FirstChild; n != nil; n = n.NextSibling {

0 commit comments

Comments
 (0)