stringifyMinimark

Serialize a Minimark-like AST into Markdown, supporting headings, lists, tables, and inline marks, and falling back to HTML for unsupported tags.

Usage

stringifyMinimark serializes a Minimark-like AST subset into Markdown. Supported nodes are output as Markdown; unsupported tags fall back to HTML. This function is not a byte-level equivalent replacement for minimark.stringify().

import { stringifyMinimark } from '@movk/core'

stringifyMinimark({
  value: [
    ['h1', {}, 'Title'],
    ['p', {}, 'Hello ', ['strong', {}, 'world']],
  ],
})
// => "# Title\n\nHello **world**\n"

Lists and Tables

stringifyMinimark({
  value: [
    ['ul', {}, ['li', {}, 'first'], ['li', {}, 'second']],
  ],
})
// => "- first\n- second\n"

HTML Fallback

stringifyMinimark({
  value: [
    ['div', { class: 'note' }, ['p', {}, 'content']],
  ],
})
// => unsupported div tag falls back to HTML output

API

stringifyMinimark(body)

Serializes a Minimark-like document body into Markdown.

Parameters

body
MinimarkDocument required
The Minimark-like document body to serialize.

Returns

returns
string
A Markdown string with HTML fallback, ending with a single newline.

MinimarkNode

MinimarkNode
string | [tag, attributes, ...children]
A Minimark-like AST node. String nodes represent text content; tuple nodes use the [tag, attributes, ...children] structure to represent elements.

MinimarkDocument

value
MinimarkNode[]
The root node list of the document body.

Changelog

No recent changes
Copyright © 2024 - 2026 YiXuan - MIT License