{"id":19584800,"url":"https://github.com/flex-development/mdast-util-from-markdown","last_synced_at":"2026-02-21T11:01:57.693Z","repository":{"id":248042417,"uuid":"827021991","full_name":"flex-development/mdast-util-from-markdown","owner":"flex-development","description":"mdast utility to parse markdown","archived":false,"fork":false,"pushed_at":"2025-02-20T01:49:52.000Z","size":2406,"stargazers_count":1,"open_issues_count":15,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-02-13T19:55:36.953Z","etag":null,"topics":["ast","markdown","mdast","mdast-util","syntax-tree","unist","unist-util"],"latest_commit_sha":null,"homepage":"https://github.com/flex-development/mdast-util-from-markdown","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/flex-development.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/funding.yml","license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","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,"zenodo":null},"funding":{"github":["flex-development"]}},"created_at":"2024-07-10T21:30:57.000Z","updated_at":"2024-11-21T01:22:12.000Z","dependencies_parsed_at":"2025-02-04T02:30:58.365Z","dependency_job_id":"61eeb3c9-1f1b-4c26-b314-d8c452c3253a","html_url":"https://github.com/flex-development/mdast-util-from-markdown","commit_stats":null,"previous_names":["flex-development/mdast-util-from-markdown"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/flex-development/mdast-util-from-markdown","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flex-development%2Fmdast-util-from-markdown","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flex-development%2Fmdast-util-from-markdown/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flex-development%2Fmdast-util-from-markdown/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flex-development%2Fmdast-util-from-markdown/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flex-development","download_url":"https://codeload.github.com/flex-development/mdast-util-from-markdown/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flex-development%2Fmdast-util-from-markdown/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29679049,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-21T09:33:50.764Z","status":"ssl_error","status_checked_at":"2026-02-21T09:33:19.949Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["ast","markdown","mdast","mdast-util","syntax-tree","unist","unist-util"],"created_at":"2024-11-11T07:49:48.828Z","updated_at":"2026-02-21T11:01:57.677Z","avatar_url":"https://github.com/flex-development.png","language":"TypeScript","funding_links":["https://github.com/sponsors/flex-development"],"categories":[],"sub_categories":[],"readme":"# mdast-util-from-markdown\n\n[![github release](https://img.shields.io/github/v/release/flex-development/mdast-util-from-markdown.svg?include_prereleases\u0026sort=semver)](https://github.com/flex-development/mdast-util-from-markdown/releases/latest)\n[![npm](https://img.shields.io/npm/v/@flex-development/mdast-util-from-markdown.svg)](https://npmjs.com/package/@flex-development/mdast-util-from-markdown)\n[![codecov](https://codecov.io/gh/flex-development/mdast-util-from-markdown/graph/badge.svg?token=U7cQgKu7HU)](https://codecov.io/gh/flex-development/mdast-util-from-markdown)\n[![module type: esm](https://img.shields.io/badge/module%20type-esm-brightgreen)](https://github.com/voxpelli/badges-cjs-esm)\n[![license](https://img.shields.io/github/license/flex-development/mdast-util-from-markdown.svg)](LICENSE.md)\n[![conventional commits](https://img.shields.io/badge/-conventional%20commits-fe5196?logo=conventional-commits\u0026logoColor=ffffff)](https://conventionalcommits.org/)\n[![typescript](https://img.shields.io/badge/-typescript-3178c6?logo=typescript\u0026logoColor=ffffff)](https://typescriptlang.org/)\n[![vitest](https://img.shields.io/badge/-vitest-6e9f18?style=flat\u0026logo=vitest\u0026logoColor=ffffff)](https://vitest.dev/)\n[![yarn](https://img.shields.io/badge/-yarn-2c8ebb?style=flat\u0026logo=yarn\u0026logoColor=ffffff)](https://yarnpkg.com/)\n\n**[mdast][mdast]** utility that turns markdown into a syntax tree\n\n## Contents\n\n- [What is this?](#what-is-this)\n- [When should I use this?](#when-should-i-use-this)\n- [Install](#install)\n- [Use](#use)\n- [API](#api)\n  - [`fromMarkdown(value[, encoding][, options])`](#frommarkdownvalue-encoding-options)\n  - [`compiler([options])`](#compileroptions)\n  - [`handles`](#handles)\n  - [`CompileContext`](#compilecontext)\n  - [`CompileData`](#compiledata)\n  - [`Compiler`](#compiler)\n  - [`Config`](#config)\n  - [`Encoding`](#encoding)\n  - [`Event`](#event)\n  - [`Extension`](#extension)\n  - [`Fragment`](#fragment)\n  - [`Handle`](#handle)\n  - [`Handles`](#handles-1)\n  - [`OnEnterError`](#onentererror)\n  - [`OnExitError`](#onexiterror)\n  - [`Options`](#options)\n  - [`Point`](#point)\n  - [`StackedNode`](#stackednode)\n  - [`StartPoint`](#startpoint)\n  - [`TokenTuple`](#tokentuple)\n  - [`Token`](#token)\n  - [`TokenizeContext`](#tokenizecontext)\n  - [`Transform`](#transform)\n  - [`Value`](#value)\n- [List of extensions](#list-of-extensions)\n- [Syntax](#syntax)\n- [Syntax tree](#syntax-tree)\n- [Security](#security)\n- [Related](#related)\n- [Types](#types)\n- [Contribute](#contribute)\n\n## What is this?\n\nThis package is a utility that takes markdown input and turns it into a [markdown abstract syntax tree][mdast].\n\nThis utility uses [`micromark`][micromark], which turns markdown into tokens, and then turns those tokens into nodes.\n\n## When should I use this?\n\nIf you want to handle syntax trees manually, use this.\nWhen you *just* want to turn markdown into HTML, use [`micromark`][micromark] instead.\nFor an easier time processing content, use the **[remark][remark]** ecosystem instead.\n\n## Install\n\nThis package is [ESM only][esm].\n\nIn Node.js (version 18+) with [yarn][yarn]:\n\n```sh\nyarn add @flex-development/mdast-util-from-markdown\n```\n\n\u003cblockquote\u003e\n  \u003csmall\u003e\n    See \u003ca href='https://yarnpkg.com/protocol/git'\u003eGit - Protocols | Yarn\u003c/a\u003e\n    \u0026nbsp;for details regarding installing from Git.\n  \u003c/small\u003e\n\u003c/blockquote\u003e\n\nIn Deno with [`esm.sh`][esmsh]:\n\n```ts\nimport { fromMarkdown } from 'https://esm.sh/@flex-development/mdast-util-from-markdown'\n```\n\nIn browsers with [`esm.sh`][esmsh]:\n\n```html\n\u003cscript type=\"module\"\u003e\n  import { fromMarkdown } from 'https://esm.sh/@flex-development/mdast-util-from-markdown'\n\u003c/script\u003e\n```\n\n## Use\n\nSay we have the following markdown file `example.md`:\n\n```markdown\n## Hello, *World*!\n```\n\n…and our module `example.mjs` looks as follows:\n\n```js\nimport { fromMarkdown } from '@flex-development/mdast-util-from-markdown'\nimport { inspect } from '@flex-development/unist-util-inspect'\nimport { read } from 'to-vfile'\n\nconst file = await read('example.md')\nconst tree = fromMarkdown(String(file))\n\nconsole.log(inspect(tree))\n```\n\n…now running `node example.mjs` yields:\n\n```sh\nroot[1] (1:1-2:1, 0-19)\n└─0 heading[3] (1:1-1:19, 0-18)\n    │ depth: 2\n    ├─0 text \"Hello, \" (1:4-1:11, 3-10)\n    ├─1 emphasis[1] (1:11-1:18, 10-17)\n    │   └─0 text \"World\" (1:12-1:17, 11-16)\n    └─2 text \"!\" (1:18-1:19, 17-18)\n```\n\n## API\n\n### `fromMarkdown(value[, encoding][, options])`\n\nTurn markdown into a syntax tree.\n\n#### Overloads\n\n- `(value: Value | null | undefined, encoding?: Encoding | null | undefined, options?: Options) =\u003e Root`\n- `(value: Value | null | undefined, options?: Options | null | undefined) =\u003e Root`\n\n#### Parameters\n\n- `value` ([`Value`](#value) | `null` | `undefined`)\n  — markdown to parse\n- `encoding` ([`Encoding`](#encoding) | `null` | `undefined`, optional)\n  — [character encoding][encoding] for when `value` is [`Uint8Array`][uint8-array]\n  - default: `'utf8'`\n- `options` ([`Options`](#options) | `null` | `undefined`, optional)\n  — configuration\n\n#### Returns\n\n([`Root`][root]) mdast.\n\n### `compiler([options])`\n\nCreate an mdast compiler.\n\n\u003e 👉 The compiler only understands complete buffering, not streaming.\n\n#### Parameters\n\n- `options` ([`Options`](#options) | `null` | `undefined`, optional)\n  — configuration\n\n#### Returns\n\n([`Compiler`](#compiler)) mdast compiler.\n\n### `handles`\n\n([`Handles`](#handles-1)) Token types mapped to default token handlers.\n\n\u003e 👉 Default handlers are also exported by name. See [`src/handles.ts`](src/handles.ts) for more info.\n\n### `CompileContext`\n\nmdast compiler context (TypeScript type).\n\n#### Properties\n\n- `buffer` (`(this: CompileContext) =\u003e undefined`)\n  — capture some of the output data\n- `config` ([`Config`](#config))\n  — configuration\n- `data` ([`CompileData`](#compiledata))\n  — info passed around; key/value store\n- `enter` (`(this: CompileContext, node: Nodes, token: Token, onError?: OnEnterError) =\u003e undefined`)\n  — enter a node\n- `exit` (`(this: CompileContext, token: Token, onError?: OnExitError) =\u003e undefined`)\n  — exit a node\n- `resume` (`(this: CompileContext) =\u003e string`)\n  — stop capturing and access the output data\n- `sliceSerialize` ([`TokenizeContext['sliceSerialize']`](#tokenizecontext))\n  — get the string value of a token\n- `stack` ([`StackedNode[]`](#stackednode))\n  — stack of nodes\n- `tokenStack` ([`TokenTuple[]`](#tokentuple))\n  — stack of tokens\n\n### `CompileData`\n\nInterface of tracked data (TypeScript interface).\n\n```ts\ninterface CompileData {/* see code */}\n```\n\nWhen developing extensions that use more data, augment `CompileData` to register custom fields:\n\n```ts\ndeclare module 'mdast-util-from-markdown' {\n  interface CompileData {\n    mathFlowInside?: boolean | undefined\n  }\n}\n```\n\n### `Compiler`\n\nTurn micromark events into a syntax tree (TypeScript type).\n\n#### Parameters\n\n- `events` ([`Event[]`](#event))\n  — list of events\n\n#### Returns\n\n([`Root`][root]) mdast.\n\n### `Config`\n\nConfiguration (TypeScript type).\n\n#### Properties\n\n- `canContainEols` (`string[]`)\n  — token types where line endings are used\n- `enter` ([`Handles`](#handles))\n  — opening handles\n- `exit` ([`Handles`](#handles))\n  — closing handles\n- `transforms` ([`Transform[]`](#transform))\n  — tree transforms\n\n### `Encoding`\n\nEncodings supported by `TextEncoder` (TypeScript type).\n\nSee [`micromark-util-types`][micromark-util-types] for more info.\n\n```ts\ntype Encoding =\n  | 'utf-8' // always supported in node\n  | 'utf-16le' // always supported in node\n  | 'utf-16be' // not supported when ICU is disabled\n  | (string \u0026 {}) // everything else (depends on browser, or full ICU data)\n```\n\n### `Event`\n\nThe start or end of a [token](#token) amongst other events (TypeScript type).\n\nSee [`micromark-util-types`][micromark-util-types] for more info.\n\n```ts\ntype Event = ['enter' | 'exit', Token, TokenizeContext]\n```\n\n### `Extension`\n\nChange how [tokens](#token) are turned into nodes (TypeScript type).\n\nSee [`Config`](#config) for more info.\n\n```ts\ntype Extension = Partial\u003cConfig\u003e\n```\n\n### `Fragment`\n\nTemporary node (TypeScript type).\n\n```ts\ntype Fragment = Omit\u003cmdast.Parent, 'children' | 'type'\u003e \u0026 {\n  children: mdast.PhrasingContent[]\n  type: 'fragment'\n}\n```\n\n#### Properties\n\n- `children` ([`mdast.PhrasingContent[]`][phrasing-content])\n  — list of children\n- `type` (`'fragment'`)\n  — node type\n\n### `Handle`\n\nHandle a [token](#token) (TypeScript type).\n\n#### Parameters\n\n- `this` ([`CompileContext`](#compilecontext))\n  — compiler context\n- `token` ([`Token`](#token))\n  — token to handle\n\n#### Returns\n\n(`undefined | void`) Nothing.\n\n### `Handles`\n\nToken types mapped to handles (TypeScript type).\n\n```ts\ntype Handles = Record\u003cstring, Handle\u003e\n```\n\n### `OnEnterError`\n\nHandle the case where the `right` token is open, but is closed by the `left` token, or because end of file was reached\n(TypeScript type).\n\n#### Parameters\n\n- `this` ([`Omit\u003cCompileContext, 'sliceSerialize'\u003e`](#compilecontext))\n  — compiler context\n- `left` ([`Token`](#token) | `undefined`)\n  — left token\n- `right` ([`Token`](#token))\n  — open token\n\n#### Returns\n\n(`undefined`) Nothing.\n\n### `OnExitError`\n\nHandle the case where the `right` token is open, but is closed by exiting the `left` token (TypeScript type).\n\n#### Parameters\n\n- `this` ([`Omit\u003cCompileContext, 'sliceSerialize'\u003e`](#compilecontext))\n  — compiler context\n- `left` ([`Token`](#token))\n  — left token\n- `right` ([`Token`](#token))\n  — open token\n\n#### Returns\n\n(`undefined`) Nothing.\n\n### `Options`\n\nConfiguration options (TypeScript type).\n\n#### Properties\n\n- `extensions?` ([`micromark.Extension[]`][micromark-extension] | `null` | `undefined`)\n  — extensions for this utility to change how tokens are turned into nodes\n- `from?` ([`StartPoint`](#startpoint) | `null` | `undefined`)\n  — point before first character in markdown value. node positions will be relative to this point\n- `mdastExtensions?` ([`(Extension | Extension[])[]`](#extension) | `null` | `undefined`)\n  — extensions for this utility to change how tokens are turned into nodes\n\n### `Point`\n\nA location in the source document and chunk (TypeScript type).\n\nSee [`micromark-util-types`][micromark-util-types] for more info.\n\n### `StackedNode`\n\nA node on the compiler context stack (TypeScript type).\n\n```ts\ntype StackedNode = Fragment | mdast.Nodes\n```\n\n### `StartPoint`\n\nPoint before first character in a markdown value (TypeScript type).\n\n```ts\ntype StartPoint = Omit\u003cPoint, '_bufferIndex' | '_index'\u003e\n```\n\n### `TokenTuple`\n\nList containing an open token on the stack, and an optional error handler to use if the token isn't closed properly\n(TypeScript type).\n\n```ts\ntype TokenTuple = [token: Token, handler: OnEnterError | undefined]\n```\n\n### `Token`\n\nA span of chunks (TypeScript interface).\n\nSee [`micromark-util-types`][micromark-util-types] for more info.\n\n### `TokenizeContext`\n\nA context object that helps with tokenizing markdown constructs (TypeScript interface).\n\nSee [`micromark-util-types`][micromark-util-types] for more info.\n\n### `Transform`\n\nExtra transform, to change the AST afterwards (TypeScript type).\n\n#### Parameters\n\n- `tree` ([`Root`][root])\n  — tree to transform\n\n#### Returns\n\n([`Root`][root] | `null` | `undefined` | `void`) New tree or nothing (in which case the current tree is used).\n\n### `Value`\n\nContents of a file.\n\nSee [`micromark-util-types`][micromark-util-types] for more info.\n\n```ts\ntype Value = Uint8Array | string\n```\n\n## List of extensions\n\n- [`mdast-util-directive`][mdast-util-directive]\n  — directives\n- [`mdast-util-frontmatter`][mdast-util-frontmatter]\n  — frontmatter (YAML, TOML, more)\n- [`mdast-util-gfm`][mdast-util-gfm]\n  — GFM\n- [`mdast-util-gfm-autolink-literal`][mdast-util-gfm-autolink-literal]\n  — GFM autolink literals\n- [`mdast-util-gfm-footnote`][mdast-util-gfm-footnote]\n  — GFM footnotes\n- [`mdast-util-gfm-strikethrough`][mdast-util-gfm-strikethrough]\n  — GFM strikethrough\n- [`mdast-util-gfm-table`][mdast-util-gfm-table]\n  — GFM tables\n- [`mdast-util-gfm-task-list-item`][mdast-util-gfm-task-list-item]\n  — GFM task list items\n- [`syntax-tree/mdast-util-math`][mdast-util-math]\n  — math\n- [`syntax-tree/mdast-util-mdx`][mdast-util-mdx]\n  — MDX\n- [`syntax-tree/mdast-util-mdx-expression`][mdast-util-mdx-expression]\n  — MDX expressions\n- [`syntax-tree/mdast-util-mdx-jsx`][mdast-util-mdx-jsx]\n  — MDX JSX\n- [`syntax-tree/mdast-util-mdxjs-esm`][mdast-util-mdxjs-esm]\n  — MDX ESM\n\n## Syntax\n\nMarkdown is parsed according to CommonMark. Extensions can add support for other syntax. If you’re interested in\nextending markdown, [more information is available in micromark’s readme][micromark-extension].\n\n## Syntax tree\n\nThe syntax tree is [mdast][mdast].\n\n## Types\n\nThis package is fully typed with [TypeScript][typescript].\n\n## Security\n\nAs markdown is sometimes used for HTML, and improper use of HTML can open you up to a [cross-site scripting (XSS)][xss]\nattack, use of `mdast-util-from-markdown` can also be unsafe.\n\nWhen going to HTML, use this utility in combination with [`hast-util-sanitize`][hast-util-sanitize] to make the tree safe.\n\n## Related\n\n- [`mdast-util-to-markdown`][mdast-util-to-markdown] \u0026mdash; serialize mdast as markdown\n- [`micromark`][micromark] \u0026mdash; parse markdown\n- [`remark`][remark] \u0026mdash; process markdown\n\n## Contribute\n\nSee [`CONTRIBUTING.md`](CONTRIBUTING.md).\n\n[encoding]: https://nodejs.org/api/util.html#whatwg-supported-encodings\n[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c\n[esmsh]: https://esm.sh/\n[hast-util-sanitize]: https://github.com/syntax-tree/hast-util-sanitize\n[mdast-util-directive]: https://github.com/syntax-tree/mdast-util-directive\n[mdast-util-frontmatter]: https://github.com/syntax-tree/mdast-util-frontmatter\n[mdast-util-gfm-autolink-literal]: https://github.com/syntax-tree/mdast-util-gfm-autolink-literal\n[mdast-util-gfm-footnote]: https://github.com/syntax-tree/mdast-util-gfm-footnote\n[mdast-util-gfm-strikethrough]: https://github.com/syntax-tree/mdast-util-gfm-strikethrough\n[mdast-util-gfm-table]: https://github.com/syntax-tree/mdast-util-gfm-table\n[mdast-util-gfm-task-list-item]: https://github.com/syntax-tree/mdast-util-gfm-task-list-item\n[mdast-util-gfm]: https://github.com/syntax-tree/mdast-util-gfm\n[mdast-util-math]: https://github.com/syntax-tree/mdast-util-math\n[mdast-util-mdx-expression]: https://github.com/syntax-tree/mdast-util-mdx-expression\n[mdast-util-mdx-jsx]: https://github.com/syntax-tree/mdast-util-mdx-jsx\n[mdast-util-mdx]: https://github.com/syntax-tree/mdast-util-mdx\n[mdast-util-mdxjs-esm]: https://github.com/syntax-tree/mdast-util-mdxjs-esm\n[mdast-util-to-markdown]: https://github.com/syntax-tree/mdast-util-to-markdown\n[mdast]: https://github.com/syntax-tree/mdast\n[micromark-extension]: https://github.com/micromark/micromark#extensions\n[micromark-util-types]: https://github.com/micromark/micromark/tree/main/packages/micromark-util-types\n[micromark]: https://github.com/micromark/micromark\n[phrasing-content]: https://github.com/syntax-tree/mdast#phrasingcontent\n[remark]: https://github.com/remarkjs/remark\n[root]: https://github.com/syntax-tree/mdast#root\n[typescript]: https://www.typescriptlang.org\n[uint8-array]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array\n[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting\n[yarn]: https://yarnpkg.com\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflex-development%2Fmdast-util-from-markdown","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflex-development%2Fmdast-util-from-markdown","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflex-development%2Fmdast-util-from-markdown/lists"}