@@ -356,40 +356,24 @@ func (ctx *postProcessCtx) visitNode(node *html.Node, visitText bool) {
356
356
if attr .Key != "class" {
357
357
continue
358
358
}
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
367
375
}
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
391
376
}
392
- break
393
377
}
394
378
}
395
379
for n := node .FirstChild ; n != nil ; n = n .NextSibling {
0 commit comments