Comments (6)
Oh yeah, that's an easy web component, I think.
from laml-wc.
The hardest part is probably around IDs / hashes. Cool URLs don't change and all that.
Do we expect authors to specify them? If we generate them, they probably shouldn't be random. Basing them on the heading content is usually a good plan but could lead to duplicates (e.g., each chapter having a section "Exercises").
from laml-wc.
Very quick experiment:
class toc extends HTMLElement {
constructor() {
super()
}
connectedCallback() {
document.querySelectorAll('h-').forEach(node => { if (!node.id) node.id = self.crypto.randomUUID() })
let headings = document.querySelectorAll('h-[aria-level="2"]');
this.insertAdjacentHTML('beforeend',
`<nav aria-label="table of contents">
<ul>
${[...headings].map(node =>
`<li>
<a href="#${node.id}">${node.innerHTML}</a>
<ul>
${[...node.parentNode.querySelectorAll('h-[aria-level="3"]')].map(nested =>
`<li><a href="#${nested.id}">${nested.innerHTML}</li>`).join('')}
</ul>
</li>`).join('')}
</ul>
</nav>`)
}
}
customElements.define('toc-', toc);
from laml-wc.
Laughed about the cool URI's...
I guess the author could supply, otherwise it gets generated?
from laml-wc.
I guess the author could supply, otherwise it gets generated?
I suspect authors don't want to do that for each chapter & section (and whatever else they want in a customized TOC).
It's probably safe to generate them from heading content initially and consider duplicate IDs an author error. If we feel like it, we can later add a simple counter suffix when detecting duplicate IDs.
from laml-wc.
Ugh - sorry. Shouldn't reply so early. I copied but didn't register "or gets generated".
So yes, I agree vehemently. 🤣
from laml-wc.
Related Issues (19)
- reconsider name- HOT 4
- go through laml backlog HOT 1
- make ref- do something interesting HOT 6
- work out a JS solution in lieu of CSS counters HOT 5
- proofs should not be enumerated
- think about proof- HOT 1
- SSR HOT 3
- move script to end of body
- naming HOT 9
- dual design HOT 15
- revise proof
- next steps for ref- HOT 7
- optional qed placement
- better SSR
- add landing page and SSR output
- look into penrose (for cichon's diagram)
- sprinkle some aria
- add pagedjs demo HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laml-wc.