web-infra-dev / rspress

🦀💨 A fast Rspack-based static site generator.
https://rspress.dev
MIT License
1.36k stars 120 forks source link

[Bug]: `markdown.highlightLanguages` config does not take effect #1026

Closed Timeless0911 closed 5 months ago

Timeless0911 commented 5 months ago

Version

-

Details

In Rspress doc https://rspress.dev/api/config/config-build#markdownhighlightlanguages

Each language config supports both string and [string, string] formats. In the array format, the former is the alias of the language, and the latter is the full name of the language. You can go to the file list to view all supported language full names.

Here can be understood as we can configure aliases to map some unsupported languages to the languages supported by prism( etc ['mdx', 'tsx']), or we can also make an abbreviation for a certain language ( etc ['oc', 'objectivec'])

But now there should be some problems in existing implementation, below code block are not highlighted.

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        NSLog(@"Hello, Objective-C!");
    }
    return 0;
}
<Alert type="info">This is a info alert</Alert>

Reproduce link

https://github.com/web-infra-dev/rspress/tree/main/e2e/fixtures/basic

Reproduce Steps

  1. cd https://github.com/web-infra-dev/rspress/tree/main/e2e/fixtures/basic
  2. modify rspress.config.ts
    
    import * as path from 'path';
    import { defineConfig } from 'rspress/config';

export default defineConfig({ root: path.join(__dirname, 'doc'), markdown: { highlightLanguages: [ ['oc', 'objectivec'], ['mdx', 'tsx'], ], }, });



`['mdx', 'tsx']` is the `DEFAULT_HIGHLIGHT_LANGUAGES` in https://github.com/web-infra-dev/rspress/blob/e42143357e9071bbc2e1e1821d29d4e66f1efd45/packages/shared/src/runtime-utils/index.ts#L11-L26

You can also try `['mdx', 'md']`, may be also check whether there are any problems with the logic of merging and deduplication highlight languages.

3. add some code blocks like below in `index.mdx`

![image](https://github.com/web-infra-dev/rspress/assets/50201324/8f56d387-115a-40b6-ae46-4b88da7dfcbf)

(since github will transform the raw code, so screenshot here)

4. run `pnpm dev`

6. see if the code is highlighted