myst-transforms
Advanced tools
Comparing version 0.0.23 to 0.0.24
@@ -5,4 +5,2 @@ "use strict"; | ||
var unist_util_select_1 = require("unist-util-select"); | ||
var unist_util_remove_1 = require("unist-util-remove"); | ||
var keys_1 = require("./keys"); | ||
var myst_common_1 = require("myst-common"); | ||
@@ -16,10 +14,9 @@ function nextNumber(current, reserved) { | ||
var TRANSFORM_SOURCE = 'myst-transforms:footnotes'; | ||
function footnotesTransform(mdast, file, opts) { | ||
function footnotesTransform(mdast, file) { | ||
var footnotes = (0, unist_util_select_1.selectAll)('footnoteDefinition', mdast); | ||
opts.references.footnotes = Object.fromEntries(footnotes.map(function (n) { | ||
var footnotesLookup = Object.fromEntries(footnotes.map(function (n) { | ||
// Clear out the number | ||
delete n.number; | ||
return [n.identifier, (0, keys_1.keysTransform)(n)]; | ||
return [n.identifier, n]; | ||
})); | ||
(0, unist_util_remove_1.remove)(mdast, 'footnoteDefinition'); | ||
var references = (0, unist_util_select_1.selectAll)('footnoteReference', mdast); | ||
@@ -29,3 +26,2 @@ var reserved = new Set(references.map(function (r) { return Number(r.identifier); }).filter(function (num) { return !Number.isNaN(num) && num > 0; })); | ||
references.forEach(function (node) { | ||
var _a; | ||
if (!node.identifier) { | ||
@@ -38,3 +34,3 @@ (0, myst_common_1.fileWarn)(file, 'FootnoteReference does not have an identifier', { | ||
} | ||
var def = (_a = opts.references.footnotes) === null || _a === void 0 ? void 0 : _a[node.identifier]; | ||
var def = footnotesLookup[node.identifier]; | ||
if (!def) { | ||
@@ -60,5 +56,5 @@ (0, myst_common_1.fileWarn)(file, "No footnoteDefinition found for ".concat(node.identifier), { | ||
exports.footnotesTransform = footnotesTransform; | ||
var footnotesPlugin = function (opts) { return function (tree, file) { | ||
footnotesTransform(tree, file, opts); | ||
var footnotesPlugin = function () { return function (tree, file) { | ||
footnotesTransform(tree, file); | ||
}; }; | ||
exports.footnotesPlugin = footnotesPlugin; |
import { selectAll } from 'unist-util-select'; | ||
import { remove } from 'unist-util-remove'; | ||
import { keysTransform } from './keys'; | ||
import { fileWarn } from 'myst-common'; | ||
@@ -12,10 +10,9 @@ function nextNumber(current, reserved) { | ||
var TRANSFORM_SOURCE = 'myst-transforms:footnotes'; | ||
export function footnotesTransform(mdast, file, opts) { | ||
export function footnotesTransform(mdast, file) { | ||
var footnotes = selectAll('footnoteDefinition', mdast); | ||
opts.references.footnotes = Object.fromEntries(footnotes.map(function (n) { | ||
var footnotesLookup = Object.fromEntries(footnotes.map(function (n) { | ||
// Clear out the number | ||
delete n.number; | ||
return [n.identifier, keysTransform(n)]; | ||
return [n.identifier, n]; | ||
})); | ||
remove(mdast, 'footnoteDefinition'); | ||
var references = selectAll('footnoteReference', mdast); | ||
@@ -25,3 +22,2 @@ var reserved = new Set(references.map(function (r) { return Number(r.identifier); }).filter(function (num) { return !Number.isNaN(num) && num > 0; })); | ||
references.forEach(function (node) { | ||
var _a; | ||
if (!node.identifier) { | ||
@@ -34,3 +30,3 @@ fileWarn(file, 'FootnoteReference does not have an identifier', { | ||
} | ||
var def = (_a = opts.references.footnotes) === null || _a === void 0 ? void 0 : _a[node.identifier]; | ||
var def = footnotesLookup[node.identifier]; | ||
if (!def) { | ||
@@ -55,4 +51,4 @@ fileWarn(file, "No footnoteDefinition found for ".concat(node.identifier), { | ||
} | ||
export var footnotesPlugin = function (opts) { return function (tree, file) { | ||
footnotesTransform(tree, file, opts); | ||
export var footnotesPlugin = function () { return function (tree, file) { | ||
footnotesTransform(tree, file); | ||
}; }; |
import type { Plugin } from 'unified'; | ||
import type { Root } from 'mdast'; | ||
import type { References } from 'myst-common'; | ||
import type { VFile } from 'vfile'; | ||
declare type Options = { | ||
references: Pick<References, 'footnotes'>; | ||
}; | ||
export declare function footnotesTransform(mdast: Root, file: VFile, opts: Options): void; | ||
export declare const footnotesPlugin: Plugin<[Options], Root, Root>; | ||
export {}; | ||
export declare function footnotesTransform(mdast: Root, file: VFile): void; | ||
export declare const footnotesPlugin: Plugin<[], Root, Root>; | ||
//# sourceMappingURL=footnotes.d.ts.map |
{ | ||
"name": "myst-transforms", | ||
"version": "0.0.23", | ||
"version": "0.0.24", | ||
"sideEffects": false, | ||
@@ -29,5 +29,5 @@ "main": "./dist/cjs/index.js", | ||
"mdast-util-find-and-replace": "^2.1.0", | ||
"myst-common": "^0.0.14", | ||
"myst-common": "^0.0.15", | ||
"myst-spec": "^0.0.4", | ||
"myst-spec-ext": "^0.0.9", | ||
"myst-spec-ext": "^0.0.10", | ||
"rehype-parse": "^8.0.4", | ||
@@ -38,3 +38,3 @@ "rehype-remark": "^9.1.2", | ||
"unist-util-modify-children": "^3.1.0", | ||
"unist-util-select": "^4.0.1", | ||
"unist-util-select": "^4.0.3", | ||
"vfile": "^5.0.0", | ||
@@ -41,0 +41,0 @@ "vfile-message": "^3.1.2" |
Sorry, the diff of this file is not supported yet
197292
4233
+ Addedmyst-common@0.0.15(transitive)
+ Addedmyst-spec-ext@0.0.10(transitive)
- Removedmyst-common@0.0.14(transitive)
- Removedmyst-spec-ext@0.0.9(transitive)
Updatedmyst-common@^0.0.15
Updatedmyst-spec-ext@^0.0.10
Updatedunist-util-select@^4.0.3