Skip to main content
Glama
processing-html-markdown.ts1.61 kB
/** * HTML to Markdown Strategy * * Converts HTML content to Markdown using a shared pool. */ import { ApiConfig } from "@superglue/client"; import { Metadata } from "@superglue/shared"; import { getSharedHtmlMarkdownPool } from '../../utils/html-markdown-pool.js'; import { logMessage } from "../../utils/logs.js"; import { DocumentationProcessingStrategy } from '../types.js'; export class HtmlMarkdownStrategy implements DocumentationProcessingStrategy { async tryProcess(content: string, config: ApiConfig, metadata: Metadata): Promise<string | null> { if (content === undefined || content === null) { return null; } if (typeof content !== 'string') { content = JSON.stringify(content, null, 2); } const contentStart = content.slice(0, 1000).toLowerCase(); const hasMarkdownIndicators = contentStart.includes('##') || contentStart.includes('###') || contentStart.includes('```') || contentStart.includes('- ') || contentStart.includes('* '); const hasHtmlIndicators = contentStart.includes("<html") || contentStart.includes("<!doctype") || contentStart.includes("<body") || contentStart.includes("<div"); if (hasMarkdownIndicators && !hasHtmlIndicators) { return content; } if (!hasHtmlIndicators) { return null; } try { const pool = getSharedHtmlMarkdownPool(); const markdown = await pool.convert(content); return markdown ?? ''; } catch (translateError) { logMessage('error', `HTML to Markdown conversion failed: ${translateError}`, metadata); return null; } } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/superglue-ai/superglue'

If you have feedback or need assistance with the MCP directory API, please join our Discord server