Skip to content

Commit

Permalink
[v3] specify default language for code blocks (#3108)
Browse files Browse the repository at this point in the history
[v3] specify the default language as plaintext for code blocks

Co-authored-by: Dimitri POSTOLOV <dmytropostolov@gmail.com>
  • Loading branch information
87xie and dimaMachina authored Aug 21, 2024
1 parent 150184b commit 73239c4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .changeset/chilly-shoes-marry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'nextra-theme-blog': patch
'nextra-theme-docs': patch
'nextra': patch
---

To ensure consistent horizontal padding, set the default language as plaintext for code blocks. This prevents any loss of formatting for code blocks without a specified language.
10 changes: 10 additions & 0 deletions examples/blog/pages/posts/code-blocks.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ object Hello {
hello world
```

## Test with code block default language

```
const links = [
{ href: '/settings', label: 'Settings' },
{ href: '/support', label: 'Support' },
{ href: '/license', label: 'License' },
]
```

## Test link in code

Link to [`google`](https://google.com)
Expand Down
3 changes: 3 additions & 0 deletions packages/nextra/src/server/rehype-plugins/rehype.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ export const DEFAULT_REHYPE_PRETTY_CODE_OPTIONS: RehypePrettyCodeOptions = {
light: 'github-light',
dark: 'github-dark'
},
defaultLang: {
block: 'plaintext'
},
getHighlighter(opts) {
return getHighlighter({
...opts,
Expand Down

0 comments on commit 73239c4

Please sign in to comment.