Files
libredesk/internal/stringutil/htmlextract.go
T
Abhinav Raut 8cdfe861e8 add AI snippet URL import, conversation summarize, and assistant reply languages
Snippet import: new "Import from URL" flow fetches a page and stores its
readable content as a snippet. Extraction uses the mackee/go-readability
library (Mozilla Readability port) and outputs Markdown, so nav/footer
boilerplate is dropped. The snippet list shows the source, and the edit
dialog is now wider with a taller content box.

Summarize: new "Summarize with AI" action on a conversation calls the AI and
adds the result as a private note. It shows an info toast right away so the
user knows it started, since the call can take a few seconds. This adds an
"info" toast variant that any feature can use.

Assistant languages: assistants can be given a list of allowed reply
languages. The assistant replies in the customer's language when it is one of
them, otherwise it falls back to the first. The preview also lists the
knowledge sources it used.

Cleanup: replace hardcoded gray/zinc/white colors with theme tokens
(text-muted-foreground, text-foreground, bg-accent) across several components.
2026-07-16 01:39:45 +05:30

22 lines
685 B
Go

package stringutil
import (
"strings"
readability "github.com/mackee/go-readability"
)
// ExtractReadableContent returns the title and readable content (as Markdown) of an HTML page.
// Returns empty content when the page has no article-like content to extract.
func ExtractReadableContent(htmlDoc string) (string, string) {
// Default char threshold (500) leaves Root nil on short support pages; lower it so they
// still get extracted.
opts := readability.DefaultOptions()
opts.CharThreshold = 100
art, err := readability.Extract(htmlDoc, opts)
if err != nil || art.Root == nil {
return "", ""
}
return art.Title, strings.TrimSpace(readability.ToMarkdown(art.Root))
}