Skip to content

TSX highlighting support #548

@puku0x

Description

@puku0x

🧩 Feature request

Description

markdownPlugin does not highlight some React / StencilJS components because highlight.js which is used in the plugin does not support .tsx files.

Example

```tsx
type Props = {
  value: number;
};

const SampleComponent: React.FC<Props> = (props) => (
  <p>{props.value}</p>
);

Describe the solution you'd like

I think Prism is a good alternative to solve this problem.

marked.setOptions({
    renderer: new marked.Renderer(),
    highlight: (code, language) => {
        // const hljs = require('highlight.js');
        // const validLanguage = hljs.getLanguage(language) ? language : 'plaintext';
        // return hljs.highlight(validLanguage, code).value;

        const Prism = require("prismjs");
        const loadLanguages = require("prismjs/components/index");
        loadLanguages(language);
        const validLanguage = Prism.languages[language] ? language : 'textfile';
        return Prism.highlight(code, Prism.languages[validLanguage], validLanguage);
    },

Describe alternatives you've considered

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions