Merge branch '1.4.0' of https://github.com/shuffle/shuffle into 1.4.0

This commit is contained in:
Frikky
2024-05-17 00:59:32 +02:00
+29 -24
View File
@@ -335,8 +335,12 @@ const Docs = (defaultprops) => {
const scrollToHash = () => { const scrollToHash = () => {
const hash = window.location.hash.replace("#", "") var hash = window.location.hash.replace("#", "").replaceAll("_", "-");
if (hash.includes('?')) {
hash = hash.split('?')[0]
}
if (hash) { if (hash) {
console.log("HASH: ", hash)
const element = document.getElementById(hash) const element = document.getElementById(hash)
if (element) { if (element) {
element.scrollIntoView({ element.scrollIntoView({
@@ -346,34 +350,33 @@ const Docs = (defaultprops) => {
} }
} }
const extractHeadings = content => {
// extract toc from all headings and subheadings
const extractHeadings = (content) => {
const headings = []; const headings = [];
const lines = content.split('\n');
let inCodeBlock = false;
const headingRegex = /^(#{2,3})\s+(.+)$/gm; for (const line of lines) {
let match; if (line.startsWith('```')) {
inCodeBlock = !inCodeBlock;
}
while ((match = headingRegex.exec(content)) !== null) { if (!inCodeBlock) {
const level = match[1].length; const headingMatch = line.match(/^(#{2,3})\s+(.+)$/);
const title = match[2].trim(); if (headingMatch) {
const level = headingMatch[1].length;
const title = headingMatch[2].trim();
const id = title.toLowerCase().replace(/\s+/g, '-');
if (level === 2) { if (level === 2) {
headings.push({ headings.push({ id, title, items: [] });
id: title.toLowerCase().replace(/\s+/g, '-'), } else if (level === 3 && headings.length) {
title: title, headings[headings.length - 1].items.push({ id, title });
items: [] }
}); }
} else if (level === 3 && headings.length > 0) {
const lastHeading = headings[headings.length - 1];
lastHeading.items.push({
id: title.toLowerCase().replace(/\s+/g, '-'),
title: title
});
} }
} }
return headings return headings;
} };
// extract TOC from actual markdown // extract TOC from actual markdown
@@ -590,7 +593,9 @@ const Docs = (defaultprops) => {
alignSelf: "flex-start", alignSelf: "flex-start",
position: "sticky", position: "sticky",
top: 80, top: 80,
overflow: "auto", overflowY: "auto",
minHeight: "93vh",
maxHeight: "93vh",
marginTop: 70, marginTop: 70,
} }