diff --git a/docs/javascripts/svg_dark.js b/docs/javascripts/svg_dark.js new file mode 100644 index 0000000..a997bf0 --- /dev/null +++ b/docs/javascripts/svg_dark.js @@ -0,0 +1,52 @@ +document.addEventListener("DOMContentLoaded", function () { + // Function to fetch SVG and inject the styles + function injectSVGStyles(imgElement) { + // Retrieve the src attribute for the image + const imgSrc = imgElement.getAttribute('src'); + + // If it's an SVG file (basic check for ".svg") + if (imgSrc && imgSrc.endsWith('.svg')) { + // Fetch the SVG file + fetch(imgSrc) + .then(response => response.text()) // Get the SVG content as text + .then(svgText => { + // Parse the SVG string into an HTML element + const parser = new DOMParser(); + const svgDocument = parser.parseFromString(svgText, 'image/svg+xml'); + const svgElement = svgDocument.querySelector('svg'); + + if (svgElement) { + // Convert old to inline + imgElement.replaceWith(svgElement); + + // Create a of SVG + svgElement.insertBefore(styleElement, svgElement.firstChild); + } + }) + .catch(err => { + console.error("Error fetching SVG:", err); + }); + } + } + + // Find all tags + const imgElements = document.querySelectorAll('img'); + + // Convert all SVG tags to inline SVG with injected styles + imgElements.forEach(imgElement => { + injectSVGStyles(imgElement); + }); +}); \ No newline at end of file diff --git a/mkdocs.yml b/mkdocs.yml index 1296658..18a0b33 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -129,6 +129,7 @@ extra: extra_javascript: - "https://cdn.jsdelivr.net/npm/mathjax@3.2.2/es5/tex-mml-chtml.min.js" - "https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.9.0/katex.min.js" + - javascripts/svg_dark.js extra_css: - css/extra.css