diff --git a/_layouts/base.html b/_layouts/base.html
index 50de135..7f5a78a 100644
--- a/_layouts/base.html
+++ b/_layouts/base.html
@@ -109,7 +109,13 @@
figure.captioned-media { counter-increment: captioned-figure; }
figure img,
figure > a,
- figure > video { display: block; }
+ figure > video,
+ figure > svg.inline-svg { display: block; }
+ figure > svg.inline-svg {
+ width: 100%;
+ max-width: 100%;
+ height: auto;
+ }
figure.captioned-media figcaption {
margin-top: .55em;
padding-top: .5em;
@@ -212,6 +218,15 @@
figure.captioned-media figcaption::before { color: #fff; }
code { background: transparent; }
thead { border-color: currentColor; }
+ mjx-container[jax="SVG"] rect[data-bgcolor="true"][fill="#fff3cd"] { fill: #51431c; }
+ mjx-container[jax="SVG"] rect[data-bgcolor="true"][fill="#cfe2ff"] { fill: #203b5e; }
+ mjx-container[jax="SVG"] rect[data-bgcolor="true"][fill="#e2d9f3"] { fill: #41305a; }
+ mjx-container[jax="SVG"] rect[data-bgcolor="true"][fill="#f8d7da"] { fill: #542b35; }
+ mjx-container[jax="SVG"] rect[data-bgcolor="true"][fill="#d1e7dd"] { fill: #1d453b; }
+ mjx-container[jax="SVG"] g[data-mml-node="mpadded"] > g[fill="#1c1c1a"] {
+ fill: #f5f5f5;
+ stroke: #f5f5f5;
+ }
}
diff --git a/_plugins/inline_svg.rb b/_plugins/inline_svg.rb
new file mode 100644
index 0000000..332a1b2
--- /dev/null
+++ b/_plugins/inline_svg.rb
@@ -0,0 +1,79 @@
+require "cgi"
+
+module InlineSvg
+ LOCAL_SVG_IMAGE = /
[^>]*\bsrc=(?["'])(?[^"']+\.svg(?:[?#][^"']*)?)\k[^>]*)\/?\s*>/i
+
+ module_function
+
+ def apply(document)
+ return unless document.output
+
+ document.output = document.output.gsub(LOCAL_SVG_IMAGE) do |image|
+ source = Regexp.last_match[:src]
+ image_attributes = Regexp.last_match[:attributes]
+ path = local_svg_path(document.site, source)
+ next image unless path && File.file?(path)
+
+ inline(File.read(path), image_attributes) || image
+ end
+ end
+
+ def local_svg_path(site, source)
+ path = source.split(/[?#]/, 2).first
+ return unless path.start_with?("/")
+
+ candidate = File.expand_path(path.delete_prefix("/"), site.source)
+ return unless candidate.start_with?("#{File.expand_path(site.source)}/")
+
+ candidate
+ end
+
+ def inline(svg, image_attributes)
+ alt = image_attributes[/\balt=(['"])(.*?)\1/i, 2]
+ svg.sub(/\A\s*