|
| 1 | +import { h } from 'hastscript'; |
| 2 | +import { visit } from 'unist-util-visit'; |
| 3 | +import { fromMarkdownDetails } from './mdast-util-details/index.js'; |
| 4 | +import { syntax } from './micromark-details/index.js'; |
| 5 | +let warningIssued = false; |
| 6 | +const remarkDetails = function (options) { |
| 7 | + var _a, _b, _c, _d; |
| 8 | + const data = this.data(); |
| 9 | + // warning for old remarks |
| 10 | + if (!warningIssued && |
| 11 | + (((_b = (_a = this.Parser) === null || _a === void 0 ? void 0 : _a.prototype) === null || _b === void 0 ? void 0 : _b.blockTokenizers) || |
| 12 | + ((_d = (_c = this.Compiler) === null || _c === void 0 ? void 0 : _c.prototype) === null || _d === void 0 ? void 0 : _d.visitors))) { |
| 13 | + warningIssued = true; |
| 14 | + console.warn('[remark-details] Warning: please upgrade to remark 13 to use this plugin'); |
| 15 | + } |
| 16 | + function add(field, value) { |
| 17 | + /* istanbul ignore if - other extensions. */ |
| 18 | + if (data[field]) |
| 19 | + data[field].push(value); |
| 20 | + else |
| 21 | + data[field] = [value]; |
| 22 | + } |
| 23 | + add('micromarkExtensions', syntax); |
| 24 | + add('fromMarkdownExtensions', fromMarkdownDetails); |
| 25 | + return transform; |
| 26 | + function transform(tree) { |
| 27 | + visit(tree, ['detailsContainer', 'detailsContainerSummary'], ondetails); |
| 28 | + } |
| 29 | + function ondetails(node) { |
| 30 | + var data = node.data || (node.data = {}); |
| 31 | + var hast = h(node.name, node.attributes); |
| 32 | + data.hName = hast.tagName; |
| 33 | + data.hProperties = hast.properties; |
| 34 | + } |
| 35 | +}; |
| 36 | +export default remarkDetails; |
0 commit comments