Guide
Custom components
Override Comark component tags with jasy element factories for barcodes, charts, or alerts.
Override any Comark component tag with a jasy element factory. Pass host-owned factories for barcodes, charts, or other optional features — comark-pdf does not depend on comark-etiket or etiket.
import { renderPdf, parseLengthToPt, sanitizeSvgLengths } from 'comark-pdf'
import { Box, Svg, Text } from '@jasy/pdf'
import { etiketTags, renderEtiketSvg } from 'comark-etiket'
const etiketComponents = Object.fromEntries(
[...etiketTags].map(tag => [
tag,
async ([directiveTag, rawAttrs], ctx) => {
const attrs = ctx.resolveAttrs(rawAttrs)
const svg = await renderEtiketSvg(String(directiveTag), attrs, {
defaults: ctx.frontmatter?.etiket as Record<string, unknown> | undefined,
})
if (!svg) return null
return Svg(sanitizeSvgLengths(svg), {
width: typeof attrs.size === 'string' ? parseLengthToPt(attrs.size) : undefined,
})
},
]),
)
const bytes = await renderPdf(markdown, {
components: {
...etiketComponents,
alert: ([, attrs, ...children], ctx) =>
Box({ bg: '#fff3cd', padding: 12, radius: 4 }, ctx.mapNodes(children)),
},
})
Factory signature
Each factory is a JasyComponentFn: it receives the component node tuple and a context with resolveAttrs, mapNodes, and frontmatter. Return a jasy element, or null to skip.
jasy-only features
AcroForm fields, Canvas, keepTogether, hyphenation, and @jasy/zugferd are not markdown features. Expose them through components when a host needs them. See Host options.