Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support highlight alias to itself #1386

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions e2e/fixtures/prism-sytax-highlighter/doc/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,13 @@ int main(int argc, const char * argv[]) {
return 0;
}
```

```go
package main

import "fmt"

func main() {
fmt.Println("Hello, World!")
}
```
1 change: 1 addition & 0 deletions e2e/fixtures/prism-sytax-highlighter/rspress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default defineConfig({
['js', 'javascript'],
['oc', 'objectivec'],
['mdx', 'tsx'],
['go', 'go'],
],
},
});
7 changes: 5 additions & 2 deletions e2e/tests/prism-sytax-highlighter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@ test.describe('markdown highlight test', async () => {
test('does highlight work', async ({ page }) => {
await page.goto(`http://localhost:${appPort}`);

const text = await page
const textOc = await page
.locator('.language-objectivec .token.macro.directive-hash')
.evaluate(node => node.textContent);

expect(text).toBe('#');
const tokenGo = await page.locator('.language-go .token').count();

expect(textOc).toBe('#');
expect(tokenGo).toBe(14);
});

test('alias content match', async ({ page }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ export function handleHighlightLanguages(
temp.push(lang);
}

highlightLanguages.add(name);
// delete first, user may config alias to itself like ['go', 'go']
highlightLanguages.delete(lang);
highlightLanguages.add(name);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

exports[`automatic import of prism languages > prism languages aliases should be configurable to users 1`] = `
"export const aliases = {
"go": [
"go"
],
"javascript": [
"js"
],
Expand All @@ -13,7 +16,9 @@ exports[`automatic import of prism languages > prism languages aliases should be
]
};
export const languages = {
"javascript": require(
"go": require(
"react-syntax-highlighter/dist/cjs/languages/prism/go"
).default,"javascript": require(
"react-syntax-highlighter/dist/cjs/languages/prism/javascript"
).default,"objectivec": require(
"react-syntax-highlighter/dist/cjs/languages/prism/objectivec"
Expand Down
1 change: 1 addition & 0 deletions packages/core/tests/prismLanguages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ describe('automatic import of prism languages', () => {
highlightLanguages: [
['js', 'javascript'],
['oc', 'objectivec'],
['go', 'go'],
],
},
},
Expand Down
12 changes: 11 additions & 1 deletion packages/core/tests/prismLanguages/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,18 @@ int main(int argc, const char * argv[]) {
}
```

```go
package main

import "fmt"

func main() {
fmt.Println("Hello, World!")
}
```

# 内置组件

import InternalComponents from './extend'
import InternalComponents from './extend';

<InternalComponents />