Last active
May 27, 2022 15:52
-
-
Save rxian/6f0e666dda9ced66e940b976f0a72a3e to your computer and use it in GitHub Desktop.
Obsidian JS snippet for centering images
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
// Use with JavaScript Init plugin (https://github.com/ryanpcmcquen/obsidian-javascript-init) | |
var observer = new MutationObserver(function(mutationsList, observer) { | |
mutationsList.forEach(function(mutation) { | |
mutation.addedNodes.forEach(function(addedNode) { | |
addedNode.querySelectorAll('.image-embed').forEach(function(e) { | |
e.parentNode.style["text-align"] = "center"; | |
}); | |
}); | |
}); | |
}); | |
observer.observe(document.querySelector('.markdown-preview-section'), {subtree: true, childList: true}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment