Skip to content

Commit f67948a

Browse files
committed
appstream-helper.go: html -> txt
Signed-off-by: xplshn <anto@xplshn.com.ar>
1 parent f547f90 commit f67948a

File tree

1 file changed

+35
-5
lines changed

1 file changed

+35
-5
lines changed

cmd/misc/appstream-helper/appstream-helper.go

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import (
2222
"github.com/shamaton/msgpack/v2"
2323
"github.com/zeebo/blake3"
2424

25+
"github.com/jaytaylor/html2text"
26+
2527
"github.com/xplshn/pelf/pkg/utils"
2628
)
2729

@@ -371,7 +373,7 @@ func main() {
371373
appBundleID, err := utils.ParseAppBundleID(appBundleInfo.AppBundleID)
372374
if err == nil && appBundleID.Compliant() == nil {
373375
pkg = appBundleID.Name + "." + appBundleInfo.FilesystemType + ".AppBundle"
374-
pkgId = ternary(appBundleID.Repo != "", appBundleID.Repo, "github.com.xplshn.appbundlehub." + appBundleID.ShortName())
376+
pkgId = ternary(appBundleID.Repo != "", appBundleID.Repo, "github.com.xplshn.appbundlehub."+appBundleID.ShortName())
375377
} else {
376378
pkgId = strings.TrimSuffix(baseFilename, filepath.Ext(baseFilename+"."+appBundleInfo.FilesystemType))
377379
pkg = baseFilename
@@ -416,10 +418,24 @@ func main() {
416418
item.Screenshots = appData.Screenshots
417419
}
418420
if appData.Summary != "" {
419-
item.Description = appData.Summary
421+
// Convert Summary to plain text
422+
summaryText, err := html2text.FromString(appData.Summary, html2text.Options{PrettyTables: true})
423+
if err != nil {
424+
log.Printf("%swarning%s failed to convert Summary to plain text for %s%s%s: %v", warningColor, resetColor, blueColor, path, resetColor, err)
425+
item.Description = appData.Summary // Fallback to raw summary
426+
} else {
427+
item.Description = summaryText
428+
}
420429
}
421430
if appData.RichDescription != "" {
422-
item.LongDescription = appData.RichDescription
431+
// Convert RichDescription to plain text
432+
richDescText, err := html2text.FromString(appData.RichDescription, html2text.Options{PrettyTables: true})
433+
if err != nil {
434+
log.Printf("%swarning%s failed to convert RichDescription to plain text for %s%s%s: %v", warningColor, resetColor, blueColor, path, resetColor, err)
435+
item.LongDescription = appData.RichDescription // Fallback to raw HTML
436+
} else {
437+
item.LongDescription = richDescText
438+
}
423439
}
424440
if appData.Categories != "" {
425441
item.Categories = appData.Categories
@@ -442,10 +458,24 @@ func main() {
442458
}
443459
}
444460
if summary := getText(appStreamXML.Summaries); summary != "" {
445-
item.Description = summary
461+
// Convert Summary to plain text
462+
summaryText, err := html2text.FromString(summary, html2text.Options{PrettyTables: true})
463+
if err != nil {
464+
log.Printf("%swarning%s failed to convert Summary to plain text for %s%s%s: %v", warningColor, resetColor, blueColor, path, resetColor, err)
465+
item.Description = summary // Fallback to raw summary
466+
} else {
467+
item.Description = summaryText
468+
}
446469
}
447470
if appStreamXML.Description.InnerXML != "" {
448-
item.LongDescription = appStreamXML.Description.InnerXML
471+
// Convert Description.InnerXML to plain text
472+
descText, err := html2text.FromString(appStreamXML.Description.InnerXML, html2text.Options{PrettyTables: true})
473+
if err != nil {
474+
log.Printf("%swarning%s failed to convert Description to plain text for %s%s%s: %v", warningColor, resetColor, blueColor, path, resetColor, err)
475+
item.LongDescription = appStreamXML.Description.InnerXML // Fallback to raw HTML
476+
} else {
477+
item.LongDescription = descText
478+
}
449479
}
450480
item.AppstreamId = appBundleID.Name
451481
}

0 commit comments

Comments
 (0)