Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add indentation to hidden counter text #604

Merged
merged 8 commits into from
Aug 27, 2024
Merged
Next Next commit
Add indentation to hidden counter text
  • Loading branch information
gibson042 committed Aug 26, 2024
commit 4e52a8c53da43ac27dfeed9c3c2938249e04de6d
1 change: 1 addition & 0 deletions css/elements.css
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 125,7 @@ body.oldtoc {

span[aria-hidden='true'] {
font-size: 0;
white-space: pre;
}

a {
Expand Down
7 changes: 5 additions & 2 deletions js/listNumbers.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 80,7 @@ const counterByDepth = [];
function addStepNumberText(
ol,
depth = 0,
indent = '',
special = [...ol.classList].some(c => c.startsWith('nested-')),
) {
let counter = !special && counterByDepth[depth];
Expand All @@ -103,7 104,9 @@ function addStepNumberText(
let i = (Number(ol.getAttribute('start')) || 1) - 1;
for (const li of ol.children) {
const marker = document.createElement('span');
marker.textContent = `${i < cache.length ? cache[i] : getTextForIndex(i)}. `;
const markerText = i < cache.length ? cache[i] : getTextForIndex(i);
const extraIndent = ' '.repeat(markerText.length 2);
marker.textContent = `${indent}${markerText}. `;
marker.setAttribute('aria-hidden', 'true');
const attributesContainer = li.querySelector('.attributes-tag');
if (attributesContainer == null) {
Expand All @@ -112,7 115,7 @@ function addStepNumberText(
attributesContainer.insertAdjacentElement('afterend', marker);
}
for (const sublist of li.querySelectorAll(':scope > ol')) {
addStepNumberText(sublist, depth 1, special);
addStepNumberText(sublist, depth 1, indent extraIndent, special);
}
i ;
}
Expand Down
10 changes: 8 additions & 2 deletions spec/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 367,10 @@ <h2>Example</h2>
1. Set _length_ to _length_ 1.
1. Let _weight_ be GetWeight of _node_.
1. If _length_ = 10&lt;sup>9&lt;/sup> or _weight_ &gt; 2&lt;sup>_length_ 1&lt;/sup>, then
1. Throw a *RangeError* exception.
1. NOTE: This is an out-of-bounds state.
1. If _ignoreErrors_ is not *true*, then
1. Throw a *RangeError* exception.
1. Set _hadError_ to *true*.
&lt;/emu-alg>
</code></pre>

Expand All @@ -386,7 389,10 @@ <h3>Result</h3>
1. Set _length_ to _length_ 1.
1. Let _weight_ be GetWeight of _node_.
1. If _length_ = 10<sup>9</sup> or _weight_ > 2<sup>_length_ 1</sup>, then
1. Throw a *RangeError* exception.
1. NOTE: This is an out-of-bounds state.
1. If _ignoreErrors_ is not *true*, then
1. Throw a *RangeError* exception.
1. Set _hadError_ to *true*.
</emu-alg>
</aside>

Expand Down