Skip to content

Commit

Permalink
fix(renderer): Fallthrough headings like Kit (#152)
Browse files Browse the repository at this point in the history
* Push

* Add changeset

* undo my bullshit
  • Loading branch information
PuruVJ authored Jun 22, 2023
1 parent 7e1046e commit d997ad9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/forty-seals-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/site-kit': patch
---

Fallthrough headings like Kit
10 changes: 5 additions & 5 deletions packages/site-kit/src/lib/docs/DocsOnThisPage.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@
await document.fonts.ready;
update();
highlight();
const hash = $page.url.hash.replace(/^#/, '');
const el = document.getElementById(hash);
el?.scrollIntoView({ behavior: 'auto', block: 'start' });
});
afterNavigate(() => {
Expand All @@ -60,6 +55,11 @@
return heading.getBoundingClientRect().top - parseFloat(style.scrollMarginTop) - top;
});
height = window.innerHeight;
const hash = $page.url.hash.replace(/^#/, '');
const el = document.getElementById(hash);
el?.scrollIntoView({ behavior: 'auto', block: 'start' });
}
function highlight() {
Expand Down
13 changes: 4 additions & 9 deletions packages/site-kit/src/lib/markdown/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ export async function render_content_markdown(
* }} opts
*/
function parse({ body, code, codespan, type_links }) {
/** @type {string[]} */
const headings = [];

// this is a bit hacky, but it allows us to prevent type declarations
Expand All @@ -196,14 +197,10 @@ function parse({ body, code, codespan, type_links }) {

const normalized = normalizeSlugify(raw);

headings[level] = normalized;
headings[level - 1] = normalized;
headings.length = level;

const type_heading_match = /^\[TYPE\]:\s+(.+)/.exec(raw);

const slug = normalizeSlugify(
type_heading_match ? type_links?.get(type_heading_match[1])?.slug ?? '' : raw
);
const slug = headings.filter(Boolean).join('-');

return `<h${level} id="${slug}">${html
.replace(/<\/?code>/g, '')
Expand Down Expand Up @@ -557,9 +554,7 @@ export function replace_export_type_placeholders(content, modules) {
const markdown =
`<div class="ts-block">${fence(t.snippet, 'dts')}` + children + `</div>`;
return `### [TYPE]: ${t.name}\n\n${deprecated}\n\n${
t.comment ?? ''
}\n\n${markdown}\n\n`;
return `### ${t.name}\n\n${deprecated}\n\n${t.comment ?? ''}\n\n${markdown}\n\n`;
})
.join('')}`;
})
Expand Down

0 comments on commit d997ad9

Please sign in to comment.