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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

TSX highlighting support #548

Closed
puku0x opened this issue May 13, 2020 · 4 comments 路 Fixed by #839
Closed

TSX highlighting support #548

puku0x opened this issue May 13, 2020 · 4 comments 路 Fixed by #839
Labels
enhancement New feature or request

Comments

@puku0x
Copy link
Contributor

puku0x commented May 13, 2020

馃З 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

@puku0x puku0x added the enhancement New feature or request label May 13, 2020
@Splaktar
Copy link
Contributor

If you use PrismJS as described in the docs, they have TSX support.

You just need to make sure to import the following in your HighlightService:

import 'prismjs/components/prism-tsx';

@puku0x
Copy link
Contributor Author

puku0x commented May 14, 2020

@Splaktar
Oh. I didn鈥檛 know Scully has a document site. Thank you for the info.

The HighlightService looks good too, for now.

@puku0x puku0x closed this as completed May 14, 2020
@puku0x
Copy link
Contributor Author

puku0x commented Aug 8, 2020

Wow, the plugin now uses Prism. I'm looking forward to the next update.
https://github.com/scullyio/scully/blob/main/libs/scully/src/lib/fileHanderPlugins/markdown.ts

@puku0x
Copy link
Contributor Author

puku0x commented Aug 8, 2020

I guess it's time to reopen this issue because Scully will be able to highlight JSX/TSX by adding following modules.

// libs/scully/src/lib/fileHanderPlugins/markdown.ts
require("prismjs/components/prism-jsx");
require("prismjs/components/prism-tsx");

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

Successfully merging a pull request may close this issue.

2 participants