`)
}
for _, data := range devs {
if !(data.NSFW && !CFG.Nsfw) {
url := ParseMedia(data.Media)
if s.Atom {
id := strconv.Itoa(data.ID)
list.WriteString(`
`)
list.WriteString(data.Author.Username)
list.WriteString(``)
list.WriteString(data.Title)
list.WriteString(``)
list.WriteString(id)
list.WriteString(``)
list.WriteString(data.PublishedTime.UTC().Format("Mon, 02 Jan 2006 15:04:05 -0700"))
list.WriteString(``)
list.WriteString(``)
list.WriteString(data.Title)
list.WriteString(`
list.WriteString(url)
list.WriteString(`)
`)
list.WriteString(ParseDescription(data.TextContent))
list.WriteString(`
`)
} else {
list.WriteString(`
")
}
}
}
if s.Atom {
list.WriteString("")
s.Writer.Write([]byte(list.String()))
return ""
} else {
list.WriteString("
")
if content != nil {
list.WriteString(s.NavBase(content[0]))
}
}
return list.String()
}
/* DESCRIPTION/COMMENT PARSER */
type text struct {
TXT string
TXT_RAW string
From int
To int
}
func ParseDescription(dscr devianter.Text) string {
var parseddescription strings.Builder
TagBuilder := func(content string, tags ...string) string {
l := len(tags)
for x := 0; x < l; x++ {
var htm strings.Builder
htm.WriteString("<")
htm.WriteString(tags[x])
htm.WriteString(">")
htm.WriteString(content)
htm.WriteString("")
htm.WriteString(tags[x])
htm.WriteString(">")
content = htm.String()
}
return content
}
DeleteTrackingFromUrl := func(url string) string {
if len(url) > 42 && url[:42] == "https://www.deviantart.com/users/outgoing?" {
url = url[42:]
}
return url
}
if description, dl := dscr.Html.Markup, len(dscr.Html.Markup); dl != 0 &&
description[0] == '{' &&
description[dl-1] == '}' {
var descr struct {
Blocks []struct {
Text, Type string
InlineStyleRanges []struct {
Offset, Length int
Style string
}
EntityRanges []struct {
Offset, Length int
Key int
}
Data struct {
TextAlignment string
}
}
EntityMap map[string]struct {
Type string
Data struct {
Url string
Config struct {
Aligment string
Width int
}
Data devianter.Deviation
}
}
}
e := json.Unmarshal([]byte(description), &descr)
try(e)
entities := make(map[int]devianter.Deviation)
urls := make(map[int]string)
for n, x := range descr.EntityMap {
num, _ := strconv.Atoi(n)
if x.Data.Url != "" {
urls[num] = DeleteTrackingFromUrl(x.Data.Url)
}
entities[num] = x.Data.Data
}
for _, x := range descr.Blocks {
Styles := make([]text, len(x.InlineStyleRanges))
if len(x.InlineStyleRanges) != 0 {
var tags = make(map[int][]string)
for n, rngs := range x.InlineStyleRanges {
Styles := &Styles[n]
switch rngs.Style {
case "BOLD":
rngs.Style = "b"
case "UNDERLINE":
rngs.Style = "u"
case "ITALIC":
rngs.Style = "i"
}
Styles.From = rngs.Offset
Styles.To = rngs.Offset + rngs.Length
FT := Styles.From * Styles.To
tags[FT] = append(tags[FT], rngs.Style)
}
for n := 0; n < len(Styles); n++ {
Styles := &Styles[n]
Styles.TXT_RAW = x.Text[Styles.From:Styles.To]
Styles.TXT = TagBuilder(Styles.TXT_RAW, tags[Styles.From*Styles.To]...)
}
}
switch x.Type {
case "atomic":
d := entities[x.EntityRanges[0].Key]
parseddescription.WriteString(` ")
}
case html.TextToken:
parseddescription.Write(tt.Text())
}
}
}
return parseddescription.String()
}