@connectv/marked
Version:
component-based markdown renderer
28 lines • 1.18 kB
JavaScript
import { extractCompProps } from './util/extract-comp-props';
export function quotedComponents(map) {
return function (_, renderer, content) {
var _a;
let ref = renderer.create("marker", null, content);
if ((_a = ref.childNodes[0].textContent) === null || _a === void 0 ? void 0 : _a.startsWith(':')) {
const parts = ref.childNodes[0].textContent.substr(1).split(' ');
const name = parts[0];
if (name in map) {
const Comp = map[name];
const props = extractCompProps(parts.slice(1).join(' '));
const children = [];
ref.childNodes.forEach((child, index) => { if (index >= 1)
children.push(child); });
return renderer.create(Comp, props, children);
}
else {
throw new Error('Unrecognized Quoted Component:: ' + name);
}
}
else {
const children = [];
ref.childNodes.forEach(child => children.push(child));
return renderer.create("blockquote", null, children);
}
};
}
//# sourceMappingURL=quote-comp.js.map