adding chain permalinks

This commit is contained in:
Juicysteak117
2025-10-11 12:44:15 -07:00
parent b37ca3df67
commit 6a7fdeaf55
7 changed files with 1646 additions and 1550 deletions

2
.gitignore vendored
View File

@@ -8,3 +8,5 @@
*.toc *.toc
LaTeXML.css LaTeXML.css
ltx-article.css ltx-article.css
test.py
test.html

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -20,8 +20,9 @@
body { body {
font-family: 'crm'; font-family: 'crm';
padding: 0 0px 0 0; margin: 0; padding: 0 0px 0 0;
font-size: 17px; margin: 0;
font-size: 17px;
} }
.ltx_TOC a:link, .ltx_TOC a:visited, .ltx_p a:link, .ltx_p a:visited { color: blue !important; } .ltx_TOC a:link, .ltx_TOC a:visited, .ltx_p a:link, .ltx_p a:visited { color: blue !important; }
@@ -71,6 +72,12 @@ font-size: 17px;
min-width: 0; min-width: 0;
} }
.chain {
text-decoration:none;
font-size: 80%;
margin-left: 0.5em;
}
/*side bar*/ /*side bar*/
ol[class="ltx_toclist ltx_toclist_section"]{ ol[class="ltx_toclist ltx_toclist_section"]{
max-height: 0; max-height: 0;
@@ -112,6 +119,50 @@ font-family: serif;
content: "" !important; content: "" !important;
} }
/* i'm just copying this shit from w3schools ngl */
#snackbar {
visibility: hidden;
min-width: 250px;
margin-left: -125px;
background-color: #333;
color: #fff;
text-align: center;
border-radius: 2px;
padding: 16px;
position: fixed;
z-index: 1;
left: 50%;
bottom: 30px;
font-size: 17px;
}
#snackbar.show {
visibility: visible;
-webkit-animation: fadein 0.5s, fadeout 0.5s 2.5s;
animation: fadein 0.5s, fadeout 0.5s 2.5s;
}
@-webkit-keyframes fadein {
from {bottom: 0; opacity: 0;}
to {bottom: 30px; opacity: 1;}
}
@keyframes fadein {
from {bottom: 0; opacity: 0;}
to {bottom: 30px; opacity: 1;}
}
@-webkit-keyframes fadeout {
from {bottom: 30px; opacity: 1;}
to {bottom: 0; opacity: 0;}
}
@keyframes fadeout {
from {bottom: 30px; opacity: 1;}
to {bottom: 0; opacity: 0;}
}
@media screen AND (max-width:1000px) { @media screen AND (max-width:1000px) {
.ltx_TOC { width: 0; visibility: hidden; top: 5vh; } .ltx_TOC { width: 0; visibility: hidden; top: 5vh; }
#menu { display: block; width: 100%; padding: 0; border-radius: 0; border-top: none; border-left: none; border-right: none;} #menu { display: block; width: 100%; padding: 0; border-radius: 0; border-top: none; border-left: none; border-right: none;}

View File

@@ -17,3 +17,17 @@ for (i = 0; i < coll.length; i++) {
coll[i].classList.add("del"); coll[i].classList.add("del");
} }
} }
function copyURI(evt) {
evt.preventDefault();
/* ensures url is without hash, then add on correct hash */
navigator.clipboard.writeText(window.location.href.replace(window.location.hash,'') + evt.target.getAttribute('href')).then(() => {
/* clipboard successfully set */
}, () => {
/* clipboard write failed */
});
/* silly little toast */
var x = document.getElementById("snackbar");
x.className = "show";
setTimeout(function(){ x.className = x.className.replace("show", ""); }, 2000);
}

View File

@@ -1329,4 +1329,6 @@ Shout out to my IB Chemistry HL teacher many years ago who quite reasonably doub
\noindent 2025-10-10: Added Gretchen's Version (.txt) and fixed formatting. 19.5k words. \noindent 2025-10-10: Added Gretchen's Version (.txt) and fixed formatting. 19.5k words.
\noindent 2025-10-11: Added
\end{document} \end{document}

33
soup.py
View File

@@ -1,5 +1,4 @@
#!/usr/bin/env python3 #source: @jonesetc.com ty king you're an icon
#source: @jonesetc.com ty king
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
# Parse the file into soup # Parse the file into soup
@@ -19,10 +18,17 @@ header.append(menu)
# Extract nav # Extract nav
toc = soup.body.find('div', class_='ltx_page_main').nav.extract() toc = soup.body.find('div', class_='ltx_page_main').nav.extract()
# Prepend header and toc into body # adding a toast
soup.body.insert(0, header, toc) toast = soup.new_tag (
"div",
id="snackbar",
string="Link Copied!"
)
# Add header info # Prepend header and toc into body
soup.body.insert(0, toast, header, toc)
# Add header info tags
head_meta = soup.new_tag( head_meta = soup.new_tag(
'meta', 'meta',
@@ -91,6 +97,23 @@ head_meta = soup.new_tag(
soup.head.append(head_meta) soup.head.append(head_meta)
soup.head.append("\n") soup.head.append("\n")
# find all the section and question headers then add a click to copy
for element in soup.find_all(["h2", "h3"]):
#find the id of its section
hash = element.parent['id']
new_chain = soup.new_tag(
'a',
**{'class':'ltx_ref chain'},
href="#" + hash,
title="Click to copy a link here",
onclick="copyURI(event)",
string='🔗',
)
element.append(new_chain)
print("soup") print("soup")
# Write the updated soup back out to the file # Write the updated soup back out to the file