Add pretty print code selectors on load

develop
Nikita Tokarchuk 3 years ago
parent b8fd70bf76
commit d6e2fffcaf
Signed by: mainnika
GPG Key ID: A595FB7E3E56911C
  1. 34
      web/index.js

@ -1,8 +1,34 @@
import "code-prettify/styles/desert.css" import "code-prettify/styles/desert.css";
import "bootstrap-icons/font/bootstrap-icons.css" import "bootstrap-icons/font/bootstrap-icons.css";
import "code-prettify" import "code-prettify";
import "./style/index.scss" import "./style/index.scss";
const applyPrettyPrint = () => {
const blogPosts = document.getElementsByClassName("blog-post-content");
for (const blogPost of blogPosts) {
const codeBlocks = blogPost.getElementsByTagName("code");
for (const codeBlock of codeBlocks) {
codeBlock.parentElement.classList.add("prettyprint", "linenums", "kg-card", "kg-code-card");
}
}
PR.prettyPrint(); PR.prettyPrint();
}
const init = () => {
applyPrettyPrint();
}
if (document.readyState === "complete" || document.readyState === "interactive") {
requestAnimationFrame(init);
} else {
document.addEventListener("DOMContentLoaded", init);
}

Loading…
Cancel
Save