Created
November 5, 2015 20:32
-
-
Save jamesacklin/715da099fe2d496eb678 to your computer and use it in GitHub Desktop.
Modify Jekyll on Github Pages' image & alt-text behavior to work with figures and figcaptions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
/* Pulls images with alt text out of paragraphs, puts them into <figure> elements with <figcaption>s */ | |
var imgs = document.querySelectorAll('article p img'); | |
[].forEach.call(imgs, function(e){ | |
var d = document.createElement('figure'); | |
d.innerHTML = '<img src="' + e.src + '" alt="' + e.alt + '"><figcaption>' + e.alt + '</figcaption>'; | |
e.parentNode.insertBefore(d, e); | |
e.parentNode.removeChild(e); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
e.parentNode.replaceChild(d, e);
would cut a line out