@sullux/markdown-docs 1.0.6 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/site.js +1 -1
- package/lib/summary.js +31 -14
- package/package.json +3 -3
package/lib/site.js
CHANGED
|
@@ -53,7 +53,7 @@ const generateSite = (options = {}) => {
|
|
|
53
53
|
const rawMd = fs.readFileSync(file.fullPath, 'utf8')
|
|
54
54
|
const ast = parse(rawMd)
|
|
55
55
|
const toc = extractToc(ast)
|
|
56
|
-
const rawHtml = markdownToHtml(
|
|
56
|
+
const rawHtml = markdownToHtml(ast)
|
|
57
57
|
const contentHtml = rewriteMarkdownLinks(rawHtml)
|
|
58
58
|
const relHtmlPath = normalizeHtmlPath(file.relPath)
|
|
59
59
|
const outHtmlPath = path.join(config.output, relHtmlPath)
|
package/lib/summary.js
CHANGED
|
@@ -15,26 +15,43 @@ const parseSummaryMd = (content) => {
|
|
|
15
15
|
const nav = []
|
|
16
16
|
let currentSection = null
|
|
17
17
|
|
|
18
|
+
const extractItems = (listNode) => {
|
|
19
|
+
const items = []
|
|
20
|
+
const listChildren = listNode.children || listNode.items || []
|
|
21
|
+
for (const item of listChildren) {
|
|
22
|
+
let linkInfo = null
|
|
23
|
+
const subLists = []
|
|
24
|
+
const itemBlocks = item.children || (Array.isArray(item) ? [{ type: 'paragraph', children: item }] : [])
|
|
25
|
+
|
|
26
|
+
for (const child of itemBlocks) {
|
|
27
|
+
if (child.type === 'paragraph') {
|
|
28
|
+
for (const node of child.children || []) {
|
|
29
|
+
if (node.type === 'link') {
|
|
30
|
+
const title = node.children ? node.children.map((c) => c.value || '').join('') : ''
|
|
31
|
+
linkInfo = { title, href: normalizeHref(node.url) }
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
} else if (child.type === 'bulletList' || child.type === 'orderedList') {
|
|
35
|
+
subLists.push(...extractItems(child))
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (linkInfo) {
|
|
40
|
+
items.push({ ...linkInfo, children: subLists })
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return items
|
|
44
|
+
}
|
|
45
|
+
|
|
18
46
|
for (const block of ast.blocks) {
|
|
19
47
|
if (block.type === 'header' && block.level > 1) {
|
|
20
48
|
const sectionTitle = block.children ? block.children.map((c) => c.value || '').join('') : ''
|
|
21
49
|
currentSection = { type: 'section', title: sectionTitle, items: [] }
|
|
22
50
|
nav.push(currentSection)
|
|
23
51
|
} else if (block.type === 'bulletList' || block.type === 'orderedList') {
|
|
24
|
-
const listItems =
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
if (node.type === 'link') {
|
|
28
|
-
const title = node.children ? node.children.map((c) => c.value || '').join('') : ''
|
|
29
|
-
listItems.push({ title, href: normalizeHref(node.url), children: [] })
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
if (currentSection) {
|
|
34
|
-
currentSection.items.push(...listItems)
|
|
35
|
-
} else {
|
|
36
|
-
nav.push(...listItems)
|
|
37
|
-
}
|
|
52
|
+
const listItems = extractItems(block)
|
|
53
|
+
if (currentSection) currentSection.items.push(...listItems)
|
|
54
|
+
else nav.push(...listItems)
|
|
38
55
|
}
|
|
39
56
|
}
|
|
40
57
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sullux/markdown-docs",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "A zero-dependency, local-first static documentation site generator compiling GitBook-style Markdown docs.",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"bin": {
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"registry": "https://registry.npmjs.org/"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@sullux/markdown-compiler": "^
|
|
37
|
-
"@sullux/markdown-html": "^
|
|
36
|
+
"@sullux/markdown-compiler": "^2.0.0",
|
|
37
|
+
"@sullux/markdown-html": "^2.0.0"
|
|
38
38
|
}
|
|
39
39
|
}
|