mdx
js/format/mdx.ts
fino:format/mdx — compile trusted MDX slide documents into Fino UI modules.
The compiler extends fino:format/markdown rather than introducing a second
Markdown implementation. The existing block parser handles CommonMark/GFM
structure, while this module protects MDX expressions and JSX during inline
rendering, converts Markdown elements to component lookups, preserves ESM,
and sends the generated TSX through Fino's Oxc compiler.
Top-level --- thematic breaks become slide boundaries. MDX is executable
application code and must not be compiled from untrusted user input.
Remark/rehype plugins and React provider semantics are not supported.
Useful references:
import { compileMdx } from 'fino:format/mdx';
const result = compileMdx('# Hello, {props.name}', { filename: 'talk.mdx' });
if (!result.ok) console.error(result.diagnostics);Interfaces
interface MdxDiagnostic {
Source location attached to an MDX compiler diagnostic.
Properties
message: string
Human-readable parser or transformer message.
line: number
One-based source line.
column: number
One-based source column.
offset: number
Zero-based source offset.
source: string
Diagnostic implementation namespace.
ruleId: string
Stable diagnostic rule identifier when available.
interface MdxCompileResult {
Successful or failed MDX compilation result.
Properties
ok: boolean
Whether parsing and transformation succeeded.
code: string
Executable ESM JavaScript, or an empty string on failure.
map: string
Version-three source map JSON, or an empty string on failure.
diagnostics: MdxDiagnostic[]
Positioned diagnostics collected during compilation.
interface MdxCompileOptions {
Options controlling one MDX compilation.
Properties
filename?: string
Original source filename used in diagnostics and source maps.
Functions
function compileMdx(source: string, options: MdxCompileOptions = {}): MdxCompileResult
Compile one trusted MDX document into an executable Fino UI ESM module.
source uses the same Markdown behavior as fino:format/markdown, plus ESM,
expressions, JSX, and slide separators. options.filename defaults to
module.mdx and is retained in diagnostics and source-map metadata. Syntax
failures are returned rather than thrown.