Skip to content

Commit 79d4abb

Browse files
committed
fix: always compile mdx with sanitized markdown
1 parent d539205 commit 79d4abb

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

src/utils/docs.tsx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,17 @@ async function _getDocs(
9898

9999
const boxes: string[] = []
100100

101+
// Sanitize markdown
102+
let content = compiled.content
103+
// Remove <!-- --> comments from frontMatter
104+
.replace(FRONTMATTER_REGEX, '')
105+
// Remove extraneous comments from post
106+
.replace(COMMENT_REGEX, '')
107+
// Remove inline link syntax
108+
.replace(INLINE_LINK_REGEX, '$1')
109+
101110
await compileMDX({
102-
source: compiled.content,
111+
source: content,
103112
options: {
104113
mdxOptions: {
105114
rehypePlugins: [
@@ -116,7 +125,8 @@ async function _getDocs(
116125
boxes,
117126
//
118127
file,
119-
compiled,
128+
content,
129+
frontmatter,
120130
}
121131
}),
122132
)
@@ -135,7 +145,8 @@ async function _getDocs(
135145
boxes,
136146
// Passed from the 1st pass
137147
file,
138-
compiled,
148+
content,
149+
frontmatter,
139150
}) => {
140151
const relFilePath = file.substring(root.length) // "/getting-started/tutorials/store.mdx"
141152

@@ -159,8 +170,6 @@ async function _getDocs(
159170
// frontmatter
160171
//
161172

162-
const frontmatter = compiled.data
163-
164173
const description: string = frontmatter.description ?? ''
165174

166175
const sourcecode: string = frontmatter.sourcecode ?? ''
@@ -191,15 +200,6 @@ async function _getDocs(
191200
// } as Doc
192201
// }
193202

194-
// Sanitize markdown
195-
let content = compiled.content
196-
// Remove <!-- --> comments from frontMatter
197-
.replace(FRONTMATTER_REGEX, '')
198-
// Remove extraneous comments from post
199-
.replace(COMMENT_REGEX, '')
200-
// Remove inline link syntax
201-
.replace(INLINE_LINK_REGEX, '$1')
202-
203203
//
204204
// inline images
205205
//

0 commit comments

Comments
 (0)