/** * @fileoverview Rant Content Component for Rantii * @author retoor * @description Renders rant text with markdown, images, and media * @keywords rant, content, markdown, media, render */ import { BaseComponent } from './base-component.js'; import { markdownRenderer } from '../utils/markdown.js'; import { extractImageUrls, extractYoutubeUrls, extractNonMediaUrls } from '../utils/url.js'; class RantContent extends BaseComponent { static get observedAttributes() { return ['text']; } init() { this.render(); } render() { const text = this.getAttr('text') || ''; this.addClass('rant-content'); const images = extractImageUrls(text); const youtubeLinks = extractYoutubeUrls(text); const otherLinks = extractNonMediaUrls(text); const renderedText = markdownRenderer.render(text); let html = `
${renderedText}
`; if (images.length > 0) { html += `
${images.map(url => ` `).join('')}
`; } if (youtubeLinks.length > 0) { html += `
${youtubeLinks.map(url => ` `).join('')}
`; } if (otherLinks.length > 0) { html += ` `; } this.setHtml(html); } onAttributeChanged(name, oldValue, newValue) { this.render(); } setText(text) { this.setAttr('text', text); } } customElements.define('rant-content', RantContent); export { RantContent };