Files
website/node_modules/@astropub/md/lib/component.js
2024-05-06 17:15:30 -04:00

54 lines
1.2 KiB
JavaScript

import { renderSlot } from 'astro/runtime/server/index.js'
import { markdown } from './markdown.js'
export const Markdown = Object.assign(
function Markdown(result, attributes, slots) {
return {
get [Symbol.toStringTag]() {
return 'AstroComponent'
},
async *[Symbol.asyncIterator]() {
const mdl = attributes.of
if (typeof mdl === 'string') {
yield await markdown(mdl, {
fileURL: new URL(import.meta.url),
contentDir: new URL('./', import.meta.url),
})
} else {
yield renderSlot(result, slots.default)
}
},
}
},
{
isAstroComponentFactory: true,
Inline: Object.assign(
function MarkdownInline(result, attributes, slots) {
return {
get [Symbol.toStringTag]() {
return 'AstroComponent'
},
async *[Symbol.asyncIterator]() {
const mdl = attributes.of
if (typeof mdl === 'string') {
yield await markdown.inline(mdl, {
fileURL: new URL(import.meta.url),
contentDir: new URL('./', import.meta.url),
})
} else {
yield renderSlot(result, slots.default)
}
},
}
},
{
isAstroComponentFactory: true,
}
)
}
)
export default Markdown