richtext

package
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 4, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package richtext provides utilities for converting between Markdown and HTML. It uses glamour for terminal-friendly Markdown rendering.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AttachmentToHTML

func AttachmentToHTML(sgid, filename, contentType string) string

AttachmentToHTML builds a <bc-attachment> tag for embedding in Trix-compatible HTML.

func DetectMIME

func DetectMIME(path string) string

DetectMIME returns the MIME type for a file path. It uses the extension map first, then falls back to reading file header bytes.

func EmbedAttachments

func EmbedAttachments(html string, attachments []AttachmentRef) string

EmbedAttachments appends <bc-attachment> tags to HTML content. Each attachment is added as a separate block after the main content.

func HTMLToMarkdown

func HTMLToMarkdown(html string) string

HTMLToMarkdown converts HTML content to Markdown. This is useful for displaying Basecamp's rich text content in the terminal.

func IsHTML

func IsHTML(s string) bool

IsHTML attempts to detect if the input string contains HTML. Only returns true for well-formed HTML with common content tags. Does not detect arbitrary tags like <script> to prevent XSS passthrough.

func IsMarkdown

func IsMarkdown(s string) bool

IsMarkdown attempts to detect if the input string is Markdown rather than plain text or HTML. This is a heuristic and may not be 100% accurate.

func MarkdownToHTML

func MarkdownToHTML(md string) string

MarkdownToHTML converts Markdown text to HTML suitable for Basecamp's rich text fields. It handles common Markdown syntax: headings, bold, italic, links, lists, code blocks, and blockquotes. If the input already appears to be HTML, it is returned unchanged to preserve existing formatting.

func RenderMarkdown

func RenderMarkdown(md string) (string, error)

RenderMarkdown renders Markdown for terminal display using glamour. It returns styled output suitable for CLI display.

func RenderMarkdownWithWidth

func RenderMarkdownWithWidth(md string, width int) (string, error)

RenderMarkdownWithWidth renders Markdown for terminal display with a custom width.

func ValidateFile

func ValidateFile(path string) error

ValidateFile checks that a path refers to an existing, regular, readable file within the size limit. Returns nil on success.

Types

type AttachmentRef

type AttachmentRef struct {
	SGID        string
	Filename    string
	ContentType string
}

AttachmentRef holds the metadata needed to embed a <bc-attachment> in HTML.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL