From 0065fdc2c7a4390762ed1883c485368b84844e5e Mon Sep 17 00:00:00 2001 From: Antoni Sawicki Date: Sat, 22 Jun 2024 01:48:46 -0700 Subject: [PATCH] asciify utf8 --- wrp.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/wrp.go b/wrp.go index 718138e..3649b22 100644 --- a/wrp.go +++ b/wrp.go @@ -415,6 +415,18 @@ func (rq *wrpReq) capture() { log.Printf("%s Done with capture for %s\n", rq.r.RemoteAddr, rq.url) } +func asciify(s []byte) []byte { + a := make([]byte, len(s)) + for i := 0; i < len(s); i++ { + if s[i] > 127 { + a[i] = '.' + continue + } + a[i] = s[i] + } + return a +} + func (rq *wrpReq) toMarkdown() { log.Printf("Processing Markdown conversion for %v", rq.url) req, err := http.NewRequest("GET", "https://r.jina.ai/"+rq.url, nil) @@ -449,8 +461,9 @@ func (rq *wrpReq) toMarkdown() { }) r := html.NewRenderer(html.RendererOptions{}) ht := markdown.Render(d, r) + // TODO: add https://github.com/microcosm-cc/bluemonday rq.printHTML(printParams{ - text: string(ht), + text: string(asciify(ht)), bgColor: "#FFFFFF", }) }