@xiee/utils
Advanced tools
Comparing version 1.2.9 to 1.2.10
@@ -1,14 +0,22 @@ | ||
(function() { | ||
(function(d) { | ||
function one_child(el) { | ||
if (el.childElementCount !== 1) return false; | ||
const nodes = el.childNodes; | ||
if (nodes.length === 1) return true; | ||
for (let i in nodes) { | ||
let node = nodes[i]; | ||
if (node.nodeName === '#text' && !/^\s$/.test(node.textContent)) return false; | ||
} | ||
return true; | ||
} | ||
function center_el(tagName) { | ||
var tags = document.getElementsByTagName(tagName), i, tag; | ||
for (i = 0; i < tags.length; i++) { | ||
tag = tags[i]; | ||
var parent = tag.parentElement; | ||
d.querySelectorAll(tagName).forEach(tag => { | ||
let parent = tag.parentElement; | ||
// center an image if it is the only element of its parent | ||
if (parent.childElementCount === 1) { | ||
if (one_child(parent)) { | ||
// if there is a link on image, check grandparent | ||
var parentA = parent.nodeName === 'A'; | ||
const parentA = parent.nodeName === 'A'; | ||
if (parentA) { | ||
parent = parent.parentElement; | ||
if (parent.childElementCount != 1) continue; | ||
if (!one_child(parent)) return; | ||
parent.firstElementChild.style.border = 'none'; | ||
@@ -24,13 +32,9 @@ } | ||
} | ||
} | ||
}); | ||
} | ||
var tagNames = ['img', 'embed', 'object']; | ||
for (var i = 0; i < tagNames.length; i++) { | ||
center_el(tagNames[i]); | ||
} | ||
['img', 'embed', 'object'].forEach(tag => center_el(tag)); | ||
// also center paragraphs that contain `* * *` | ||
var ps = document.getElementsByTagName('p'); | ||
for (var i = 0; i < ps.length; i++) { | ||
if (ps[i].innerText === '* * *') ps[i].style.textAlign = 'center'; | ||
}; | ||
})(); | ||
d.querySelectorAll('p').forEach(p => { | ||
if (p.innerText === '* * *') p.style.textAlign = 'center'; | ||
}); | ||
})(document); |
{ | ||
"name": "@xiee/utils", | ||
"version": "1.2.9", | ||
"version": "1.2.10", | ||
"description": "Miscellaneous tools and utilities to manipulate HTML pages", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -53,5 +53,3 @@ This repo contains miscellaneous tools and utilities written in JavaScript. They | ||
Fix links to/from footnotes rendered by lower versions of Hugo (Blackfriday) | ||
when footnotes do not contain any ASCII characters, in which case Hugo is unable | ||
to render unique `id`s for the footnote items (the `id` is `fn:-`). | ||
Add `[ ]` to footnote numbers and move the return symbols in footnotes. | ||
@@ -58,0 +56,0 @@ ## fix-toc.js |
Sorry, the diff of this file is not supported yet
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
35502
47
511
100