{"id":15117141,"url":"https://github.com/unjs/mdbox","last_synced_at":"2025-06-10T22:41:25.825Z","repository":{"id":221130761,"uuid":"753559682","full_name":"unjs/mdbox","owner":"unjs","description":"⬇ Just simple markdown utils","archived":false,"fork":false,"pushed_at":"2025-01-15T06:33:19.000Z","size":388,"stargazers_count":92,"open_issues_count":7,"forks_count":7,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-15T08:48:02.277Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/unjs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-02-06T11:11:58.000Z","updated_at":"2025-01-08T01:29:08.000Z","dependencies_parsed_at":"2024-03-25T21:29:18.030Z","dependency_job_id":"20945094-00ff-4c76-82bc-6a14589a7042","html_url":"https://github.com/unjs/mdbox","commit_stats":{"total_commits":40,"total_committers":9,"mean_commits":4.444444444444445,"dds":0.55,"last_synced_commit":"1f187442c456621e894b2dbd85754f5577b06e0b"},"previous_names":["unjs/omark","unjs/mdbox"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unjs%2Fmdbox","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unjs%2Fmdbox/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unjs%2Fmdbox/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unjs%2Fmdbox/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/unjs","download_url":"https://codeload.github.com/unjs/mdbox/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234462180,"owners_count":18837276,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-09-26T01:45:50.971Z","updated_at":"2025-01-18T04:31:28.122Z","avatar_url":"https://github.com/unjs.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# ⬇ mdbox\n\n\u003c!-- automd:badges color=yellow bundlephobia --\u003e\n\n[![npm version](https://img.shields.io/npm/v/mdbox?color=yellow)](https://npmjs.com/package/mdbox)\n[![npm downloads](https://img.shields.io/npm/dm/mdbox?color=yellow)](https://npm.chart.dev/mdbox)\n[![bundle size](https://img.shields.io/bundlephobia/minzip/mdbox?color=yellow)](https://bundlephobia.com/package/mdbox)\n\n\u003c!-- /automd --\u003e\n\nJust simple markdown utils!\n\n\u003e [!IMPORTANT]\n\u003e This project is under development.\n\n## 💡 Why?\n\n\u003e Markdown is intended to be as easy-to-read and easy-to-write as is. Readability is emphasized above all else. A Markdown-formatted document should be publishable as-is, as plain text [^1]. Any sequence of characters is a valid Markdown document [^2].\n\nWhile Markdown is designed to be simple, I often find myself in situations where there is simply no tool to allow programmatically working with Markdown syntax without dealing with complex and strict AST objects and choosing between dozens of available tools and extensions. Often, not even worth pursuing ideas around Markdown.\n\nThe idea is to make good-enough tools to read and write Markdown programmatically, as easy as Markdown itself is, without dealing with an AST.\n\n## Usage\n\nInstall package:\n\n```sh\n# npm\nnpm install mdbox\n\n# yarn\nyarn add mdbox\n\n# pnpm\npnpm install mdbox\n\n# bun\nbun install mdbox\n```\n\nImport:\n\n```js\n// ESM\nimport { md } from \"mdbox\";\n\n// CommonJS\nconst { md } = require(\"mdbox\");\n```\n\n\u003c!-- automd:jsdocs src=\"./src/index\" group=\"render_utils\" --\u003e\n\n## Render Utils\n\n### `blockquote(text)`\n\nRender a markdown blockquote text with \u003e in front of a paragraph\n\n**Example:**\n\n```js\nmd.blockquote(\"Hello, World!\");\n// =\u003e \"\u003e Hello, World!\"\n```\n\n### `bold(text)`\n\nRender a markdown bold text.\n\n**Example:**\n\n```js\nmd.bold(\"Hello, World!\");\n// =\u003e \"**Hello, World!**\"\n```\n\n### `boldAndItalic(text)`\n\nRender a markdown bold and italic text.\n\n**Example:**\n\n```js\nmd.boldAndItalic(\"Hello, World!\");\n// =\u003e \"***Hello, World!***\"\n```\n\n### `codeBlock(code, lang?, opts?: { ext? })`\n\nFormat a string as a code block.\n\n**Example:**\n\n```js\nmd.codeBlock('console.log(\"Hello, World!\");', \"js\");\n// =\u003e \"```js\\nconsole.log(\"Hello, World!\");\\n```\"\n```\n\n### `heading(text, level)`\n\nRender a markdown heading.\n\n**Example:**\n\n```js\nmd.heading(\"Hello, World!\", 1);\n// =\u003e \"\\n# Hello, World!\\n\"\n```\n\n### `hr(length)`\n\nRender a markdown horizontal rule.\n\n**Example:**\n\n```js\nmd.hr();\n// =\u003e \"---\"\n```\n\n### `image(url, text?, opts?: { title? })`\n\nRender a markdown image.\n\n**Example:**\n\n```js\nmd.image(\"https://cataas.com/cat\", \"Cute Cat\");\n// =\u003e \"![Cute Cat](https://cataas.com/cat)\"\n```\n\n### `italic(text)`\n\nRender a markdown italic text.\n\n**Example:**\n\n```js\nmd.italic(\"Hello, World!\");\n// =\u003e \"_Hello, World!_\"\n```\n\n### `link(url, text?, opts?: { title?, external? })`\n\nRender a markdown link.\n\n**Example:**\n\n```js\nmd.link(\"https://www.google.com\", \"Google\");\n// =\u003e \"[Google](https://www.google.com)\"\n```\n```js\nmd.link(\"https://www.google.com\", \"Google\", { external: true });\n// =\u003e \"\u003ca href=\"https://www.google.com\" title=\"Google\" target=\"_blank\"\u003eGoogle\u003c/a\u003e\"\n```\n\n### `list(items, opts: { ordered?, char? })`\n\nRender a markdown ordered or unordered list.\n\n**Example:**\n\n```js\nmd.list([\"Item 1\", \"Item 2\", \"Item 3\"]);\n// =\u003e \"- Item 1\\n- Item 2\\n- Item 3\"\n```\n```js\nmd.list([\"Item 1\", \"Item 2\", \"Item 3\"], { ordered: true });\n// =\u003e \"1. Item 1\\n2. Item 2\\n3. Item 3\"\n```\n\n### `strikethrough(text)`\n\nRender a markdown strikethrough text.\n\n**Example:**\n\n```js\nmd.strikethrough(\"Hello, World!\");\n// =\u003e \"~~Hello, World!~~\"\n```\n\n### `table(table: { rows[][], columns[] })`\n\nRender a markdown table.\n\n**Example:**\n\n```js\nmd.table({\n columns: [\"Breed\", \"Origin\", \"Size\", \"Temperament\"],\n rows: [\n   [\"Abyssinian\", \"Egypt\", \"Medium\", \"Active\"],\n   [\"Aegean\", \"Greece\", \"Medium\", \"Active\"],\n   [\"American Bobtail\", \"United States\", \"Medium\", \"Active\"],\n   [\"Applehead Siamese\", \"Thailand\", \"Medium\", \"Active\"],\n  ],\n});\n```\n\n\u003c!-- /automd --\u003e\n\n\u003c!-- automd:jsdocs src=\"./src/parser/index\" group=\"parsing_utils\" --\u003e\n\n## Parsing Utils\n\n### `initMarkdownItParser(options)`\n\nCreate parser with [markdown-it](https://github.com/markdown-it/markdown-it).\n\n**WARNING**: The returned tree structure is unstable.\n\n**Example:**\n\n```ts\nimport { initMarkdownItParser } from \"mdbox/parser\";\nconst parser = await initMarkdownItParser();\nconst { tree } = parser.parse(\"# Hello, *world*!\");\n```\n\n### `initMd4wParser(opts)`\n\nCreate parser with [md4w](https://github.com/ije/md4w).\n\n**WARNING**: The returned tree structure is unstable.\n\n**Example:**\n\n```ts\nimport { initMd4wParser } from \"mdbox/parser\";\nconst parser = await initMd4wParser();\nconst { tree } = parser.parse(\"# Hello, *world*!\");\n```\n\n### `initMdAstParser(opts)`\n\nCreate parser with [mdast-util-from-markdown](https://github.com/syntax-tree/mdast-util-from-markdown).\n\n**WARNING**: The returned tree structure is unstable.\n\n**Example:**\n\n```ts\nimport { initMdAstParser } from \"mdbox/parser\";\nconst parser = await initMdAstParser();\nconst { tree } = parser.parse(\"# Hello, *world*!\");\n```\n\n\u003c!-- /automd --\u003e\n\n\u003c!-- automd:fetch url=\"gh:unjs/.github/main/snippets/readme-contrib-node-pnpm.md\" --\u003e\n\n## Contribution\n\n\u003cdetails\u003e\n  \u003csummary\u003eLocal development\u003c/summary\u003e\n\n- Clone this repository\n- Install the latest LTS version of [Node.js](https://nodejs.org/en/)\n- Enable [Corepack](https://github.com/nodejs/corepack) using `corepack enable`\n- Install dependencies using `pnpm install`\n- Run tests using `pnpm dev` or `pnpm test`\n\n\u003c/details\u003e\n\n\u003c!-- /automd --\u003e\n\n## License\n\n\u003c!-- automd:contributors license=MIT author=pi0 --\u003e\n\nPublished under the [MIT](https://github.com/unjs/mdbox/blob/main/LICENSE) license.\nMade by [@pi0](https://github.com/pi0) and [community](https://github.com/unjs/mdbox/graphs/contributors) 💛\n\u003cbr\u003e\u003cbr\u003e\n\u003ca href=\"https://github.com/unjs/mdbox/graphs/contributors\"\u003e\n\u003cimg src=\"https://contrib.rocks/image?repo=unjs/mdbox\" /\u003e\n\u003c/a\u003e\n\n\u003c!-- /automd --\u003e\n\n\u003c!-- automd:with-automd --\u003e\n\n---\n\n_🤖 auto updated with [automd](https://automd.unjs.io)_\n\n\u003c!-- /automd --\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funjs%2Fmdbox","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Funjs%2Fmdbox","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funjs%2Fmdbox/lists"}