livemark 0.23.0 → 0.24.1
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/.agents/skills/change-review/SKILL.md +47 -0
- package/{skills/configuration → .agents/skills/livemark-configuration}/SKILL.md +2 -4
- package/build/actions/changelog/build.d.ts +21 -9
- package/build/actions/changelog/build.js +31 -23
- package/build/actions/changelog/build.unit.js +156 -2
- package/build/actions/config/load.js +1 -1
- package/build/actions/config/load.unit.js +1 -1
- package/build/actions/target/build.js +2 -5
- package/build/commands/build.js +1 -1
- package/build/commands/escape.js +1 -1
- package/build/commands/preview.js +1 -1
- package/build/commands/start.js +1 -1
- package/build/components/Abbr.js +2 -2
- package/build/components/Article.js +2 -2
- package/build/components/BlogIndex.js +2 -4
- package/build/components/Callout.js +2 -2
- package/build/components/ChangelogIndex.js +1 -1
- package/build/components/CodeBlock.js +3 -5
- package/build/components/CodeTabs.js +1 -1
- package/build/components/Columns.js +2 -4
- package/build/components/Content.js +2 -2
- package/build/components/ContentTab.js +1 -1
- package/build/components/ContentTabs.js +1 -1
- package/build/components/DefinitionList.js +1 -1
- package/build/components/FileTree.js +1 -1
- package/build/components/FootnoteRef.js +2 -2
- package/build/components/InlineToc.js +1 -1
- package/build/components/Layout.js +1 -1
- package/build/components/LinkButton.js +2 -2
- package/build/components/Mermaid.js +1 -1
- package/build/components/PackageTabs.js +2 -2
- package/build/components/PageToolbar.js +2 -2
- package/build/components/PrevNext.js +3 -7
- package/build/components/SearchDialog.js +1 -1
- package/build/components/Section.js +2 -2
- package/build/components/SectionHeader.js +2 -2
- package/build/components/Sidebar.js +2 -2
- package/build/components/SidebarArticles.js +2 -2
- package/build/components/SidebarLinks.js +2 -2
- package/build/components/TagIndex.js +2 -4
- package/build/components/Toc.js +1 -1
- package/build/content/article.js +1 -1
- package/build/content-collections.js +6 -7
- package/build/elements/accordion.js +2 -2
- package/build/elements/alert-dialog.js +5 -5
- package/build/elements/alert.js +2 -2
- package/build/elements/aspect-ratio.js +2 -2
- package/build/elements/avatar.d.ts +1 -1
- package/build/elements/avatar.js +3 -3
- package/build/elements/badge.js +2 -2
- package/build/elements/breadcrumb.js +2 -2
- package/build/elements/button-group.d.ts +1 -1
- package/build/elements/button-group.js +3 -3
- package/build/elements/button.js +2 -2
- package/build/elements/calendar.js +5 -5
- package/build/elements/card.js +2 -2
- package/build/elements/carousel.js +2 -2
- package/build/elements/chart.js +5 -15
- package/build/elements/checkbox.js +2 -2
- package/build/elements/collapsible.js +3 -3
- package/build/elements/command.js +2 -2
- package/build/elements/context-menu.js +5 -5
- package/build/elements/dialog.js +2 -2
- package/build/elements/direction.d.ts +1 -1
- package/build/elements/direction.js +2 -2
- package/build/elements/drawer.js +2 -2
- package/build/elements/dropdown-menu.js +3 -3
- package/build/elements/empty.d.ts +1 -1
- package/build/elements/empty.js +3 -3
- package/build/elements/field.js +2 -2
- package/build/elements/hover-card.js +3 -3
- package/build/elements/input-group.js +2 -2
- package/build/elements/input-otp.js +2 -2
- package/build/elements/input.js +2 -2
- package/build/elements/item.js +2 -2
- package/build/elements/kbd.js +2 -2
- package/build/elements/label.js +2 -2
- package/build/elements/menubar.js +2 -2
- package/build/elements/native-select.js +2 -2
- package/build/elements/navigation-menu.js +2 -2
- package/build/elements/pagination.js +3 -3
- package/build/elements/popover.js +2 -2
- package/build/elements/progress.d.ts +1 -1
- package/build/elements/progress.js +3 -3
- package/build/elements/radio-group.js +2 -2
- package/build/elements/resizable.js +3 -3
- package/build/elements/scroll-area.js +2 -2
- package/build/elements/select.js +2 -2
- package/build/elements/separator.js +2 -2
- package/build/elements/sheet.js +2 -2
- package/build/elements/sidebar.js +3 -4
- package/build/elements/skeleton.js +2 -2
- package/build/elements/slider.js +2 -2
- package/build/elements/spinner.js +2 -2
- package/build/elements/switch.js +2 -2
- package/build/elements/table.js +2 -2
- package/build/elements/tabs.js +2 -2
- package/build/elements/textarea.js +2 -2
- package/build/elements/toggle-group.js +2 -2
- package/build/elements/toggle.js +2 -2
- package/build/elements/tooltip.js +2 -2
- package/build/helpers/changelog-source.js +1 -1
- package/build/helpers/dynamic-icon-resolver.js +1 -1
- package/build/helpers/resolve-asset-path.unit.js +1 -1
- package/build/helpers/resolve-base.unit.js +2 -2
- package/build/helpers/resolve-includes.js +2 -2
- package/build/helpers/resolve-includes.unit.js +1 -1
- package/build/helpers/rss.js +2 -4
- package/build/helpers/rss.unit.js +1 -1
- package/build/helpers/section.js +2 -3
- package/build/helpers/section.unit.js +4 -13
- package/build/helpers/toc.unit.js +2 -4
- package/build/plugins/rehype-inline-code.js +2 -2
- package/build/plugins/rehype-task-list-a11y.js +1 -1
- package/build/plugins/remark-abbr.js +2 -4
- package/build/plugins/remark-ansi.js +2 -4
- package/build/plugins/remark-ansi.unit.js +1 -1
- package/build/plugins/remark-badge.js +2 -4
- package/build/plugins/remark-button.unit.js +1 -1
- package/build/plugins/remark-callout.js +1 -1
- package/build/plugins/remark-card.js +1 -1
- package/build/plugins/remark-code-tabs.js +4 -8
- package/build/plugins/remark-columns.js +1 -1
- package/build/plugins/remark-custom-heading-id.unit.js +1 -1
- package/build/plugins/remark-deflist.js +1 -1
- package/build/plugins/remark-details.js +2 -4
- package/build/plugins/remark-filetree.js +1 -1
- package/build/plugins/remark-filetree.unit.js +1 -1
- package/build/plugins/remark-media.js +3 -7
- package/build/plugins/remark-media.unit.js +1 -1
- package/build/plugins/remark-steps.unit.js +1 -1
- package/build/plugins/remark-tab.js +4 -2
- package/build/plugins/remark-tab.unit.js +3 -7
- package/build/plugins/remark-toc.unit.js +1 -1
- package/build/plugins/shiki-icon.js +1 -1
- package/build/plugins/shiki-line-highlight.js +1 -1
- package/build/plugins/vite-livemark.js +1 -1
- package/build/plugins/vite-robots.js +1 -1
- package/build/plugins/vite-robots.unit.js +1 -1
- package/build/routes/$.js +1 -1
- package/build/vite.config.js +3 -8
- package/package.json +17 -19
- package/source/actions/changelog/build.ts +32 -35
- package/source/actions/changelog/build.unit.ts +191 -1
- package/source/actions/config/load.ts +1 -3
- package/source/actions/config/load.unit.ts +2 -7
- package/source/actions/target/build.ts +1 -4
- package/source/commands/build.ts +1 -7
- package/source/commands/escape.ts +3 -8
- package/source/commands/preview.ts +1 -7
- package/source/commands/start.ts +1 -7
- package/source/components/Abbr.tsx +1 -5
- package/source/components/Article.tsx +1 -5
- package/source/components/BlogIndex.tsx +3 -9
- package/source/components/Callout.tsx +2 -7
- package/source/components/ChangelogIndex.tsx +1 -3
- package/source/components/CodeBlock.tsx +4 -14
- package/source/components/CodeTabs.tsx +1 -3
- package/source/components/Columns.tsx +1 -3
- package/source/components/Content.tsx +1 -5
- package/source/components/ContentTab.tsx +1 -4
- package/source/components/ContentTabs.tsx +3 -10
- package/source/components/DefinitionList.tsx +1 -4
- package/source/components/FileTree.tsx +1 -5
- package/source/components/FootnoteRef.tsx +1 -5
- package/source/components/InlineToc.tsx +1 -4
- package/source/components/Layout.tsx +3 -10
- package/source/components/LinkButton.tsx +2 -8
- package/source/components/Mermaid.tsx +1 -3
- package/source/components/PackageTabs.tsx +1 -5
- package/source/components/PageToolbar.tsx +1 -5
- package/source/components/PrevNext.tsx +2 -6
- package/source/components/SearchDialog.tsx +2 -6
- package/source/components/Section.tsx +1 -1
- package/source/components/SectionHeader.tsx +2 -8
- package/source/components/Sidebar.tsx +2 -7
- package/source/components/SidebarArticles.tsx +4 -20
- package/source/components/SidebarLinks.tsx +2 -6
- package/source/components/TagIndex.tsx +3 -9
- package/source/components/Toc.tsx +2 -7
- package/source/content/article.ts +1 -2
- package/source/content-collections.ts +6 -8
- package/source/elements/accordion.tsx +1 -1
- package/source/elements/alert-dialog.tsx +8 -30
- package/source/elements/alert.tsx +2 -5
- package/source/elements/aspect-ratio.tsx +1 -1
- package/source/elements/avatar.tsx +5 -21
- package/source/elements/badge.tsx +3 -5
- package/source/elements/breadcrumb.tsx +4 -14
- package/source/elements/button-group.tsx +2 -7
- package/source/elements/button.tsx +1 -1
- package/source/elements/calendar.tsx +7 -24
- package/source/elements/card.tsx +1 -1
- package/source/elements/carousel.tsx +4 -11
- package/source/elements/chart.tsx +9 -34
- package/source/elements/checkbox.tsx +1 -1
- package/source/elements/collapsible.tsx +2 -6
- package/source/elements/command.tsx +4 -13
- package/source/elements/context-menu.tsx +8 -25
- package/source/elements/dialog.tsx +4 -14
- package/source/elements/direction.tsx +1 -4
- package/source/elements/drawer.tsx +4 -10
- package/source/elements/dropdown-menu.tsx +5 -19
- package/source/elements/empty.tsx +3 -13
- package/source/elements/field.tsx +3 -7
- package/source/elements/hover-card.tsx +2 -4
- package/source/elements/input-group.tsx +15 -28
- package/source/elements/input-otp.tsx +1 -1
- package/source/elements/input.tsx +1 -1
- package/source/elements/item.tsx +4 -13
- package/source/elements/kbd.tsx +1 -1
- package/source/elements/label.tsx +1 -1
- package/source/elements/menubar.tsx +5 -14
- package/source/elements/native-select.tsx +4 -15
- package/source/elements/navigation-menu.tsx +2 -5
- package/source/elements/pagination.tsx +4 -14
- package/source/elements/popover.tsx +2 -5
- package/source/elements/progress.tsx +4 -16
- package/source/elements/radio-group.tsx +1 -1
- package/source/elements/resizable.tsx +4 -12
- package/source/elements/scroll-area.tsx +2 -6
- package/source/elements/select.tsx +4 -14
- package/source/elements/separator.tsx +1 -1
- package/source/elements/sheet.tsx +3 -10
- package/source/elements/sidebar.tsx +7 -25
- package/source/elements/skeleton.tsx +1 -1
- package/source/elements/slider.tsx +1 -1
- package/source/elements/spinner.tsx +1 -1
- package/source/elements/switch.tsx +1 -1
- package/source/elements/table.tsx +4 -13
- package/source/elements/tabs.tsx +1 -1
- package/source/elements/textarea.tsx +1 -1
- package/source/elements/toggle-group.tsx +2 -4
- package/source/elements/toggle.tsx +1 -1
- package/source/elements/tooltip.tsx +3 -10
- package/source/helpers/changelog-source.ts +1 -3
- package/source/helpers/dynamic-icon-resolver.tsx +1 -4
- package/source/helpers/resolve-asset-path.unit.ts +6 -12
- package/source/helpers/resolve-base.unit.ts +1 -2
- package/source/helpers/resolve-includes.ts +2 -8
- package/source/helpers/resolve-includes.unit.ts +9 -36
- package/source/helpers/rss.ts +3 -9
- package/source/helpers/rss.unit.ts +1 -3
- package/source/helpers/section.ts +1 -4
- package/source/helpers/section.unit.ts +5 -18
- package/source/helpers/toc.unit.ts +1 -3
- package/source/plugins/rehype-inline-code.ts +5 -21
- package/source/plugins/rehype-task-list-a11y.ts +1 -2
- package/source/plugins/remark-abbr.ts +1 -3
- package/source/plugins/remark-ansi.ts +2 -5
- package/source/plugins/remark-ansi.unit.ts +6 -18
- package/source/plugins/remark-badge.ts +1 -3
- package/source/plugins/remark-button.unit.ts +3 -9
- package/source/plugins/remark-callout.ts +35 -40
- package/source/plugins/remark-card.ts +25 -29
- package/source/plugins/remark-code-tabs.ts +3 -7
- package/source/plugins/remark-columns.ts +13 -17
- package/source/plugins/remark-custom-heading-id.unit.ts +2 -6
- package/source/plugins/remark-deflist.ts +1 -2
- package/source/plugins/remark-details.ts +28 -34
- package/source/plugins/remark-filetree.ts +28 -34
- package/source/plugins/remark-filetree.unit.ts +1 -4
- package/source/plugins/remark-media.ts +2 -6
- package/source/plugins/remark-media.unit.ts +2 -6
- package/source/plugins/remark-steps.unit.ts +2 -7
- package/source/plugins/remark-tab.ts +26 -30
- package/source/plugins/remark-tab.unit.ts +2 -6
- package/source/plugins/remark-toc.unit.ts +1 -3
- package/source/plugins/shiki-icon.ts +1 -4
- package/source/plugins/shiki-line-highlight.ts +4 -11
- package/source/plugins/vite-livemark.ts +3 -10
- package/source/plugins/vite-robots.ts +1 -6
- package/source/plugins/vite-robots.unit.ts +1 -3
- package/source/routes/$.tsx +1 -3
- package/source/styles/general.css +1 -5
- package/source/vite.config.ts +2 -7
- package/build/utils/style.d.ts +0 -2
- package/build/utils/style.js +0 -6
- package/source/utils/style.ts +0 -6
- /package/{skills/authoring → .agents/skills/livemark-authoring}/SKILL.md +0 -0
- /package/{skills/customization → .agents/skills/livemark-customization}/SKILL.md +0 -0
|
@@ -8,50 +8,45 @@ const calloutTypes = new Set(["note", "tip", "info", "warning", "danger"])
|
|
|
8
8
|
/** Remark plugin that converts container directives into Callout JSX elements */
|
|
9
9
|
export const remarkCallout: Plugin<[], Root> = () => {
|
|
10
10
|
return tree => {
|
|
11
|
-
visit(
|
|
12
|
-
|
|
13
|
-
"containerDirective",
|
|
14
|
-
(node: ContainerDirective, index, parent) => {
|
|
15
|
-
if (!calloutTypes.has(node.name) || index === undefined || !parent)
|
|
16
|
-
return
|
|
11
|
+
visit(tree, "containerDirective", (node: ContainerDirective, index, parent) => {
|
|
12
|
+
if (!calloutTypes.has(node.name) || index === undefined || !parent) return
|
|
17
13
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
const labelParagraph = node.children.find(
|
|
15
|
+
(child): child is Paragraph =>
|
|
16
|
+
child.type === "paragraph" && !!child.data?.directiveLabel,
|
|
17
|
+
)
|
|
22
18
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
19
|
+
const title = labelParagraph
|
|
20
|
+
? {
|
|
21
|
+
type: "mdxJsxAttribute" as const,
|
|
22
|
+
name: "title",
|
|
23
|
+
value: labelParagraph.children
|
|
24
|
+
.map(c => ("value" in c ? String(c.value) : ""))
|
|
25
|
+
.join(""),
|
|
26
|
+
}
|
|
27
|
+
: undefined
|
|
32
28
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
29
|
+
const body = node.children.filter(
|
|
30
|
+
child => !(child.type === "paragraph" && child.data?.directiveLabel),
|
|
31
|
+
)
|
|
36
32
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
33
|
+
const jsxNode = {
|
|
34
|
+
type: "mdxJsxFlowElement" as const,
|
|
35
|
+
name: "Callout",
|
|
36
|
+
attributes: [
|
|
37
|
+
{
|
|
38
|
+
type: "mdxJsxAttribute" as const,
|
|
39
|
+
name: "type",
|
|
40
|
+
value: node.name,
|
|
41
|
+
},
|
|
42
|
+
...(title ? [title] : []),
|
|
43
|
+
],
|
|
44
|
+
children: body,
|
|
45
|
+
data: { _mdxExplicitJsx: true },
|
|
46
|
+
}
|
|
51
47
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
)
|
|
48
|
+
// @ts-expect-error mdxJsxFlowElement is not in mdast types
|
|
49
|
+
parent.children.splice(index, 1, jsxNode)
|
|
50
|
+
})
|
|
56
51
|
}
|
|
57
52
|
}
|
|
@@ -6,39 +6,35 @@ import { visit, SKIP } from "unist-util-visit"
|
|
|
6
6
|
/** Remark plugin that converts :::card directives into Card/Cards JSX elements */
|
|
7
7
|
export const remarkCard: Plugin<[], Root> = () => {
|
|
8
8
|
return tree => {
|
|
9
|
-
visit(
|
|
10
|
-
|
|
11
|
-
"containerDirective",
|
|
12
|
-
(node: ContainerDirective, index, parent) => {
|
|
13
|
-
if (node.name !== "card" || index === undefined || !parent) return
|
|
9
|
+
visit(tree, "containerDirective", (node: ContainerDirective, index, parent) => {
|
|
10
|
+
if (node.name !== "card" || index === undefined || !parent) return
|
|
14
11
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
const title = node.attributes?.title ?? ""
|
|
13
|
+
const href = node.attributes?.href
|
|
14
|
+
const icon = node.attributes?.icon
|
|
18
15
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
16
|
+
const attributes = [
|
|
17
|
+
{ type: "mdxJsxAttribute" as const, name: "title", value: title },
|
|
18
|
+
...(href
|
|
19
|
+
? [{ type: "mdxJsxAttribute" as const, name: "href", value: href }]
|
|
20
|
+
: []),
|
|
21
|
+
...(icon
|
|
22
|
+
? [{ type: "mdxJsxAttribute" as const, name: "icon", value: icon }]
|
|
23
|
+
: []),
|
|
24
|
+
]
|
|
28
25
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
26
|
+
const jsxNode = {
|
|
27
|
+
type: "mdxJsxFlowElement" as const,
|
|
28
|
+
name: "Card",
|
|
29
|
+
attributes,
|
|
30
|
+
children: node.children,
|
|
31
|
+
data: { _mdxExplicitJsx: true },
|
|
32
|
+
}
|
|
36
33
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
)
|
|
34
|
+
// @ts-expect-error mdxJsxFlowElement is not in mdast types
|
|
35
|
+
parent.children[index] = jsxNode
|
|
36
|
+
return SKIP
|
|
37
|
+
})
|
|
42
38
|
|
|
43
39
|
const children = tree.children
|
|
44
40
|
let i = 0
|
|
@@ -23,9 +23,7 @@ export const remarkCodeTabs: Plugin<[], Root> = () => {
|
|
|
23
23
|
continue
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
const group: { name: string; code: Code }[] = [
|
|
27
|
-
{ name: firstMatch[1]!, code: node },
|
|
28
|
-
]
|
|
26
|
+
const group: { name: string; code: Code }[] = [{ name: firstMatch[1]!, code: node }]
|
|
29
27
|
|
|
30
28
|
let j = i + 1
|
|
31
29
|
while (j < children.length) {
|
|
@@ -47,10 +45,8 @@ export const remarkCodeTabs: Plugin<[], Root> = () => {
|
|
|
47
45
|
|
|
48
46
|
for (const item of group) {
|
|
49
47
|
item.code.meta =
|
|
50
|
-
item.code
|
|
51
|
-
|
|
52
|
-
.replace(SYNC_PATTERN, "")
|
|
53
|
-
.trim() || null
|
|
48
|
+
item.code.meta!.replace(TAB_PATTERN, "").replace(SYNC_PATTERN, "").trim() ||
|
|
49
|
+
null
|
|
54
50
|
}
|
|
55
51
|
|
|
56
52
|
const codeTabsAttrs: {
|
|
@@ -6,25 +6,21 @@ import { visit, SKIP } from "unist-util-visit"
|
|
|
6
6
|
/** Remark plugin that converts consecutive :::column directives into a Columns grid */
|
|
7
7
|
export const remarkColumns: Plugin<[], Root> = () => {
|
|
8
8
|
return tree => {
|
|
9
|
-
visit(
|
|
10
|
-
|
|
11
|
-
"containerDirective",
|
|
12
|
-
(node: ContainerDirective, index, parent) => {
|
|
13
|
-
if (node.name !== "column" || index === undefined || !parent) return
|
|
9
|
+
visit(tree, "containerDirective", (node: ContainerDirective, index, parent) => {
|
|
10
|
+
if (node.name !== "column" || index === undefined || !parent) return
|
|
14
11
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
12
|
+
const jsxNode = {
|
|
13
|
+
type: "mdxJsxFlowElement" as const,
|
|
14
|
+
name: "Column",
|
|
15
|
+
attributes: [],
|
|
16
|
+
children: node.children,
|
|
17
|
+
data: { _mdxExplicitJsx: true },
|
|
18
|
+
}
|
|
22
19
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
)
|
|
20
|
+
// @ts-expect-error mdxJsxFlowElement is not in mdast types
|
|
21
|
+
parent.children[index] = jsxNode
|
|
22
|
+
return SKIP
|
|
23
|
+
})
|
|
28
24
|
|
|
29
25
|
const children = tree.children
|
|
30
26
|
let i = 0
|
|
@@ -75,18 +75,14 @@ describe("transformHeadingAnnotations", () => {
|
|
|
75
75
|
})
|
|
76
76
|
|
|
77
77
|
it("should handle ids with hyphens and numbers", () => {
|
|
78
|
-
const tree = process(
|
|
79
|
-
makeTree(makeHeading(2, "Section 1 [#section-1-intro]")),
|
|
80
|
-
)
|
|
78
|
+
const tree = process(makeTree(makeHeading(2, "Section 1 [#section-1-intro]")))
|
|
81
79
|
const heading = findHeading(tree, 0)
|
|
82
80
|
expect(heading.data?.hProperties).toEqual({ id: "section-1-intro" })
|
|
83
81
|
expect(headingText(heading)).toBe("Section 1")
|
|
84
82
|
})
|
|
85
83
|
|
|
86
84
|
it("should preserve inline formatting before the id", () => {
|
|
87
|
-
const tree = process(
|
|
88
|
-
makeTree(makeBoldHeading("Bold", " heading [#bold-heading]")),
|
|
89
|
-
)
|
|
85
|
+
const tree = process(makeTree(makeBoldHeading("Bold", " heading [#bold-heading]")))
|
|
90
86
|
const heading = findHeading(tree, 0)
|
|
91
87
|
expect(heading.data?.hProperties).toEqual({ id: "bold-heading" })
|
|
92
88
|
expect(heading.children.some(c => c.type === "strong")).toBe(true)
|
|
@@ -9,8 +9,7 @@ export const remarkDeflist: Plugin<[], Root> = () => {
|
|
|
9
9
|
if (index === undefined || !parent) return
|
|
10
10
|
|
|
11
11
|
const children = node.children.map(child => {
|
|
12
|
-
const name =
|
|
13
|
-
child.type === "defListTerm" ? "DefinitionTerm" : "DefinitionDetail"
|
|
12
|
+
const name = child.type === "defListTerm" ? "DefinitionTerm" : "DefinitionDetail"
|
|
14
13
|
return {
|
|
15
14
|
type: "mdxJsxFlowElement" as const,
|
|
16
15
|
name,
|
|
@@ -6,44 +6,38 @@ import { visit } from "unist-util-visit"
|
|
|
6
6
|
/** Remark plugin that converts :::details directives into collapsible details/summary elements */
|
|
7
7
|
export const remarkDetails: Plugin<[], Root> = () => {
|
|
8
8
|
return tree => {
|
|
9
|
-
visit(
|
|
10
|
-
|
|
11
|
-
"containerDirective",
|
|
12
|
-
(node: ContainerDirective, index, parent) => {
|
|
13
|
-
if (node.name !== "details" || index === undefined || !parent) return
|
|
9
|
+
visit(tree, "containerDirective", (node: ContainerDirective, index, parent) => {
|
|
10
|
+
if (node.name !== "details" || index === undefined || !parent) return
|
|
14
11
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
const labelParagraph = node.children.find(
|
|
13
|
+
(child): child is Paragraph =>
|
|
14
|
+
child.type === "paragraph" && !!child.data?.directiveLabel,
|
|
15
|
+
)
|
|
19
16
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
.join("")
|
|
24
|
-
: "Details"
|
|
17
|
+
const summary = labelParagraph
|
|
18
|
+
? labelParagraph.children.map(c => ("value" in c ? String(c.value) : "")).join("")
|
|
19
|
+
: "Details"
|
|
25
20
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
21
|
+
const body = node.children.filter(
|
|
22
|
+
child => !(child.type === "paragraph" && child.data?.directiveLabel),
|
|
23
|
+
)
|
|
29
24
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
25
|
+
const jsxNode = {
|
|
26
|
+
type: "mdxJsxFlowElement" as const,
|
|
27
|
+
name: "Details",
|
|
28
|
+
attributes: [
|
|
29
|
+
{
|
|
30
|
+
type: "mdxJsxAttribute" as const,
|
|
31
|
+
name: "summary",
|
|
32
|
+
value: summary,
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
children: body,
|
|
36
|
+
data: { _mdxExplicitJsx: true },
|
|
37
|
+
}
|
|
43
38
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
)
|
|
39
|
+
// @ts-expect-error mdxJsxFlowElement is not in mdast types
|
|
40
|
+
parent.children.splice(index, 1, jsxNode)
|
|
41
|
+
})
|
|
48
42
|
}
|
|
49
43
|
}
|
|
@@ -51,39 +51,33 @@ function parseListItem(listItem: ListItem): TreeItem | undefined {
|
|
|
51
51
|
/** Remark plugin that converts :::filetree directives into FileTree JSX elements */
|
|
52
52
|
export const remarkFiletree: Plugin<[], Root> = () => {
|
|
53
53
|
return tree => {
|
|
54
|
-
visit(
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
(
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
// @ts-expect-error mdxJsxFlowElement is not in mdast types
|
|
84
|
-
parent.children[index] = jsxNode
|
|
85
|
-
return SKIP
|
|
86
|
-
},
|
|
87
|
-
)
|
|
54
|
+
visit(tree, "containerDirective", (node: ContainerDirective, index, parent) => {
|
|
55
|
+
if (node.name !== "filetree" || index === undefined || !parent) return
|
|
56
|
+
|
|
57
|
+
const lists = node.children.filter((child): child is List => child.type === "list")
|
|
58
|
+
|
|
59
|
+
const treeItems: TreeItem[] = []
|
|
60
|
+
for (const list of lists) {
|
|
61
|
+
treeItems.push(...parseList(list))
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const jsxNode = {
|
|
65
|
+
type: "mdxJsxFlowElement" as const,
|
|
66
|
+
name: "FileTree",
|
|
67
|
+
attributes: [
|
|
68
|
+
{
|
|
69
|
+
type: "mdxJsxAttribute" as const,
|
|
70
|
+
name: "tree",
|
|
71
|
+
value: JSON.stringify(treeItems),
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
children: [],
|
|
75
|
+
data: { _mdxExplicitJsx: true },
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// @ts-expect-error mdxJsxFlowElement is not in mdast types
|
|
79
|
+
parent.children[index] = jsxNode
|
|
80
|
+
return SKIP
|
|
81
|
+
})
|
|
88
82
|
}
|
|
89
83
|
}
|
|
@@ -98,10 +98,7 @@ describe("parseList", () => {
|
|
|
98
98
|
listItem(
|
|
99
99
|
paragraph(text("b/")),
|
|
100
100
|
list(
|
|
101
|
-
listItem(
|
|
102
|
-
paragraph(text("c/")),
|
|
103
|
-
list(listItem(paragraph(text("deep.ts")))),
|
|
104
|
-
),
|
|
101
|
+
listItem(paragraph(text("c/")), list(listItem(paragraph(text("deep.ts"))))),
|
|
105
102
|
),
|
|
106
103
|
),
|
|
107
104
|
),
|
|
@@ -23,9 +23,7 @@ export function transformMediaDirectives(tree: Root) {
|
|
|
23
23
|
const jsxNode = {
|
|
24
24
|
type: "mdxJsxFlowElement" as const,
|
|
25
25
|
name: "YouTube",
|
|
26
|
-
attributes: [
|
|
27
|
-
{ type: "mdxJsxAttribute" as const, name: "id", value: id },
|
|
28
|
-
],
|
|
26
|
+
attributes: [{ type: "mdxJsxAttribute" as const, name: "id", value: id }],
|
|
29
27
|
children: [],
|
|
30
28
|
data: { _mdxExplicitJsx: true },
|
|
31
29
|
}
|
|
@@ -41,9 +39,7 @@ export function transformMediaDirectives(tree: Root) {
|
|
|
41
39
|
const jsxNode = {
|
|
42
40
|
type: "mdxJsxFlowElement" as const,
|
|
43
41
|
name: "SoundCloud",
|
|
44
|
-
attributes: [
|
|
45
|
-
{ type: "mdxJsxAttribute" as const, name: "url", value: url },
|
|
46
|
-
],
|
|
42
|
+
attributes: [{ type: "mdxJsxAttribute" as const, name: "url", value: url }],
|
|
47
43
|
children: [],
|
|
48
44
|
data: { _mdxExplicitJsx: true },
|
|
49
45
|
}
|
|
@@ -57,17 +57,13 @@ describe("transformMediaDirectives", () => {
|
|
|
57
57
|
})
|
|
58
58
|
|
|
59
59
|
it("should skip audio directive without url", () => {
|
|
60
|
-
const tree = process(
|
|
61
|
-
makeTree(makeLeafDirective("audio", { type: "soundcloud" })),
|
|
62
|
-
)
|
|
60
|
+
const tree = process(makeTree(makeLeafDirective("audio", { type: "soundcloud" })))
|
|
63
61
|
const node = tree.children[0]
|
|
64
62
|
expect(node).toMatchObject({ type: "leafDirective", name: "audio" })
|
|
65
63
|
})
|
|
66
64
|
|
|
67
65
|
it("should ignore unrelated leaf directives", () => {
|
|
68
|
-
const tree = process(
|
|
69
|
-
makeTree(makeLeafDirective("include", { file: "test.md" })),
|
|
70
|
-
)
|
|
66
|
+
const tree = process(makeTree(makeLeafDirective("include", { file: "test.md" })))
|
|
71
67
|
const node = tree.children[0]
|
|
72
68
|
expect(node).toMatchObject({ type: "leafDirective", name: "include" })
|
|
73
69
|
})
|
|
@@ -30,9 +30,7 @@ describe("transformStepHeadings", () => {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
it("should strip [step] and set data-step attribute", () => {
|
|
33
|
-
const tree = process(
|
|
34
|
-
makeTree(makeHeading(3, "Install Dependencies [step]")),
|
|
35
|
-
)
|
|
33
|
+
const tree = process(makeTree(makeHeading(3, "Install Dependencies [step]")))
|
|
36
34
|
const heading = findHeading(tree, 0)
|
|
37
35
|
expect(heading.data?.hProperties).toEqual({ "data-step": 1 })
|
|
38
36
|
expect(headingText(heading)).toBe("Install Dependencies")
|
|
@@ -75,10 +73,7 @@ describe("transformStepHeadings", () => {
|
|
|
75
73
|
|
|
76
74
|
it("should handle different heading depths", () => {
|
|
77
75
|
const tree = process(
|
|
78
|
-
makeTree(
|
|
79
|
-
makeHeading(2, "Big Step [step]"),
|
|
80
|
-
makeHeading(4, "Small Step [step]"),
|
|
81
|
-
),
|
|
76
|
+
makeTree(makeHeading(2, "Big Step [step]"), makeHeading(4, "Small Step [step]")),
|
|
82
77
|
)
|
|
83
78
|
|
|
84
79
|
expect(findHeading(tree, 0).data?.hProperties).toEqual({ "data-step": 1 })
|
|
@@ -5,38 +5,35 @@ import { visit, SKIP } from "unist-util-visit"
|
|
|
5
5
|
|
|
6
6
|
/** Walk a mdast tree and convert :::tab directives into ContentTab/ContentTabs JSX elements */
|
|
7
7
|
export function transformTabDirectives(tree: Root) {
|
|
8
|
-
visit(
|
|
9
|
-
|
|
10
|
-
"containerDirective",
|
|
11
|
-
(node: ContainerDirective, index, parent) => {
|
|
12
|
-
if (node.name !== "tab" || index === undefined || !parent) return
|
|
8
|
+
visit(tree, "containerDirective", (node: ContainerDirective, index, parent) => {
|
|
9
|
+
if (node.name !== "tab" || index === undefined || !parent) return
|
|
13
10
|
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
const title = node.attributes?.title ?? ""
|
|
12
|
+
const sync = node.attributes?.sync
|
|
16
13
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
14
|
+
const attrs: { type: "mdxJsxAttribute"; name: string; value: string }[] = [
|
|
15
|
+
{ type: "mdxJsxAttribute" as const, name: "title", value: title },
|
|
16
|
+
]
|
|
17
|
+
if (sync) {
|
|
18
|
+
attrs.push({
|
|
19
|
+
type: "mdxJsxAttribute" as const,
|
|
20
|
+
name: "sync",
|
|
21
|
+
value: sync,
|
|
22
|
+
})
|
|
23
|
+
}
|
|
26
24
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
25
|
+
const jsxNode = {
|
|
26
|
+
type: "mdxJsxFlowElement" as const,
|
|
27
|
+
name: "ContentTab",
|
|
28
|
+
attributes: attrs,
|
|
29
|
+
children: node.children,
|
|
30
|
+
data: { _mdxExplicitJsx: true },
|
|
31
|
+
}
|
|
34
32
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
)
|
|
33
|
+
// @ts-expect-error mdxJsxFlowElement is not in mdast types
|
|
34
|
+
parent.children[index] = jsxNode
|
|
35
|
+
return SKIP
|
|
36
|
+
})
|
|
40
37
|
|
|
41
38
|
const children = tree.children
|
|
42
39
|
let i = 0
|
|
@@ -52,8 +49,7 @@ export function transformTabDirectives(tree: Root) {
|
|
|
52
49
|
while (j < children.length) {
|
|
53
50
|
const next = children[j]
|
|
54
51
|
// @ts-expect-error mdxJsxFlowElement is not in mdast types
|
|
55
|
-
if (next?.type !== "mdxJsxFlowElement" || next.name !== "ContentTab")
|
|
56
|
-
break
|
|
52
|
+
if (next?.type !== "mdxJsxFlowElement" || next.name !== "ContentTab") break
|
|
57
53
|
j++
|
|
58
54
|
}
|
|
59
55
|
|
|
@@ -11,9 +11,7 @@ function makeContainerDirective(
|
|
|
11
11
|
type: "containerDirective",
|
|
12
12
|
name,
|
|
13
13
|
attributes: attributes ?? {},
|
|
14
|
-
children: [
|
|
15
|
-
{ type: "paragraph", children: [{ type: "text", value: "content" }] },
|
|
16
|
-
],
|
|
14
|
+
children: [{ type: "paragraph", children: [{ type: "text", value: "content" }] }],
|
|
17
15
|
}
|
|
18
16
|
}
|
|
19
17
|
|
|
@@ -39,9 +37,7 @@ describe("transformTabDirectives", () => {
|
|
|
39
37
|
{
|
|
40
38
|
type: "mdxJsxFlowElement",
|
|
41
39
|
name: "ContentTab",
|
|
42
|
-
attributes: [
|
|
43
|
-
{ type: "mdxJsxAttribute", name: "title", value: "React" },
|
|
44
|
-
],
|
|
40
|
+
attributes: [{ type: "mdxJsxAttribute", name: "title", value: "React" }],
|
|
45
41
|
},
|
|
46
42
|
],
|
|
47
43
|
})
|
|
@@ -37,9 +37,7 @@ describe("transformTocDirectives", () => {
|
|
|
37
37
|
})
|
|
38
38
|
|
|
39
39
|
it("should ignore unrelated leaf directives", () => {
|
|
40
|
-
const tree = process(
|
|
41
|
-
makeTree(makeLeafDirective("video", { type: "youtube" })),
|
|
42
|
-
)
|
|
40
|
+
const tree = process(makeTree(makeLeafDirective("video", { type: "youtube" })))
|
|
43
41
|
const node = tree.children[0]
|
|
44
42
|
expect(node).toMatchObject({ type: "leafDirective", name: "video" })
|
|
45
43
|
})
|
|
@@ -4,10 +4,7 @@ interface HastElement {
|
|
|
4
4
|
|
|
5
5
|
interface ShikiTransformer {
|
|
6
6
|
name: string
|
|
7
|
-
pre: (
|
|
8
|
-
this: { options: { lang?: string } },
|
|
9
|
-
pre: HastElement,
|
|
10
|
-
) => HastElement | void
|
|
7
|
+
pre: (this: { options: { lang?: string } }, pre: HastElement) => HastElement | void
|
|
11
8
|
}
|
|
12
9
|
|
|
13
10
|
type Icon = { viewBox: string; fill: string; d: string }
|
|
@@ -11,10 +11,7 @@ interface HastElement {
|
|
|
11
11
|
|
|
12
12
|
interface ShikiTransformer {
|
|
13
13
|
name: string
|
|
14
|
-
preprocess?: (
|
|
15
|
-
this: { options: { meta?: { __raw?: string } } },
|
|
16
|
-
code: string,
|
|
17
|
-
) => void
|
|
14
|
+
preprocess?: (this: { options: { meta?: { __raw?: string } } }, code: string) => void
|
|
18
15
|
pre?: (pre: HastElement) => HastElement | void
|
|
19
16
|
line?: (line: HastElement, lineNumber: number) => HastElement | void
|
|
20
17
|
span?: (span: HastElement) => HastElement | void
|
|
@@ -67,8 +64,7 @@ function spanContainsWord(span: HastElement, word: string): boolean {
|
|
|
67
64
|
return false
|
|
68
65
|
}
|
|
69
66
|
|
|
70
|
-
const NOTATION_RE =
|
|
71
|
-
/\/\/\s*\[!code\s+(highlight|focus|\+\+|--|error|warning)\]\s*$/
|
|
67
|
+
const NOTATION_RE = /\/\/\s*\[!code\s+(highlight|focus|\+\+|--|error|warning)\]\s*$/
|
|
72
68
|
const NOTATION_BLOCK_RE =
|
|
73
69
|
/\/\*\s*\[!code\s+(highlight|focus|\+\+|--|error|warning)\]\s*\*\/\s*$/
|
|
74
70
|
|
|
@@ -79,8 +75,7 @@ function stripNotationFromLine(line: HastElement): string | undefined {
|
|
|
79
75
|
if (result !== undefined) return result
|
|
80
76
|
}
|
|
81
77
|
if (child.type === "text") {
|
|
82
|
-
const match =
|
|
83
|
-
child.value.match(NOTATION_RE) ?? child.value.match(NOTATION_BLOCK_RE)
|
|
78
|
+
const match = child.value.match(NOTATION_RE) ?? child.value.match(NOTATION_BLOCK_RE)
|
|
84
79
|
if (match) {
|
|
85
80
|
child.value = child.value.slice(0, match.index).trimEnd()
|
|
86
81
|
return match[1]!
|
|
@@ -158,9 +153,7 @@ export function transformerLineHighlight(): ShikiTransformer {
|
|
|
158
153
|
line.properties["data-highlighted"] = ""
|
|
159
154
|
}
|
|
160
155
|
if (lineNumbers.enabled) {
|
|
161
|
-
line.properties["data-line-number"] = String(
|
|
162
|
-
lineNumber - 1 + lineNumbers.start,
|
|
163
|
-
)
|
|
156
|
+
line.properties["data-line-number"] = String(lineNumber - 1 + lineNumbers.start)
|
|
164
157
|
}
|
|
165
158
|
return line
|
|
166
159
|
},
|