updates for new svg view/download links

This commit is contained in:
James Brumond 2023-05-28 15:56:56 -07:00
parent e3bf8dc139
commit 5d36def32c
Signed by: james
GPG Key ID: E8F2FC44BAA3357A
9 changed files with 103 additions and 11 deletions

View File

@ -116,9 +116,16 @@
const outline = [ ]; const outline = [ ];
for (const heading of headings) { 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(` outline.push(`
<li data-depth="${heading.tagName.toLowerCase()}"> <li data-depth="${heading.tagName.toLowerCase()}">
<a href="#${heading.id}">${heading.innerText}</a> <a href="#${heading.id}">${content.innerHTML}</a>
</li> </li>
`); `);
} }

View File

@ -92,9 +92,16 @@
const outline = [ ]; const outline = [ ];
for (const heading of headings) { 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(` outline.push(`
<li data-depth="${heading.tagName.toLowerCase()}"> <li data-depth="${heading.tagName.toLowerCase()}">
<a href="#${heading.id}">${heading.innerText}</a> <a href="#${heading.id}">${content.innerHTML}</a>
</li> </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-start: 0;
margin-block-end: 0.15rem; 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); font-family: var(--font-body);
text-align: center; text-align: center;
font-size: 0.85rem; font-size: 0.85rem;
margin-block-start: 1rem;
color: var(--theme-text-light); color: var(--theme-text-light);
max-width: 60vw; max-width: 60vw;
margin-inline: auto; margin-inline: auto;

View File

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

14
package-lock.json generated
View File

@ -10,7 +10,7 @@
"dependencies": { "dependencies": {
"@doc-utils/color-themes": "^0.1.14", "@doc-utils/color-themes": "^0.1.14",
"@doc-utils/jsonschema2markdown": "^0.1.1", "@doc-utils/jsonschema2markdown": "^0.1.1",
"@doc-utils/markdown2html": "^0.3.1", "@doc-utils/markdown2html": "^0.3.2",
"glob": "^10.2.3", "glob": "^10.2.3",
"ical": "^0.8.0", "ical": "^0.8.0",
"ical-generator": "^4.1.0", "ical-generator": "^4.1.0",
@ -51,9 +51,9 @@
} }
}, },
"node_modules/@doc-utils/markdown2html": { "node_modules/@doc-utils/markdown2html": {
"version": "0.3.1", "version": "0.3.2",
"resolved": "https://gitea.jbrumond.me/api/packages/doc-utils/npm/%40doc-utils%2Fmarkdown2html/-/0.3.1/markdown2html-0.3.1.tgz", "resolved": "https://gitea.jbrumond.me/api/packages/doc-utils/npm/%40doc-utils%2Fmarkdown2html/-/0.3.2/markdown2html-0.3.2.tgz",
"integrity": "sha512-+1i1dOrQYCPMMi7L84frt+JdYGX7uBvSEhY3zSIkGVgLVeyWhCnDVQ3celwaRCOpnnuK6qh9nWCD6WwmjULnqw==", "integrity": "sha512-aRPlxA25gowmWmzPID4xyLCTVs7VgQJvlmYn3amnFAsUC55JzFXZQ9MR40AKeQYv9VSXIpxjUr7A86hgOzRFFw==",
"dependencies": { "dependencies": {
"bytefield-svg": "^1.6.1", "bytefield-svg": "^1.6.1",
"dompurify": "^2.3.6", "dompurify": "^2.3.6",
@ -2692,9 +2692,9 @@
} }
}, },
"@doc-utils/markdown2html": { "@doc-utils/markdown2html": {
"version": "0.3.1", "version": "0.3.2",
"resolved": "https://gitea.jbrumond.me/api/packages/doc-utils/npm/%40doc-utils%2Fmarkdown2html/-/0.3.1/markdown2html-0.3.1.tgz", "resolved": "https://gitea.jbrumond.me/api/packages/doc-utils/npm/%40doc-utils%2Fmarkdown2html/-/0.3.2/markdown2html-0.3.2.tgz",
"integrity": "sha512-+1i1dOrQYCPMMi7L84frt+JdYGX7uBvSEhY3zSIkGVgLVeyWhCnDVQ3celwaRCOpnnuK6qh9nWCD6WwmjULnqw==", "integrity": "sha512-aRPlxA25gowmWmzPID4xyLCTVs7VgQJvlmYn3amnFAsUC55JzFXZQ9MR40AKeQYv9VSXIpxjUr7A86hgOzRFFw==",
"requires": { "requires": {
"bytefield-svg": "^1.6.1", "bytefield-svg": "^1.6.1",
"dompurify": "^2.3.6", "dompurify": "^2.3.6",

View File

@ -24,7 +24,7 @@
"dependencies": { "dependencies": {
"@doc-utils/color-themes": "^0.1.14", "@doc-utils/color-themes": "^0.1.14",
"@doc-utils/jsonschema2markdown": "^0.1.1", "@doc-utils/jsonschema2markdown": "^0.1.1",
"@doc-utils/markdown2html": "^0.3.1", "@doc-utils/markdown2html": "^0.3.2",
"glob": "^10.2.3", "glob": "^10.2.3",
"ical": "^0.8.0", "ical": "^0.8.0",
"ical-generator": "^4.1.0", "ical-generator": "^4.1.0",

View File

@ -104,6 +104,7 @@ export async function load_extras() {
const extras: Record<string, string> = Object.create(null); const extras: Record<string, string> = Object.create(null);
const extras_dir = resolve_path(__dirname, '../extras'); const extras_dir = resolve_path(__dirname, '../extras');
const extras_files = [ const extras_files = [
'svg-links.js',
'components/color-scheme-toggle-button.js', 'components/color-scheme-toggle-button.js',
'components/outline-button.js', 'components/outline-button.js',
'components/outline-inline.js', 'components/outline-inline.js',