Guides

API Reference

useNizel(options?)

Creates a Nizel processor instance.

import { useNizel } from 'nizel';

const nizel = useNizel(options);

Options

OptionTypeDefaultDescription
output`'html' \'ast' \'text'`'html'Main output format
frontmatterbooleantrueExtract YAML frontmatter
tocbooleantrueGenerate table of contents
anchorsbooleantrueAdd id attributes to headings
slugStyle`'github' \'classic'`'github'Slug generation style
elementsobject{}Customize HTML element output
pluginsarray[]Plugin instances
presetstringundefinedBuilt-in preset name
safebooleantrueSanitize output
variablesobject{}Template variables
autolinks`boolean \object`{ enabled: true }Auto-link URLs

Usage

const nizel = useNizel({
  output: 'html',
  frontmatter: true,
  toc: true,
  anchors: true,
});

nizel(markdown, runtimeOptions?)

Parse Markdown and return a structured result.

const data = await nizel(markdown, runtimeOptions);

Parameters

  • markdown string — The Markdown source text.
  • runtimeOptions object — Optional per-call overrides.

Runtime Options

OptionTypeDescription
variablesobjectTemplate variables for this call

Return Value

Returns a NizelResult object. See Result Object.

useNizel().parse(markdown)

Returns the raw AST without rendering. This is an async method.

const ast = await nizel.parse('# Hello');

useNizel().render(ast)

Renders an AST to HTML.

const html = nizel.render(ast);

htmlToMarkdown(html, options?)

Converts semantic HTML into Markdown.

import { htmlToMarkdown } from 'nizel';

const markdown = htmlToMarkdown('<h1>Intro</h1><p>Hello <strong>world</strong>.</p>');

Options

OptionTypeDefaultDescription
unsupported`'preserve' \'drop'`'preserve'Preserve HTML that Markdown cannot represent, or drop unsupported markup and keep readable text where possible.

See HTML to Markdown for conversion rules and unsupported HTML policy.

Browser API

Browser-specific helpers are available from nizel/browser.

import {
  htmlToMarkdown,
  markdownToHtml,
  mountMarkdown,
  selectionToMarkdown,
  useBrowserNizel,
} from 'nizel/browser';

const html = await markdownToHtml('# Preview');
const markdown = htmlToMarkdown(document.querySelector('article')!);
const selected = selectionToMarkdown();

await mountMarkdown('#preview', '# Preview');

const nizel = useBrowserNizel();
await nizel.mount('#preview', '# Preview');

The browser entry also exports the core API (useNizel, defineNizelPlugin, defineBlock, and types), so it can be used as the single Nizel entry in browser bundles.

For embedded webviews such as WKWebView, the package build emits explicit browser artifacts:

dist/browser/nizel.js       ESM bundle
dist/browser/nizel.iife.js  IIFE bundle exposing globalThis.Nizel

Use dist/browser/nizel.iife.js when loading scripts directly into a webview, then call Nizel.markdownToHtml(), Nizel.htmlToMarkdown(), or Nizel.useBrowserNizel() from the preview bridge.

If the native app should expose plugin settings, use nizel-kit instead of the core browser bundle. See NizelKit for Native Apps.