11import type { ParserOptions , RendererOptions } from 'comark'
22import { createMarkdownParser } from 'comark'
3- import { renderHtml } from './render.ts'
3+ import { renderHtmlFromDocument } from './render.ts'
44
5- export { renderHtml } from './render.ts'
5+ export { renderHtmlFromDocument } from './render.ts'
66
77/**
88 * Creates a reusable parse+render function with pre-configured options.
@@ -13,43 +13,43 @@ export { renderHtml } from './render.ts'
1313 *
1414 * @example
1515 * ```typescript
16- * import { createRender } from '@comark/html'
17- * import highlight from 'comark/plugins/highlight'
16+ * import { createHtmlRenderer } from '@comark/html'
17+ * import highlight from '@ comark/html /plugins/highlight'
1818 *
19- * const render = createRender ({
19+ * const renderHtml = createHtmlRenderer ({
2020 * plugins: [highlight()],
2121 * components: {
22- * alert: ([, attrs, ...children], { render }) =>
23- * `<div class="alert alert-${attrs.type}">${render(children)}</div>`
22+ * alert: async ([, attrs, ...children], { render }) =>
23+ * `<div class="alert alert-${attrs.type}">${await render(children)}</div>`
2424 * }
2525 * })
2626 *
27- * const html = await render ('# Hello\n\n**Bold** text.')
27+ * const html = await renderHtml ('# Hello\n\n**Bold** text.')
2828 * ```
2929 */
30- export function createRender ( options ?: ParserOptions & RendererOptions ) : ( markdown : string ) => Promise < string > {
31- const parse = createMarkdownParser ( options )
30+ export function createHtmlRenderer ( options ?: ParserOptions & RendererOptions ) : ( markdown : string ) => Promise < string > {
31+ const parseMarkdown = createMarkdownParser ( options )
3232 return async ( markdown : string ) => {
33- const tree = await parse ( markdown )
34- return await renderHtml ( tree , options as RendererOptions )
33+ const document = await parseMarkdown ( markdown )
34+ return await renderHtmlFromDocument ( document , options as RendererOptions )
3535 }
3636}
3737
3838/**
3939 * Parse markdown and render it to an HTML string.
4040 *
41- * @param markdown - The markdown/Comark content to render
41+ * @param markdown - The markdown content to parse and render
4242 * @param options - Optional parse and render options
4343 * @returns A Promise resolving to the HTML string
4444 *
4545 * @example
4646 * ```typescript
47- * import { render } from '@comark/html'
47+ * import { renderHtml } from '@comark/html'
4848 *
49- * const html = await render ('# Hello\n\nThis is **bold** and _italic_.')
49+ * const html = await renderHtml ('# Hello\n\nThis is **bold** and _italic_.')
5050 * document.body.innerHTML = html
5151 * ```
5252 */
53- export async function render ( markdown : string , options ?: RendererOptions ) : Promise < string > {
54- return createRender ( options ) ( markdown )
53+ export async function renderHtml ( markdown : string , options ?: ParserOptions & RendererOptions ) : Promise < string > {
54+ return createHtmlRenderer ( options ) ( markdown )
5555}
0 commit comments