Skip to content

Commit

Permalink
Merge pull request #24 from altano/main
Browse files Browse the repository at this point in the history
fix: Don't aggressively trim code whitespace
  • Loading branch information
pomber authored Jul 23, 2023
2 parents 4044b8e + ffc5f47 commit 2c68871
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changeset/twelve-doors-rush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"bright": patch
"bright-web": patch
---

Don't trim all whitespace
8 changes: 6 additions & 2 deletions lib/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,21 +181,25 @@ function runExtensionsBeforeHighlight(props: CodeProps): CodeProps {
return newProps
}

function trimTrailingNewline(code: string | null): string | undefined {
return code?.replace(/\n$/, "") ?? undefined
}

function parseChildren(
children: CodeText,
lang?: LanguageAlias,
code?: string
): Partial<BrightProps> {
if (typeof children === "object" && children?.type === "code") {
return {
code: children.props?.children?.trim(),
code: trimTrailingNewline(children.props?.children),
...getLanguageAndTitle(children.props?.className),
}
} else if (typeof children === "object") {
const subProps = React.Children.toArray(children as any).map((c: any) => {
const codeProps = c.props?.children?.props
return {
code: codeProps.children?.trim(),
code: trimTrailingNewline(codeProps.children),
...getLanguageAndTitle(codeProps.className),
}
})
Expand Down
22 changes: 22 additions & 0 deletions web/app/test-mdx/mdx-demo.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,25 @@ console.log(1) // mark[3:10] red
// mark
const x = 20
```

## Mark code with space

````md
```


here is some text with leading and trailing spaces
that is working if the two lines are left-aligned.


```
````

```
here is some text with leading and trailing spaces
that is working if the two lines are left-aligned.
```

1 comment on commit 2c68871

@vercel
Copy link

@vercel vercel bot commented on 2c68871 Jul 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

bright – ./

bright-git-main-codehike.vercel.app
bright.codehike.org
bright-codehike.vercel.app

Please sign in to comment.