Skip to content

Commit

Permalink
fix: highlight alias to itself
Browse files Browse the repository at this point in the history
  • Loading branch information
Timeless0911 committed Sep 3, 2024
1 parent 353ebda commit 4c41422
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 5 deletions.
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 />

0 comments on commit 4c41422

Please sign in to comment.