import { Component, Prop, h } from '@stencil/core'; @Component({ tag: 'internal-text-renderer', styleUrl: 'text-renderer.css', shadow: true }) export class InternalTextRenderer { @Prop() content: string = ''; @Prop() autoLink: boolean = true; @Prop() highlightCode: boolean = false; @Prop() preserveWhitespace: boolean = true; private processContent(): string { if (!this.content) return ''; let processedContent = this.content; // 保留换行符 if (this.preserveWhitespace) { processedContent = processedContent.replace(/\n/g, '
'); } // 自动链接识别 if (this.autoLink) { const urlRegex = /(https?:\/\/[^\s]+)/g; processedContent = processedContent.replace(urlRegex, '$1'); } // 代码高亮(简单实现) if (this.highlightCode) { const codeRegex = /`([^`]+)`/g; processedContent = processedContent.replace(codeRegex, '$1'); } return processedContent; } render() { return (
); } }