Skip to content
This repository was archived by the owner on Jul 30, 2025. It is now read-only.

Commit 596d7b2

Browse files
committed
fix(plugins/plugin-client-common): support for tips in guidebook wizard steps
This PR updates `toMarkdownString()` i.e. the logic to turn the markdown AST back into a string, so that it supports tips.
1 parent 4a26075 commit 596d7b2

File tree

1 file changed

+33
-15
lines changed

1 file changed

+33
-15
lines changed

plugins/plugin-client-common/src/components/Content/Markdown/toMarkdownString.ts

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -83,28 +83,46 @@ function visitDFS(root: Node, type: string, visitors: { pre?: Visitor; post?: Vi
8383

8484
function stringifyTabs(root: Node) {
8585
const post = (node: Node) => {
86-
if (isElementWithProperties(node) && isTabs(node.properties)) {
87-
const tabStackDepth = getTabsDepth(node.properties)
88-
const indentation = ''.padStart(tabStackDepth, ' ')
86+
if (isElementWithProperties(node)) {
87+
if (isTabs(node.properties)) {
88+
const tabStackDepth = getTabsDepth(node.properties)
89+
const indentation = ''.padStart(tabStackDepth, ' ')
8990

90-
node['value'] = indentAll(
91-
node.children.map(tab => {
92-
const tabTitle = getTabTitle(tab)
91+
node['value'] = indentAll(
92+
node.children.map(tab => {
93+
const tabTitle = getTabTitle(tab)
9394

94-
// eslint-disable-next-line @typescript-eslint/no-use-before-define
95-
const tabContent = indent(toMarkdownString(tab), ' ')
95+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
96+
const tabContent = indent(toMarkdownString(tab))
9697

97-
return `=== "${tabTitle}"
98+
return `=== "${tabTitle}"
9899
99100
${tabContent}
100101
`
101-
}),
102-
indentation
103-
)
102+
}),
103+
indentation
104+
)
104105

105-
delete node.tagName
106-
delete node.children
107-
delete node.properties
106+
delete node.tagName
107+
delete node.children
108+
delete node.properties
109+
} else if (node.tagName === 'tip') {
110+
const { className, title, open } = node.properties
111+
112+
const tipContent = node.children
113+
.map(toMarkdownString) // eslint-disable-line @typescript-eslint/no-use-before-define
114+
.map(_ => indent(_))
115+
.join('\n')
116+
117+
node['value'] = `!!!${open ? '+' : ''} ${className} "${title}"
118+
119+
${tipContent}
120+
`
121+
122+
delete node.tagName
123+
delete node.children
124+
delete node.properties
125+
}
108126
}
109127
}
110128

0 commit comments

Comments
 (0)