telegraph_export_page
Export Telegraph pages to Markdown or HTML format for backup, sharing, or content migration purposes.
Instructions
Export a Telegraph page to Markdown or HTML format
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | Path to the Telegraph page | |
| format | No | Export format | markdown |
Implementation Reference
- src/tools/export.ts:168-192 (handler)Handler function logic that executes the telegraph_export_page tool: parses input, fetches the page using telegraph.getPage, converts content to markdown or html, and returns structured JSON output.
if (name === 'telegraph_export_page') { const input = ExportPageSchema.parse(args); const page = await telegraph.getPage(input.path, true); if (!page.content) { throw new Error('Page has no content'); } const content = input.format === 'markdown' ? nodesToMarkdown(page.content) : nodesToHtml(page.content); return { content: [{ type: 'text' as const, text: JSON.stringify({ title: page.title, path: page.path, url: page.url, format: input.format, content, }, null, 2), }], }; } - src/tools/export.ts:11-14 (schema)Zod schema defining input parameters for telegraph_export_page tool: path (required) and format (markdown or html).
export const ExportPageSchema = z.object({ path: z.string().describe('Path to the Telegraph page'), format: z.enum(['markdown', 'html']).default('markdown').describe('Export format'), }); - src/tools/export.ts:117-136 (registration)Tool registration entry in exportTools array, including name, description, and JSON inputSchema.
{ name: 'telegraph_export_page', description: 'Export a Telegraph page to Markdown or HTML format', inputSchema: { type: 'object' as const, properties: { path: { type: 'string', description: 'Path to the Telegraph page', }, format: { type: 'string', enum: ['markdown', 'html'], default: 'markdown', description: 'Export format', }, }, required: ['path'], }, }, - src/tools/export.ts:23-35 (helper)Helper function to convert Telegraph page nodes to Markdown format, used in the handler.
function nodesToMarkdown(nodes: Node[]): string { let markdown = ''; for (const node of nodes) { if (typeof node === 'string') { markdown += node; } else { markdown += nodeElementToMarkdown(node as NodeElement); } } return markdown; } - src/tools/export.ts:37-86 (helper)Helper function to convert individual Telegraph NodeElement to Markdown, supporting various tags.
function nodeElementToMarkdown(node: NodeElement): string { const children = node.children ? nodesToMarkdown(node.children) : ''; switch (node.tag) { case 'h3': return `\n# ${children}\n`; case 'h4': return `\n## ${children}\n`; case 'p': return `\n${children}\n`; case 'b': case 'strong': return `**${children}**`; case 'i': case 'em': return `*${children}*`; case 'a': return `[${children}](${node.attrs?.href || ''})`; case 'img': return ``; case 'figure': return children; case 'figcaption': return `\n*${children}*\n`; case 'ul': return `\n${children}`; case 'ol': return `\n${children}`; case 'li': return `- ${children}\n`; case 'blockquote': return `\n> ${children}\n`; case 'code': return `\`${children}\``; case 'pre': return `\n\`\`\`\n${children}\n\`\`\`\n`; case 'br': return '\n'; case 'hr': return '\n---\n'; case 's': return `~~${children}~~`; case 'u': return children; // No markdown equivalent case 'aside': return `\n*${children}*\n`; default: return children; } }