From af74d483c4bd89e733379876f6185a4c9118a646 Mon Sep 17 00:00:00 2001 From: Arthur Zamarin Date: Mon, 10 Apr 2023 20:57:54 +0300 Subject: app/packages/show: better rendering of newlines in description Signed-off-by: Arthur Zamarin --- pkg/app/handler/packages/utils.go | 3 +++ pkg/portage/repository/deprecated.go | 6 +++++- pkg/portage/repository/mask.go | 6 +++++- 3 files changed, 13 insertions(+), 2 deletions(-) (limited to 'pkg') diff --git a/pkg/app/handler/packages/utils.go b/pkg/app/handler/packages/utils.go index 0456c14..eeafc36 100644 --- a/pkg/app/handler/packages/utils.go +++ b/pkg/app/handler/packages/utils.go @@ -203,6 +203,9 @@ func GetFuncMap() template.FuncMap { "showRemovalNotice": showRemovalNotice, "isDeprecated": isDeprecated, "getDeprecation": getDeprecation, + "replaceNewline": func(s string) template.HTML { + return template.HTML(strings.Replace(template.HTMLEscapeString(s), "\n", "
", -1)) + }, "add": func(a, b int) int { return a + b }, diff --git a/pkg/portage/repository/deprecated.go b/pkg/portage/repository/deprecated.go index 4c642b7..f9348d6 100644 --- a/pkg/portage/repository/deprecated.go +++ b/pkg/portage/repository/deprecated.go @@ -70,7 +70,11 @@ func parsePackagesDeprecated(entry string) { var reason string packageLine, packageLines = packageLines[0], packageLines[1:] for strings.HasPrefix(packageLine, "#") { - reason = reason + " " + strings.Replace(packageLine, "# ", "", 1) + if packageLine == "#" { + reason += "\n" + } else { + reason = reason + " " + strings.TrimPrefix(packageLine, "# ") + } packageLine, packageLines = packageLines[0], packageLines[1:] } diff --git a/pkg/portage/repository/mask.go b/pkg/portage/repository/mask.go index 1b70c64..22715f2 100644 --- a/pkg/portage/repository/mask.go +++ b/pkg/portage/repository/mask.go @@ -113,7 +113,11 @@ func parsePackageMask(packageMask string) { var reason string packageMaskLine, packageMaskLines = packageMaskLines[0], packageMaskLines[1:] for strings.HasPrefix(packageMaskLine, "#") { - reason = reason + " " + strings.Replace(packageMaskLine, "# ", "", 1) + if packageMaskLine == "#" { + reason += "\n" + } else { + reason = reason + " " + strings.TrimPrefix(packageMaskLine, "# ") + } packageMaskLine, packageMaskLines = packageMaskLines[0], packageMaskLines[1:] } -- cgit v1.2.3-65-gdbad