Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions src/decorate.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
* governing permissions and limitations under the License.
*/

import { toCamelCase, toClassName } from './utils.js';
import { readBlockConfig } from './block-utils.js';

/**
* Add <img> for icon, prefixed with codeBasePath and optional prefix.
* @param {Element} [span] span element with icon classes
Expand Down Expand Up @@ -65,20 +62,5 @@ export function decorateSections(main) {
section.classList.add('section');
section.dataset.sectionStatus = 'initialized';
section.style.display = 'none';

// Process section metadata
const sectionMeta = section.querySelector('div.section-metadata');
if (sectionMeta) {
const meta = readBlockConfig(sectionMeta);
Object.keys(meta).forEach((key) => {
if (key === 'style') {
const styles = meta.style.split(',').filter((style) => style).map((style) => toClassName(style.trim()));
styles.forEach((style) => section.classList.add(style));
} else {
section.dataset[toCamelCase(key)] = meta[key];
}
});
sectionMeta.parentNode.remove();
}
});
}
22 changes: 6 additions & 16 deletions test/decorate/decorateSections.test.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ <h2 id="this-is-another-headline-here-for-more-content">This is another headline
</div>
</div>
</div>
<div>
<div class="highlight afterempty" data-anchor="highlights">
<h2 id="boilerplate-highlights">Boilerplate Highlights?</h2>
<p>Find some of our favorite staff picks below:</p>
<div class="cards">
Expand Down Expand Up @@ -70,16 +70,6 @@ <h2 id="boilerplate-highlights">Boilerplate Highlights?</h2>
</div>
</div>
</div>
<div class="section-metadata">
<div>
<div>Style</div>
<div>highlight,,afterempty</div>
</div>
<div>
<div>Anchor</div>
<div>highlights</div>
</div>
</div>
</div>
<script type="module">
/* eslint-env mocha */
Expand All @@ -90,7 +80,6 @@ <h2 id="boilerplate-highlights">Boilerplate Highlights?</h2>
runTests(() => {
it('decorates sections', () => {
const { body } = document;
const meta = body.querySelector('.section-metadata').parentElement;
decorateSections(body);
const sections = body.querySelectorAll(':scope > div');
sections.forEach((section) => {
Expand All @@ -107,10 +96,11 @@ <h2 id="boilerplate-highlights">Boilerplate Highlights?</h2>
}
});
});
// section metadata is applied
expect(meta.classList.contains('highlight')).to.be.true;
expect(meta.classList.contains('afterempty')).to.be.true;
expect(meta.dataset.anchor).to.equal('highlights');
// pre-applied section metadata is preserved
const styled = sections[1];
expect(styled.classList.contains('highlight')).to.be.true;
expect(styled.classList.contains('afterempty')).to.be.true;
expect(styled.dataset.anchor).to.equal('highlights');
});
});
</script>
Expand Down