remark-caml
Version:
A remark plugin for caml (semantic) attributes in markdown.
46 lines (40 loc) • 1.72 kB
JavaScript
// remark-caml v0.0.5-rm - https://github.com/wikibonsai/remark-caml.git
import { syntaxCaml } from 'micromark-extension-caml';
import { fromMarkdownCaml, toMarkdownCaml, initAttrBox } from 'mdast-util-caml';
var warningIssued = false;
function remarkV13Warning(context) {
if (!warningIssued && (context.Parser && context.Parser.prototype && context.Parser.prototype.blockTokenizers || context.Compiler && context.Compiler.prototype && context.Compiler.prototype.visitors)) {
warningIssued = true;
console.warn('[remark-caml] Warning: please upgrade to remark 13 to use this plugin');
}
return warningIssued;
}
function remarkCaml(opts) {
var _opts$attrs$render, _opts$attrs;
var doRenderAttrBox = (_opts$attrs$render = opts === null || opts === void 0 ? void 0 : (_opts$attrs = opts.attrs) === null || _opts$attrs === void 0 ? void 0 : _opts$attrs.render) !== null && _opts$attrs$render !== void 0 ? _opts$attrs$render : true;
var data = this.data();
// warn for earlier versions
remarkV13Warning(this);
add('micromarkExtensions', syntaxCaml(opts));
add('fromMarkdownExtensions', fromMarkdownCaml(opts));
add('toMarkdownExtensions', toMarkdownCaml(opts));
function add(field, value) {
if (data[field]) {
data[field].push(value);
} else {
data[field] = [value];
}
}
// ref: https://github.com/remarkjs/remark-toc/blob/main/lib/index.js#L36
return function (tree) {
if (doRenderAttrBox) {
var attrbox = initAttrBox(tree, opts);
// place attrbox at the beginning of the tree content
if (attrbox !== undefined) {
tree.children.unshift(attrbox);
}
}
};
}
export { remarkCaml };
//# sourceMappingURL=index.js.map