Skip to content

Commit

Permalink
Update MarkdownComponent.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
mythz committed Feb 26, 2024
1 parent f4dd101 commit 0b9913a
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/components/MarkdownComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,19 @@ function Files({ body }: { body?: string }) {
const stack = [root]

for (const line of lines) {
const depth = line.search(/\S/)/indent
const depth = line.search(/\S/) / indent
const name = line.trim()
const parent:{[name:string]:any} = stack[depth]
const isDir = name.startsWith('/')

if (name.includes('.')) {
parent._.push(name)
} else {
const newObj = { _: [] }
const dir = name.substring(1)
parent[dir] = newObj
if (isDir) {
const dirName = name.substring(1)
const dirContents = { _: [] }
parent[dirName] = dirContents
stack.length = depth + 1
stack.push(newObj)
stack.push(dirContents)
} else {
parent._.push(name)
}
}
return root
Expand Down

0 comments on commit 0b9913a

Please sign in to comment.