diff --git a/index.html b/index.html
index b3da35c..60f5b2f 100644
--- a/index.html
+++ b/index.html
@@ -3,7 +3,7 @@
-
+
@@ -257,6 +257,43 @@
// 读取并解析指定文件
const getMarkdown = async (mdPath, response = null) => {
+ // 生成目录
+ function generateOutline(doc) {
+ let outline = '';
+ let headings = Array.from(doc.querySelectorAll('h1, h2, h3, h4, h5, h6'));
+ let stack = [];
+
+ headings.forEach(heading => {
+ let level = parseInt(heading.tagName.charAt(1));
+ // let id = heading.textContent.toLowerCase().replace(/ /g, '-').replace(/[^\w-]/g, '');
+
+ // 设置 id 属性以便链接跳转
+ heading.setAttribute('id', heading.textContent);
+
+ while (stack.length > 0 && stack[stack.length - 1].level >= level) {
+ stack.pop();
+ outline += '
';
+ }
+
+ if (stack.length === 0 || stack[stack.length - 1].level < level) {
+ outline += '';
+ } else {
+ outline += '
';
+ }
+
+ outline += `${heading.textContent}`;
+ stack.push({ level: level });
+ });
+
+ while (stack.length > 0) {
+ outline += '';
+ stack.pop();
+ }
+
+ outline += '';
+ return outline;
+ }
+
if (!response) {
response = await fetch(mdPath);
if (!response.ok) {
@@ -264,9 +301,13 @@
}
}
var content = marked.parse(await response.text());
- content = `${decodeURIComponent(mdPath)}
${content}`;
+ content = `${decodeURIComponent(mdPath)}
${content}`;
const parser = new DOMParser();
const doc = parser.parseFromString(content, 'text/html');
+
+ const outline = generateOutline(doc);
+ doc.querySelector('.outline').innerHTML += outline;
+
const links = doc.querySelectorAll('a[href$=".md"]');
const pValue = await getPValue()
links.forEach(link => {
@@ -505,10 +546,15 @@
background-color: rgba(255, 255, 255, 0.1);
}
+ #c ul,
+ #c ol {
+ padding-left: 2rem;
+ }
+
#c pre {
background-color: rgba(0, 0, 0, 0.05);
padding: .4rem;
- border-radius: .5rem;
+ border-radius: .1rem;
overflow-y: scroll;
}
@@ -527,9 +573,25 @@
background-color: rgba(0, 0, 0, 0.05);
font-size: small;
padding: .4rem;
+ margin: .5rem 2rem;
border-left: 5px solid rgba(0, 0, 0, 0.1);
}
+ #c details {
+ border: 1px solid rgba(0, 0, 0, 0.1);
+ border-radius: .1rem;
+ }
+
+ #c summary {
+ background-color: rgba(0, 0, 0, 0.05);
+ padding: .4rem;
+ font-weight: bold;
+ }
+
+ #c details a {
+ margin-left: -2rem;
+ }
+
#c table {
border-spacing: 0;
border-radius: .1rem;