mirror of
https://github.com/sern-handler/website
synced 2026-06-16 12:52:20 +00:00
38 lines
1.0 KiB
JavaScript
38 lines
1.0 KiB
JavaScript
import { createMarkdownProcessor } from '@astrojs/markdown-remark'
|
|
import { shared } from './shared.js'
|
|
import { HTMLString } from './html-string.js'
|
|
|
|
export async function markdown(
|
|
/** @type {string} */ content,
|
|
/** @type {MarkdownRenderingOptions} */ options = null
|
|
) {
|
|
const processor = await createMarkdownProcessor({
|
|
...shared.markdownConfig,
|
|
...Object(options),
|
|
});
|
|
|
|
const result = await processor.render(content);
|
|
return new HTMLString(result.code);
|
|
}
|
|
|
|
markdown.inline = async function inlinemarkdown(
|
|
/** @type {string} */ content,
|
|
/** @type {MarkdownRenderingOptions} */ options = null
|
|
) {
|
|
const processor = await createMarkdownProcessor({
|
|
...shared.markdownConfig,
|
|
...Object(options),
|
|
});
|
|
|
|
const result = await processor.render(content);
|
|
|
|
return new HTMLString(
|
|
result.code.indexOf("<p>") === 0 &&
|
|
result.code.indexOf("</p>") === result.code.length - 4
|
|
? result.code.slice(3, -4)
|
|
: result.code,
|
|
);
|
|
};
|
|
|
|
/** @typedef {import('./markdown').MarkdownRenderingOptions} MarkdownRenderingOptions */
|