rehype-footnotes-title
Advanced tools
Comparing version 0.0.32 to 1.0.0
@@ -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 @@ } |
{ | ||
"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 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
5914
93
1
1
+ Added@types/unist@2.0.11(transitive)
+ Addedunist-util-is@4.1.0(transitive)
+ Addedunist-util-visit@2.0.3(transitive)
+ Addedunist-util-visit-parents@3.1.1(transitive)
- Removedunist-util-is@3.0.0(transitive)
- Removedunist-util-visit@1.4.1(transitive)
- Removedunist-util-visit-parents@2.1.2(transitive)
Updatedunist-util-visit@^2.0.1