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

Support Multiple PreConfig for different languages #114

Open
huntrist opened this issue Jun 13, 2023 · 3 comments
Open

Support Multiple PreConfig for different languages #114

huntrist opened this issue Jun 13, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@huntrist
Copy link

Is your feature request related to a problem? Please describe.
Currently, only support 1 PreConfig, but sometimes, there might be multiple code blocks of DIFFERENT languages, and the language used might not be known before the markdown text is rendered.

Describe the solution you'd like
Please consider support multiple PreConfig: let user define ALL the languages they want to be supported, and MarkdownWidget chooses the correct one based on the Language marking in the markdown

Describe alternatives you've considered
N/A

Additional context
N/A

@huntrist huntrist added the enhancement New feature or request label Jun 13, 2023
@asjqkkkk
Copy link
Owner

Hi @huntrist , you can use the PreConfig like this:

            return MarkdownWidget(
                data: data!,
                config: config.copy(configs: [
                  PreConfig().copy(wrapper: (child, text){
                    ///detecting the current language through `text`
                    return YourCodeWidget(differentLanguage);
                  })
                ]),
            );

or custom your own CodeBlockNode

Because the content in CodeBlock cannot be determined currently, it may be pure text, a particular programming language, or a mixture of multiple languages. Therefore, I believe that in order to achieve such functionality, it needs to be determined by the user themselves.

@huntrist
Copy link
Author

huntrist commented Jul 7, 2023

Hi @huntrist , you can use the PreConfig like this:

            return MarkdownWidget(
                data: data!,
                config: config.copy(configs: [
                  PreConfig().copy(wrapper: (child, text){
                    ///detecting the current language through `text`
                    return YourCodeWidget(differentLanguage);
                  })
                ]),
            );

or custom your own CodeBlockNode

Because the content in CodeBlock cannot be determined currently, it may be pure text, a particular programming language, or a mixture of multiple languages. Therefore, I believe that in order to achieve such functionality, it needs to be determined by the user themselves.

thanks, this could work, but I still think making it accept multiple PreConfig for different languages, and detect language marking by the MarkdownWidget is a cleaner approach.
let me elaborate:

I believe it is a common practice specifying language with a "language marking" (called "info string" in the CommonMark spec: see text right after example-141: https://spec.commonmark.org/0.30/#example-141)

i.e. ``` javascript

if we let user specify multiple PreConfig for different languages, and MarkdownWidget can automatically detects the "language name marking" (javascript in this case), then the highlights can be applied accordingly. If no matching PreConfig for the language marking is found (or if no language marking is given), then apply the default PreConfig.

@asjqkkkk
Copy link
Owner

asjqkkkk commented Jul 7, 2023

Hi @huntrist , you can use the PreConfig like this:

            return MarkdownWidget(
                data: data!,
                config: config.copy(configs: [
                  PreConfig().copy(wrapper: (child, text){
                    ///detecting the current language through `text`
                    return YourCodeWidget(differentLanguage);
                  })
                ]),
            );

or custom your own CodeBlockNode
Because the content in CodeBlock cannot be determined currently, it may be pure text, a particular programming language, or a mixture of multiple languages. Therefore, I believe that in order to achieve such functionality, it needs to be determined by the user themselves.

thanks, this could work, but I still think making it accept multiple PreConfig for different languages, and detect language marking by the MarkdownWidget is a cleaner approach. let me elaborate:

I believe it is a common practice specifying language with a "language marking" (called "info string" in the CommonMark spec: see text right after example-141: https://spec.commonmark.org/0.30/#example-141)

i.e. ``` javascript

if we let user specify multiple PreConfig for different languages, and MarkdownWidget can automatically detects the "language name marking" (javascript in this case), then the highlights can be applied accordingly. If no matching PreConfig for the language marking is found (or if no language marking is given), then apply the default PreConfig.

Hi @huntrist , that's a good idea, I will consider how to implement this feature in the upcoming version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants