rehype-footnotes-title
Advanced tools
Comparing version 2.0.0 to 2.0.1
"use strict"; | ||
var visit = require('unist-util-visit'); | ||
function findLastTag(node) { | ||
var tag = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'p'; | ||
const visit = require('unist-util-visit'); | ||
function findLastTag(node, tag = 'p') { | ||
if (!node.children || !node.children.length) return; | ||
var links = node.children.filter(function (e) { | ||
return e.tagName === tag; | ||
}); | ||
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; | ||
var links = node.children.filter(function (e) { | ||
return e.tagName === 'a'; | ||
}); | ||
const links = node.children.filter(e => e.tagName === 'a'); | ||
if (!links.length) return; | ||
var aTag = links[links.length - 1]; | ||
const aTag = links[links.length - 1]; | ||
if (!aTag.properties || !aTag.properties.className || !aTag.properties.className.includes(className)) return; | ||
return aTag; | ||
} | ||
function plugin() { | ||
var title = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; | ||
function plugin(title = '') { | ||
function transformer(tree) { | ||
visit(tree, 'element', visitor); | ||
} | ||
function visitor(node, index, parent) { | ||
if (node.tagName === 'li' && node.properties.id) { | ||
if (!node.children || !node.children.length) return; | ||
var aTag = findLastLink(node, 'footnote-backref'); | ||
let aTag = findLastLink(node, 'footnote-backref'); | ||
if (!aTag) { | ||
var pTag = findLastTag(node, 'p'); | ||
const pTag = findLastTag(node, 'p'); | ||
aTag = findLastLink(pTag, 'footnote-backref'); | ||
} | ||
if (!aTag) return; | ||
var identifier = node.properties.id.slice(3); | ||
var placeholderIndex = title.indexOf('$id'); | ||
var thisTitle; | ||
const identifier = node.properties.id.slice(3); | ||
const placeholderIndex = title.indexOf('$id'); | ||
let thisTitle; | ||
if (placeholderIndex !== -1) { | ||
@@ -53,3 +39,2 @@ thisTitle = title.split(''); | ||
} | ||
if (!thisTitle) thisTitle = identifier; | ||
@@ -59,6 +44,4 @@ aTag.properties.title = thisTitle; | ||
} | ||
return transformer; | ||
} | ||
module.exports = plugin; |
{ | ||
"name": "rehype-footnotes-title", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"repository": { | ||
@@ -16,3 +16,3 @@ "url": "https://github.com/zestedesavoir/zmarkdown/tree/master/packages/rehype-footnotes-title", | ||
"pretest": "eslint .", | ||
"build": "del-cli dist && cross-env BABEL_ENV=production babel src --out-dir dist", | ||
"build": "babel --root-mode upward --delete-dir-on-start --env-name production --out-dir dist src", | ||
"test": "jest", | ||
@@ -35,3 +35,3 @@ "coverage": "jest --coverage" | ||
}, | ||
"gitHead": "7dfdfdf98ac64c3867791036ab0cf1ce45918e40" | ||
"gitHead": "b278abe5320c5ca01bdaed3c833f5f68ab389663" | ||
} |
@@ -26,3 +26,2 @@ const visit = require('unist-util-visit') | ||
if (node.tagName === 'li' && node.properties.id) { | ||
if (!node.children || !node.children.length) return | ||
@@ -29,0 +28,0 @@ let aTag = findLastLink(node, 'footnote-backref') |
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
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
5692
87