UNPKG

@ankimcp/anki-mcp-server

Version:

Model Context Protocol server for Anki - enables AI assistants to interact with your Anki flashcards

48 lines • 1.73 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseMarkdownSections = parseMarkdownSections; const unified_1 = require("unified"); const remark_parse_1 = __importDefault(require("remark-parse")); function nodeToString(node) { if (node.type === "text") { return node.value; } if (node.type === "inlineCode") { return `\`${node.value}\``; } if ("children" in node && Array.isArray(node.children)) { return node.children .map((child) => nodeToString(child)) .join(""); } if ("value" in node && typeof node.value === "string") { return node.value; } return ""; } function extractHeadingText(node) { if ("children" in node && Array.isArray(node.children)) { return node.children .map((child) => nodeToString(child)) .join(""); } return ""; } function parseMarkdownSections(markdown) { const tree = (0, unified_1.unified)().use(remark_parse_1.default).parse(markdown); const sections = {}; const h1Headings = tree.children.filter((node) => node.type === "heading" && node.depth === 1); h1Headings.forEach((heading, index) => { const start = heading.position?.end.offset; const end = h1Headings[index + 1]?.position?.start.offset ?? markdown.length; if (start === undefined || end === undefined) { return; } sections[extractHeadingText(heading)] = markdown.slice(start, end).trim(); }); return sections; } //# sourceMappingURL=markdown.utils.js.map