New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@amanda-mitchell/remark-renumber-footnotes

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@amanda-mitchell/remark-renumber-footnotes - npm Package Compare versions

Comparing version 2.0.0 to 3.0.0

dist/__tests__/index.d.ts

101

index.js

@@ -1,100 +0,1 @@

import is from 'unist-util-is';
const isFootnoteReference = is.convert('footnoteReference');
const isFootnoteDefinition = is.convert('footnoteDefinition');
const isFootnote = is.convert('footnote');
function findFootnoteNodes(node) {
if (
isFootnote(node) ||
isFootnoteReference(node) ||
isFootnoteDefinition(node)
) {
return [node];
}
if (!node.children) {
return [];
}
return node.children.flatMap(findFootnoteNodes);
}
function isNumeric(text) {
return /^\d+$/.test(text);
}
function applyNewIdentifiers(node, remappedIdentifiers) {
if (isFootnoteReference(node) || isFootnoteDefinition(node)) {
const identifier = remappedIdentifiers[node.identifier];
if (!identifier) {
return node;
}
return { ...node, identifier, label: identifier };
}
if (!node.children) {
return node;
}
return {
...node,
children: node.children.map(child =>
applyNewIdentifiers(child, remappedIdentifiers)
),
};
}
export function renumberFootnotes(options) {
const { ignoreNonnumericFootnotes } = options || {
ignoreNonnumericFootnotes: false,
};
return function transform(tree) {
const nodes = findFootnoteNodes(tree);
let identifierCount = 0;
const remappedIdentifiers = {};
for (const node of nodes) {
if (isFootnoteDefinition(node)) {
continue;
}
if (isFootnote(node)) {
// Footnote nodes don't get an identifier until rendered
// to HTML, but we still need to account for them in our
// numbering.
++identifierCount;
continue;
}
const identifier = node.identifier;
if (ignoreNonnumericFootnotes && !isNumeric(identifier)) {
continue;
}
if (!remappedIdentifiers[identifier]) {
remappedIdentifiers[identifier] = (++identifierCount).toString();
}
}
const orphanedDefinitions = nodes.filter(
node =>
isFootnoteDefinition(node) &&
!remappedIdentifiers[node.identifier] &&
(!ignoreNonnumericFootnotes || isNumeric(node.identifier))
);
for (const node of orphanedDefinitions) {
// Two definitions might use the same identifier, so we still need
// to perform this check.
if (!remappedIdentifiers[node.identifier]) {
remappedIdentifiers[node.identifier] = (++identifierCount).toString();
}
}
return applyNewIdentifiers(tree, remappedIdentifiers);
};
}
export * from './dist/index.js';
{
"name": "@amanda-mitchell/remark-renumber-footnotes",
"version": "2.0.0",
"version": "3.0.0",
"description": "A remark-parse plugin that renumbers footnotes sequentially.",

@@ -22,14 +22,24 @@ "main": "index.js",

"type": "module",
"files": [
"index.js",
"dist/**/*.js",
"dist/**/*.map",
"dist/**/*.d.ts",
"!**/__tests__"
],
"types": "dist/index.d.ts",
"devDependencies": {
"@amanda-mitchell/node-project-scripts": "^3.4.0",
"jest": "^27.0.6",
"remark-footnotes": "^3.0.0",
"remark-html": "^13.0.1",
"remark-parse": "^9.0.0",
"unified": "^9.2.0",
"unist-builder": "^2.0.3"
"@amanda-mitchell/node-project-scripts": "4.72.1",
"@types/unist": "^3.0.2",
"jest": "^29.0.0",
"mdast": "^3.0.0",
"remark-html": "^16.0.1",
"remark-parse": "^11.0.0",
"unified": "^11.0.2",
"unist-builder": "^4.0.0"
},
"dependencies": {
"unist-util-is": "^4.0.4"
"remark-gfm": "^4.0.0",
"unist-util-is": "^6.0.0"
}
}

@@ -13,3 +13,3 @@ # @amanda-mitchell/remark-renumber-footnotes

Construct a unified parser and pass `renumerFooters` to it as a plugin:
Construct a unified parser and pass `renumberFootnotes` to it as a plugin:

@@ -19,3 +19,3 @@ ```js

const markdown = require('remark-parse');
const footnotes = require('remark-footnotes');
const remarkGfm = require('remark-gfm');
const {

@@ -28,3 +28,3 @@ renumberFootnotes,

This is a document[^2] with[^2] a couple[^1] of^[inline] footnotes[^foo].
This is a document[^2] with[^2] a couple[^1] of footnotes[^foo].

@@ -38,3 +38,3 @@ [^foo]: Last item

.use(markdown)
.use(footnotes, { inlineNotes: true })
.use(remarkGfm)
.use(renumberFootnotes)

@@ -51,12 +51,16 @@ .use(html)

```html
<p>This is a document<sup id="fnref-1"><a href="#fn-1" class="footnote-ref">1</a></sup> with<sup id="fnref-1"><a href="#fn-1" class="footnote-ref">1</a></sup> a couple<sup id="fnref-2"><a href="#fn-2" class="footnote-ref">2</a></sup> of<sup id="fnref-3"><a href="#fn-3" class="footnote-ref">3</a></sup> footnotes<sup id="fnref-4"><a href="#fn-4" class="footnote-ref">4</a></sup>.</p>
<div class="footnotes">
<hr>
<p>This is a document<sup><a href="#user-content-fn-1" id="user-content-user-content-fnref-1" data-footnote-ref aria-describedby="user-content-footnote-label">1</a></sup> with<sup><a href="#user-content-fn-1" id="user-content-user-content-fnref-1-2" data-footnote-ref aria-describedby="user-content-footnote-label">1</a></sup> a couple<sup><a href="#user-content-fn-2" id="user-content-user-content-fnref-2" data-footnote-ref aria-describedby="user-content-footnote-label">2</a></sup> of footnotes<sup><a href="#user-content-fn-3" id="user-content-user-content-fnref-3" data-footnote-ref aria-describedby="user-content-footnote-label">3</a></sup>.</p>
<section data-footnotes class="footnotes"><h2 class="sr-only" id="user-content-footnote-label">Footnotes</h2>
<ol>
<li id="fn-1">First<a href="#fnref-1" class="footnote-backref">↩</a></li>
<li id="fn-2">Second<a href="#fnref-2" class="footnote-backref">↩</a></li>
<li id="fn-3">inline<a href="#fnref-3" class="footnote-backref">↩</a></li>
<li id="fn-4">Last item<a href="#fnref-4" class="footnote-backref">↩</a></li>
<li id="user-content-user-content-fn-1">
<p>First <a href="#user-content-fnref-1" data-footnote-backref="" aria-label="Back to reference 1" class="data-footnote-backref">↩</a> <a href="#user-content-fnref-1-2" data-footnote-backref="" aria-label="Back to reference 1-2" class="data-footnote-backref">↩<sup>2</sup></a></p>
</li>
<li id="user-content-user-content-fn-2">
<p>Second <a href="#user-content-fnref-2" data-footnote-backref="" aria-label="Back to reference 2" class="data-footnote-backref">↩</a></p>
</li>
<li id="user-content-user-content-fn-3">
<p>Last item <a href="#user-content-fnref-3" data-footnote-backref="" aria-label="Back to reference 3" class="data-footnote-backref">↩</a></p>
</li>
</ol>
</div>
</section>
```

@@ -63,0 +67,0 @@ <!-- prettier-ignore-end -->

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc