Skip to main content
Glama

convert_markdown_to_html

Convert Markdown files to HTML with customizable themes, table of contents, and custom CSS. Outputs are saved automatically to a specified directory for streamlined document processing.

Instructions

Enhanced Markdown to HTML conversion with beautiful styling and theme support. Supports GitHub, Academic, Modern, and Default themes with complete style preservation. Output directory is controlled by OUTPUT_DIR environment variable. Files will be automatically saved to OUTPUT_DIR with auto-generated names.

Input Schema

NameRequiredDescriptionDefault
customCSSNoAdditional custom CSS styles
includeTableOfContentsNoGenerate table of contents
markdownPathYesMarkdown file path to convert
themeNoTheme to applygithub

Input Schema (JSON Schema)

{ "properties": { "customCSS": { "description": "Additional custom CSS styles", "type": "string" }, "includeTableOfContents": { "default": false, "description": "Generate table of contents", "type": "boolean" }, "markdownPath": { "description": "Markdown file path to convert", "type": "string" }, "theme": { "default": "github", "description": "Theme to apply", "enum": [ "default", "github", "academic", "modern" ], "type": "string" } }, "required": [ "markdownPath" ], "type": "object" }

Implementation Reference

  • The exported entry point function for the convert_markdown_to_html tool, which instantiates the converter class and delegates to its main convertMarkdownToHtml method.
    export async function convertMarkdownToHtml( inputPath: string, options: MarkdownToHtmlOptions = {} ): Promise<MarkdownConversionResult> { const converter = new MarkdownToHtmlConverter(); return await converter.convertMarkdownToHtml(inputPath, options); }
  • Core handler logic within the MarkdownToHtmlConverter class that performs the actual Markdown to HTML conversion using marked library, applies themes, generates complete HTML documents with CSS, handles file I/O, and returns structured results.
    async convertMarkdownToHtml( inputPath: string, options: MarkdownToHtmlOptions = {} ): Promise<MarkdownConversionResult> { try { this.options = { preserveStyles: true, theme: 'default', includeTableOfContents: false, enableSyntaxHighlighting: false, standalone: true, debug: false, ...options, }; if (this.options.debug) { console.log('๐Ÿš€ ๅผ€ๅง‹ Markdown ๅˆฐ HTML ่ฝฌๆข...'); console.log('๐Ÿ“„ ่พ“ๅ…ฅๆ–‡ไปถ:', inputPath); console.log('๐ŸŽจ ไฝฟ็”จไธป้ข˜:', this.options.theme); } // ่ฏปๅ– Markdown ๆ–‡ไปถ const markdownContent = await fs.readFile(inputPath, 'utf-8'); // ้…็ฝฎ marked this.configureMarked(); // ่ฝฌๆขไธบ HTML const htmlContent = marked.parse(markdownContent); // ๅˆ†ๆžๅ†…ๅฎน็ปŸ่ฎก const stats = this.analyzeContent(htmlContent); // ็”ŸๆˆๅฎŒๆ•ด็š„ HTML ๆ–‡ๆกฃ const completeHtml = this.generateCompleteHtml(htmlContent); // ไฟๅญ˜ๆ–‡ไปถ๏ผˆๅฆ‚ๆžœๆŒ‡ๅฎšไบ†่พ“ๅ‡บ่ทฏๅพ„๏ผ‰ let htmlPath: string | undefined; if (this.options.outputPath) { const { validateAndSanitizePath } = require('../security/securityConfig'); // ็งป้™ค่ทฏๅพ„้™ๅˆถ๏ผŒๅ…่ฎธ่ฎฟ้—ฎไปปๆ„็›ฎๅฝ•๏ผˆไธŽindex.tsไธญ็š„validatePathๅ‡ฝๆ•ฐไฟๆŒไธ€่‡ด๏ผ‰ htmlPath = validateAndSanitizePath(this.options.outputPath, []); await fs.writeFile(htmlPath, completeHtml, 'utf-8'); if (this.options.debug) { console.log('โœ… HTML ๆ–‡ไปถๅทฒไฟๅญ˜:', htmlPath); } } if (this.options.debug) { console.log('๐Ÿ“Š ่ฝฌๆข็ปŸ่ฎก:', stats); console.log('โœ… Markdown ่ฝฌๆขๅฎŒๆˆ'); } return { success: true, content: completeHtml, htmlPath, metadata: { originalFormat: 'markdown', targetFormat: 'html', stylesPreserved: this.options.preserveStyles ?? false, theme: this.options.theme ?? 'default', converter: 'markdown-to-html-converter', contentLength: completeHtml.length, ...stats, }, }; } catch (error: any) { console.error('โŒ Markdown ่ฝฌๆขๅคฑ่ดฅ:', error.message); return { success: false, error: error.message, }; } }
  • Input schema defining options for the Markdown to HTML conversion tool, including theme selection, style preservation, TOC inclusion, and output configuration.
    interface MarkdownToHtmlOptions { preserveStyles?: boolean; theme?: 'default' | 'github' | 'academic' | 'modern'; includeTableOfContents?: boolean; enableSyntaxHighlighting?: boolean; customCSS?: string; outputPath?: string; standalone?: boolean; debug?: boolean; }
  • Output schema for the conversion result, including success status, generated HTML content/path, metadata statistics, and error handling.
    interface MarkdownConversionResult { success: boolean; content?: string; htmlPath?: string; cssPath?: string; metadata?: { originalFormat: string; targetFormat: string; stylesPreserved: boolean; theme: string; converter: string; contentLength: number; headingsCount: number; linksCount: number; imagesCount: number; }; error?: string; }
  • Helper mapping in conversion planner that associates the tool name 'convert_markdown_to_html' with its description for planning purposes.
    convert_markdown_to_html: 'ๅฐ†Markdownๆ–‡ๆกฃ่ฝฌๆขไธบHTMLๆ ผๅผ๏ผŒๅบ”็”จไธป้ข˜ๆ ทๅผ',
  • Helper defining input parameter name 'markdownPath' for the 'convert_markdown_to_html' tool.
    convert_markdown_to_html: 'markdownPath',
  • Helper case in parameter generation switch that sets default parameters like theme='github' for the convert_markdown_to_html tool.
    case 'convert_markdown_to_html':

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/Tele-AI/doc-ops-mcp'

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