zenity/internal/zencmd/markup.go

30 lines
457 B
Go
Raw Normal View History

2022-06-14 08:03:32 -04:00
package zencmd
import (
"encoding/xml"
"io"
"strings"
)
// StripMarkup is internal.
func StripMarkup(s string) string {
// Strips XML markup described in:
// https://docs.gtk.org/Pango/pango_markup.html
dec := xml.NewDecoder(strings.NewReader(s))
2022-12-20 07:23:15 -05:00
var res strings.Builder
2022-06-14 08:03:32 -04:00
for {
t, err := dec.Token()
if err == io.EOF {
2022-12-20 07:23:15 -05:00
return res.String()
2022-06-14 08:03:32 -04:00
}
if err != nil {
return s
}
if t, ok := t.(xml.CharData); ok {
2022-12-20 07:23:15 -05:00
res.Write(t)
2022-06-14 08:03:32 -04:00
}
}
}