From 8e9dcfac954c3ffdf92b7a824532871d963489ab Mon Sep 17 00:00:00 2001 From: dragonwocky Date: Mon, 18 Nov 2024 21:06:24 +1100 Subject: [PATCH] fix(outliner): correctly indent h1 > h3 > h2 heading sequences --- src/extensions/outliner/client.mjs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/extensions/outliner/client.mjs b/src/extensions/outliner/client.mjs index 33c4f84..7be9953 100644 --- a/src/extensions/outliner/client.mjs +++ b/src/extensions/outliner/client.mjs @@ -84,10 +84,17 @@ export default async (api, db) => { updateHeadings = debounce(() => { $toc.innerHTML = ""; if (!$page) return; + let indent = 0, + prev_level = 0; const $frag = document.createDocumentFragment(); for (const $heading of getHeadings()) { + const level = getHeadingLevel($heading); + if (level === 1) indent = 1; + else if (level > prev_level) indent = Math.min(indent + 1, level); + else if (level < prev_level) indent = Math.max(indent - 1, level); + prev_level = level; $heading._$outline = html`<${Heading} - indent=${getHeadingLevel($heading)} + ...${{ indent }} onclick=${() => { if (!$scroller) return; const top = getBlockOffset($heading) - 24;