MCPcopy
hub / github.com/vercel/streamdown / post

Function post

packages/streamdown/lib/markdown.ts:289–350  ·  view source on GitHub ↗
(tree: Nodes, options: Readonly<Options>)

Source from the content-addressed store, hash-verified

287};
288
289const post = (tree: Nodes, options: Readonly<Options>): ReactElement => {
290 const {
291 allowElement,
292 allowedElements,
293 disallowedElements,
294 skipHtml,
295 unwrapDisallowed,
296 urlTransform,
297 } = options;
298
299 const hasFiltering =
300 allowElement ||
301 allowedElements ||
302 disallowedElements ||
303 skipHtml ||
304 urlTransform;
305
306 if (hasFiltering) {
307 const transform = urlTransform || defaultUrlTransform;
308
309 visit(tree as Root, (node, index, parent) => {
310 /* v8 ignore next */
311 if (node.type === "raw" && parent && typeof index === "number") {
312 /* v8 ignore next */
313 handleRawNode(parent, index, skipHtml, node.value);
314 return index;
315 }
316
317 if (node.type === "element") {
318 transformUrls(node, transform);
319
320 const remove = shouldRemoveElement(
321 node,
322 index,
323 parent,
324 allowedElements,
325 disallowedElements,
326 allowElement
327 );
328
329 if (remove && parent && typeof index === "number") {
330 if (unwrapDisallowed && node.children) {
331 parent.children.splice(index, 1, ...node.children);
332 } else {
333 parent.children.splice(index, 1);
334 }
335 return index;
336 }
337 }
338 });
339 }
340
341 return toJsxRuntime(tree, {
342 Fragment,
343 components: options.components,
344 ignoreInvalidStyle: true,
345 jsx,
346 jsxs,

Callers 1

MarkdownFunction · 0.85

Calls 3

handleRawNodeFunction · 0.85
transformUrlsFunction · 0.85
shouldRemoveElementFunction · 0.85

Tested by

no test coverage detected