UNPKG

telegram-markdown-v2

Version:

Convert markdown into Telegram Markdown V2 format with TypeScript support

46 lines (45 loc) 1.78 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createMarkdownOptions = createMarkdownOptions; const blocks_js_1 = require("./blocks.js"); const formatting_js_1 = require("./formatting.js"); const links_js_1 = require("./links.js"); const text_js_1 = require("./text.js"); /** * Creates custom `mdast-util-to-markdown` handlers that tailor the output for * Telegram Markdown V2. */ function createHandlers(definitions, unsupportedTagsStrategy) { return { heading: formatting_js_1.handleHeading, strong: formatting_js_1.handleStrong, delete: formatting_js_1.handleDelete, emphasis: formatting_js_1.handleEmphasis, list: blocks_js_1.handleList, listItem: blocks_js_1.handleListItem, inlineCode: text_js_1.handleInlineCode, code: text_js_1.handleCode, link: links_js_1.handleLink, linkReference: (0, links_js_1.handleLinkReference)(definitions), image: links_js_1.handleImage, imageReference: (0, links_js_1.handleImageReference)(definitions), text: text_js_1.handleText, blockquote: (0, blocks_js_1.handleBlockquote)(unsupportedTagsStrategy), html: (0, blocks_js_1.handleHtml)(unsupportedTagsStrategy), table: (0, blocks_js_1.handleTable)(unsupportedTagsStrategy), }; } /** * Creates options to be passed into a `remark-stringify` processor that tailor * the output for Telegram Markdown V2. */ function createMarkdownOptions(definitions, unsupportedTagsStrategy = 'keep') { return { bullet: '*', bulletOrdered: '.', bulletOther: '+', tightDefinitions: true, listItemIndent: 'one', handlers: createHandlers(definitions, unsupportedTagsStrategy), }; }