UNPKG

bktide

Version:

Command-line interface for Buildkite CI/CD workflows with rich shell completions (Fish, Bash, Zsh) and Alfred workflow integration for macOS power users

53 lines 1.71 kB
import { htmlToText } from 'html-to-text'; /** * Formats HTML text for terminal display */ export function formatTextForTerminal(text, options = {}) { const { maxWidth = 80, preserveLinks = true } = options; if (!text || typeof text !== 'string') { return ''; } // Convert HTML to text with better structure preservation const htmlToTextOptions = { wordwrap: maxWidth, preserveNewlines: true, selectors: [ { selector: 'a', format: 'anchor' } ], formatters: { anchor: (elem, _walk, builder) => { const href = elem.attribs?.href; const text = elem.children?.[0]?.data || href; if (preserveLinks && href) { builder.addInline(`${text} (${href})`); } else { builder.addInline(text); } } } }; try { const formattedText = htmlToText(text, htmlToTextOptions); // Clean up any excessive whitespace while preserving structure return formattedText .replace(/\n{3,}/g, '\n\n') // Replace 3+ newlines with 2 .trim(); } catch (error) { // If HTML parsing fails, fall back to original text console.warn('Failed to parse HTML, using original text:', error); return text.trim(); } } /** * Formats annotation body text specifically for terminal display */ export function formatAnnotationBody(bodyText, options = {}) { return formatTextForTerminal(bodyText, { maxWidth: 100, preserveLinks: true, ...options }); } //# sourceMappingURL=textFormatter.js.map