#814 standardise outliner indentation

merge pr from @achiyae
This commit is contained in:
Tom 2024-01-30 22:28:24 +11:00 committed by GitHub
commit 4e1a28df3d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -43,18 +43,12 @@ export default async function ({ web, components }, db) {
$headingList.style.display = ''; $headingList.style.display = '';
const $headerBlocks = $page.querySelectorAll('[class^="notion-"][class*="header-block"]'), const $headerBlocks = $page.querySelectorAll('[class^="notion-"][class*="header-block"]'),
$fragment = web.html`<div></div>`; $fragment = web.html`<div></div>`;
let depth = 0, let indent = 0;
indent = 0;
for (const $header of $headerBlocks) { for (const $header of $headerBlocks) {
const id = $header.dataset.blockId.replace(/-/g, ''), const id = $header.dataset.blockId.replace(/-/g, ''),
placeholder = $header.querySelector('[placeholder]').getAttribute('placeholder'), placeholder = $header.querySelector('[placeholder]').getAttribute('placeholder'),
headerDepth = +[...placeholder].reverse()[0]; headerDepth = +[...placeholder].reverse()[0];
if (depth && depth < headerDepth) { indent = (headerDepth-1) * 18;
indent += 18;
} else if (depth > headerDepth) {
indent = Math.max(indent - 18, 0);
}
depth = headerDepth;
const $outlineHeader = web.render( const $outlineHeader = web.render(
web.html`<a href="#${id}" class="outliner--header" web.html`<a href="#${id}" class="outliner--header"
placeholder="${web.escape(placeholder)}" placeholder="${web.escape(placeholder)}"