MCPcopy Create free account
hub / github.com/basecamp/hey-cli / ToText

Function ToText

internal/htmlutil/htmlutil.go:12–25  ·  view source on GitHub ↗

ToText converts HTML content to plain text, preserving basic structure.

(s string)

Source from the content-addressed store, hash-verified

10
11// ToText converts HTML content to plain text, preserving basic structure.
12func ToText(s string) string {
13 doc, err := html.Parse(strings.NewReader(s))
14 if err != nil {
15 return s
16 }
17 var b strings.Builder
18 walkNode(&b, doc)
19 // Collapse runs of 3+ newlines into 2
20 result := b.String()
21 for strings.Contains(result, "\n\n\n") {
22 result = strings.ReplaceAll(result, "\n\n\n", "\n\n")
23 }
24 return strings.TrimSpace(result)
25}
26
27// ExtractImageURLs finds image URLs from <img src> tags and
28// <figure data-trix-attachment> elements.

Callers 14

htmlToTextFunction · 0.92
runMethod · 0.92
ParseTopicEntriesHTMLFunction · 0.85
TestToTextPlainFunction · 0.85
TestToTextParagraphsFunction · 0.85
TestToTextBrFunction · 0.85
TestToTextListFunction · 0.85
TestToTextStripsEntitiesFunction · 0.85
TestToTextStripsScriptFunction · 0.85
TestToTextEmptyFunction · 0.85
TestToTextImgTagFunction · 0.85
TestToTextImgNoAltFunction · 0.85

Calls 2

walkNodeFunction · 0.85
StringMethod · 0.80

Tested by 11

TestToTextPlainFunction · 0.68
TestToTextParagraphsFunction · 0.68
TestToTextBrFunction · 0.68
TestToTextListFunction · 0.68
TestToTextStripsEntitiesFunction · 0.68
TestToTextStripsScriptFunction · 0.68
TestToTextEmptyFunction · 0.68
TestToTextImgTagFunction · 0.68
TestToTextImgNoAltFunction · 0.68
TestToTextTrixFigureFunction · 0.68