From 8879a6bd7c82d7cdb61ee8a293ee26490ed53e4e Mon Sep 17 00:00:00 2001 From: Feuerfuchs Date: Sat, 18 Jan 2020 11:12:14 +0100 Subject: Remove ANSI SGR sequences from Gemini docs --- gopherproxy/gopherproxy.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/gopherproxy/gopherproxy.go b/gopherproxy/gopherproxy.go index 4a7d972..453ee9c 100644 --- a/gopherproxy/gopherproxy.go +++ b/gopherproxy/gopherproxy.go @@ -29,6 +29,10 @@ import ( "github.com/temoto/robotstxt" ) +var ( + TermEscapeSGRPattern = regexp.MustCompile("\\[\\d+(;\\d+)*m") +) + const ( ITEM_TYPE_GEMINI_LINE = "" ITEM_TYPE_GEMINI_LINK = " =>" @@ -177,6 +181,7 @@ func parseGeminiDocument(body *bytes.Buffer, uri string, hostport string) (items for scanner.Scan() { line := strings.Trim(scanner.Text(), "\r\n") + line = TermEscapeSGRPattern.ReplaceAllString(line, "") item := Item{ Type: ITEM_TYPE_GEMINI_LINE, -- cgit v1.2.3-70-g09d2