Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rehype-postfix-footnote-anchors

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rehype-postfix-footnote-anchors - npm Package Compare versions

Comparing version 1.0.8 to 2.0.0

63

dist/index.js

@@ -5,2 +5,35 @@ "use strict";

function findLastTag(node) {
var tag = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'p';
if (!node.children || !node.children.length) return;
var links = node.children.filter(function (e) {
return e.tagName === tag;
});
if (!links.length) return;
return links[links.length - 1];
}
function findLastLink(node, className) {
if (!node.children || !node.children.length) return;
var links = node.children.filter(function (e) {
return e.tagName === 'a';
});
if (!links.length) return;
var aTag = links[links.length - 1];
if (!aTag.properties || !aTag.properties.className || !aTag.properties.className.includes(className)) return;
return aTag;
}
function setPostfix(node, aTag, postfix) {
if (typeof postfix === 'function') {
var id = node.properties.id;
node.properties.id = postfix(id);
var link = aTag.properties.href;
aTag.properties.href = "#".concat(postfix(link.substr(1)));
} else {
node.properties.id += postfix;
aTag.properties.href += postfix;
}
}
function plugin() {

@@ -15,13 +48,12 @@ var postfix = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '-postfix';

if (!node.properties.id.startsWith('fn-')) return;
if (!node.children.length || node.children[node.children.length - 2].tagName !== 'a') return;
if (!node.children.length) return;
var aTag = findLastLink(node, 'footnote-backref');
if (typeof postfix === 'function') {
var id = node.properties.id;
node.properties.id = postfix(id);
var link = node.children[node.children.length - 2].properties.href;
node.children[node.children.length - 2].properties.href = "#".concat(postfix(link.substr(1)));
} else {
node.properties.id += postfix;
node.children[node.children.length - 2].properties.href += postfix;
if (!aTag) {
var pTag = findLastTag(node, 'p');
aTag = findLastLink(pTag, 'footnote-backref');
}
if (!aTag) return;
setPostfix(node, aTag, postfix);
}

@@ -33,12 +65,5 @@

if (!node.children.length || node.children[0].tagName !== 'a') return;
if (typeof postfix === 'function') {
var _id = node.properties.id;
node.properties.id = postfix(_id);
var _link = node.children[0].properties.href;
node.children[0].properties.href = "#".concat(postfix(_link.substr(1)));
} else {
node.properties.id += postfix;
node.children[0].properties.href += postfix;
}
var _aTag = node.children[0];
if (!_aTag.properties || !_aTag.properties.className || !_aTag.properties.className.includes('footnote-ref')) return;
setPostfix(node, _aTag, postfix);
}

@@ -45,0 +70,0 @@ });

{
"name": "rehype-postfix-footnote-anchors",
"version": "1.0.8",
"version": "2.0.0",
"repository": {

@@ -36,8 +36,8 @@ "url": "https://github.com/zestedesavoir/zmarkdown/tree/master/packages/rehype-postfix-footnote-anchors",

"dependencies": {
"unist-util-visit": "^1.3.1"
"unist-util-visit": "^2.0.1"
},
"devDependencies": {
"remark-numbered-footnotes": "^1.1.0"
"remark-numbered-footnotes": "^2.0.0"
},
"gitHead": "b05f25a9f9f7be3c2987fb3c07f48cc1b43ca2aa"
"gitHead": "c2bf169996c4adfdf75a55290080947a2384c09f"
}
const visit = require('unist-util-visit')
function findLastTag (node, tag = 'p') {
if (!node.children || !node.children.length) return
const links = node.children.filter(e => e.tagName === tag)
if (!links.length) return
return links[links.length - 1]
}
function findLastLink (node, className) {
if (!node.children || !node.children.length) return
const links = node.children.filter(e => e.tagName === 'a')
if (!links.length) return
const aTag = links[links.length - 1]
if (!aTag.properties || !aTag.properties.className ||
!aTag.properties.className.includes(className)) return
return aTag
}
function setPostfix (node, aTag, postfix) {
if (typeof postfix === 'function') {
const id = node.properties.id
node.properties.id = postfix(id)
const link = aTag.properties.href
aTag.properties.href = `#${postfix(link.substr(1))}`
} else {
node.properties.id += postfix
aTag.properties.href += postfix
}
}
function plugin (postfix = '-postfix') {

@@ -10,13 +37,13 @@ return (tree) => {

if (!node.properties.id.startsWith('fn-')) return
if (!node.children.length || node.children[node.children.length - 2].tagName !== 'a') return
if (typeof postfix === 'function') {
const id = node.properties.id
node.properties.id = postfix(id)
const link = node.children[node.children.length - 2].properties.href
node.children[node.children.length - 2].properties.href = `#${postfix(link.substr(1))}`
} else {
node.properties.id += postfix
node.children[node.children.length - 2].properties.href += postfix
if (!node.children.length) return
let aTag = findLastLink(node, 'footnote-backref')
if (!aTag) {
const pTag = findLastTag(node, 'p')
aTag = findLastLink(pTag, 'footnote-backref')
}
if (!aTag) return
setPostfix(node, aTag, postfix)
}

@@ -29,11 +56,8 @@

if (typeof postfix === 'function') {
const id = node.properties.id
node.properties.id = postfix(id)
const link = node.children[0].properties.href
node.children[0].properties.href = `#${postfix(link.substr(1))}`
} else {
node.properties.id += postfix
node.children[0].properties.href += postfix
}
const aTag = node.children[0]
if (!aTag.properties || !aTag.properties.className ||
!aTag.properties.className.includes('footnote-ref')) return
setPostfix(node, aTag, postfix)
}

@@ -40,0 +64,0 @@ })

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