updates for new svg view/download links

This commit is contained in:
2023-05-28 15:56:56 -07:00
parent e3bf8dc139
commit 5d36def32c
9 changed files with 103 additions and 11 deletions

View File

@@ -116,9 +116,16 @@
const outline = [ ];
for (const heading of headings) {
const content = heading.cloneNode(true);
const anchor = content.querySelector('a.heading-anchor');
if (anchor) {
anchor.parentNode.removeChild(anchor);
}
outline.push(`
<li data-depth="${heading.tagName.toLowerCase()}">
<a href="#${heading.id}">${heading.innerText}</a>
<a href="#${heading.id}">${content.innerHTML}</a>
</li>
`);
}

View File

@@ -92,9 +92,16 @@
const outline = [ ];
for (const heading of headings) {
const content = heading.cloneNode(true);
const anchor = content.querySelector('a.heading-anchor');
if (anchor) {
anchor.parentNode.removeChild(anchor);
}
outline.push(`
<li data-depth="${heading.tagName.toLowerCase()}">
<a href="#${heading.id}">${heading.innerText}</a>
<a href="#${heading.id}">${content.innerHTML}</a>
</li>
`);
}

58
extras/svg-links.js Normal file
View File

@@ -0,0 +1,58 @@
(() => {
if (document.readyState === 'complete') {
add_svg_links();
}
else {
window.addEventListener('DOMContentLoaded', add_svg_links);
}
function add_svg_links() {
const svg_elems = document.querySelectorAll('figure > svg');
for (const svg_elem of svg_elems) {
const figure_elem = svg_elem.parentElement;
const anchor_elem = document.createElement('a');
const lang = figure_elem.getAttribute('data-lang') || '';
let svg_html;
if ('svg_link_css' in window) {
const svg_clone = svg_elem.cloneNode(true);
const style_elem = document.createElement('style');
svg_clone.insertBefore(style_elem, svg_clone.firstChild);
const css
= (window.svg_link_css['*'] || '')
+ (lang ? window.svg_link_css[lang] || '' : '');
style_elem.setAttribute('type', 'text/css');
style_elem.appendChild(document.createTextNode(css));
svg_html = svg_clone.outerHTML;
}
else {
svg_html = svg_elem.outerHTML;
}
const box = document.createElement('div');
const svg_xml = '<?xml version="1.0" standalone="no" ?>\r\n'
+ svg_html.replace(/(&(?!(amp|gt|lt|quot|apos))[^;]+;)/g, ($0, $1) => {
box.innerHTML = $0;
return box.textContent;
});
const svg_blob = new Blob([ svg_xml ], { type: 'image/svg+xml; charset=utf-8' });
const svg_object_url = URL.createObjectURL(svg_blob);
anchor_elem.href = svg_object_url;
anchor_elem.className = 'view-svg';
anchor_elem.textContent = 'View / Download Graphic';
figure_elem.insertBefore(anchor_elem, svg_elem);
}
}
})();

View File

@@ -66,3 +66,13 @@ dd + dt {
margin-block-start: 0;
margin-block-end: 0.15rem;
}
/* ===== Figure Captions ===== */
figcaption {
margin-block-start: 1.5rem;
}

View File

@@ -326,7 +326,6 @@ figcaption {
font-family: var(--font-body);
text-align: center;
font-size: 0.85rem;
margin-block-start: 1rem;
color: var(--theme-text-light);
max-width: 60vw;
margin-inline: auto;

View File

@@ -65,3 +65,13 @@ dd + dt {
margin-block-start: 0;
margin-block-end: 0.25rem;
}
/* ===== Figure Captions ===== */
figcaption {
margin-block-start: 2rem;
}