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

rehype-footnotes-title

Package Overview
Dependencies
Maintainers
2
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rehype-footnotes-title - npm Package Compare versions

Comparing version 0.0.32 to 1.0.0

36

dist/index.js

@@ -5,2 +5,23 @@ "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 plugin() {

@@ -14,4 +35,13 @@ var title = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';

function visitor(node, index, parent) {
if (node.tagName === 'a' && node.properties.className && node.properties.className.includes('footnote-backref')) {
var identifier = parent.properties.id.slice(3);
if (node.tagName === 'li' && node.properties.id) {
if (!node.children || !node.children.length) return;
var aTag = findLastLink(node, 'footnote-backref');
if (!aTag) {
var pTag = findLastTag(node, 'p');
aTag = findLastLink(pTag, 'footnote-backref');
}
if (!aTag) return;
var identifier = node.properties.id.slice(3);
var placeholderIndex = title.indexOf('$id');

@@ -27,3 +57,3 @@ var thisTitle;

if (!thisTitle) thisTitle = identifier;
node.properties.title = thisTitle;
aTag.properties.title = thisTitle;
}

@@ -30,0 +60,0 @@ }

6

package.json
{
"name": "rehype-footnotes-title",
"version": "0.0.32",
"version": "1.0.0",
"repository": {

@@ -35,5 +35,5 @@ "url": "https://github.com/zestedesavoir/zmarkdown/tree/master/packages/rehype-footnotes-title",

"dependencies": {
"unist-util-visit": "^1.3.1"
"unist-util-visit": "^2.0.1"
},
"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 plugin (title = '') {

@@ -9,10 +25,18 @@ function transformer (tree) {

function visitor (node, index, parent) {
if (
node.tagName === 'a' &&
node.properties.className &&
node.properties.className.includes('footnote-backref')
) {
const identifier = parent.properties.id.slice(3)
if (node.tagName === 'li' && node.properties.id) {
if (!node.children || !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
const identifier = node.properties.id.slice(3)
const placeholderIndex = title.indexOf('$id')
let thisTitle
if (placeholderIndex !== -1) {

@@ -24,3 +48,3 @@ thisTitle = title.split('')

if (!thisTitle) thisTitle = identifier
node.properties.title = thisTitle
aTag.properties.title = thisTitle
}

@@ -27,0 +51,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