Implementation:Microsoft Playwright Markdown Parser
| Knowledge Sources | |
|---|---|
| Domains | Documentation Tooling, Markdown Processing |
| Last Updated | 2026-02-12 00:00 GMT |
Overview
Concrete tool for parsing and rendering Markdown documentation provided by the Playwright library.
Description
The `markdown.js` module provides a custom Markdown parser and renderer used by Playwright's documentation tooling. It parses Markdown content into a tree of typed nodes (`MarkdownTextNode`, `MarkdownHeaderNode`, `MarkdownLiNode`, `MarkdownCodeNode`, `MarkdownNoteNode`, `MarkdownPropsNode`, `MarkdownNullNode`) and can render the tree back to formatted Markdown text. The parser handles headers (h0-h4), bullet and ordered lists, code blocks (with language, title, and highlight metadata), notes (with Docusaurus and compact rendering modes), properties blocks, and text content with wrapped line handling. The renderer supports configurable options including max column width, text wrapping, code block title rendering, and note format modes. Additional utilities include `clone` for deep-copying node trees, `visit`/`visitAll` for tree traversal, `filterNodesForLanguage` for language-specific content filtering, and `wrapText` for text column wrapping.
Usage
Use this module in Playwright's build and documentation tooling for processing API documentation Markdown files, generating language-specific documentation, and formatting Markdown output.
Code Reference
Source Location
- Repository: Microsoft_Playwright
- File: utils/markdown.js
Signature
/**
* @typedef {MarkdownTextNode | MarkdownLiNode | MarkdownCodeNode | MarkdownNoteNode | MarkdownHeaderNode | MarkdownNullNode | MarkdownPropsNode} MarkdownNode
*/
function parse(content: string): MarkdownNode[];
function render(nodes: MarkdownNode[], options?: RenderOptions): string;
function clone(node: MarkdownNode): MarkdownNode;
function visitAll(nodes: MarkdownNode[], visitor: (node: MarkdownNode) => void): void;
function visit(node: MarkdownNode, visitor: (node: MarkdownNode, depth: number) => void, depth?: number): void;
function filterNodesForLanguage(nodes: MarkdownNode[], language: string): MarkdownNode[];
function wrapText(text: string, options: RenderOptions, prefix: string): string;
module.exports = { parse, render, clone, visitAll, visit, filterNodesForLanguage, wrapText };
Import
const { parse, render, clone, visit, visitAll, filterNodesForLanguage } = require('./markdown');
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| content | string | Yes | Raw Markdown text to parse |
| nodes | MarkdownNode[] | Yes | Array of parsed Markdown nodes to render |
| options | RenderOptions | No | Rendering options (maxColumns, omitLastCR, flattenText, noteMode) |
| language | string | No | Target language for filtering language-specific content blocks |
Outputs
| Name | Type | Description |
|---|---|---|
| nodes | MarkdownNode[] | Parsed Markdown tree as an array of typed nodes |
| text | string | Rendered Markdown text from the node tree |
| cloned | MarkdownNode | Deep copy of a Markdown node |
Usage Examples
const { parse, render, visit, filterNodesForLanguage } = require('./utils/markdown');
// Parse Markdown content
const nodes = parse('# Title\n\nSome text\n\n```js\nconsole.log("hello");\n```\n');
// Visit all nodes
visit(nodes[0], (node, depth) => {
console.log(' '.repeat(depth) + node.type);
});
// Filter for a specific language
const jsNodes = filterNodesForLanguage(nodes, 'js');
// Render back to Markdown
const output = render(jsNodes, { maxColumns: 80 });