How to add the razor code snippet?

I want to add the razor code snippet in md file and need to convert that md file in to html file using the jekyll.

Currently I am using the below one in the md file.

```cshtml

But it showing the code snippet like this.

image

But the same razor code snippet looking fine in the Microsoft document site. Please refer this.

I have mentioned the language as “razor-cshtml” and “razor” in the md file.

```razor-cshtml

But getting the below failure on conversion.

========================================================================
Conversion error: Jekyll::Converters::Markdown encountered an error while converting ‘getting-started.md’:
Traceback (most recent call last): File “C:\Ruby27-x64\lib\ruby\gems\2.7.0\gems\pygments.rb-2.2.0\lib\pygments\mentos.py”, line 244, in start res = self.get_data(method, lexer, args, kwargs, text) File “C:\Ruby27-x64\lib\ruby\gems\2.7.0\gems\pygments.rb-2.2.0\lib\pygments\mentos.py”, line 157, in get_data res = self.highlight_text(text, lexer, formatter_name, args, convert_keys(opts)) File “C:\Ruby27-x64\lib\ruby\gems\2.7.0\gems\pygments.rb-2.2.0\lib\pygments\mentos.py”, line 113, in highlight_text lexer = self.return_lexer(lexer, args, kwargs, code) File “C:\Ruby27-x64\lib\ruby\gems\2.7.0\gems\pygments.rb-2.2.0\lib\pygments\mentos.py”, line 70, in return_lexer return lexers.get_lexer_by_name(lexer, **inputs) File "C:\Ruby27-x64/lib/ruby/gems/2.7.0/gems/pygments.rb-2.2.0/lib/pygments/…/…/vendor/pygments-main\pygments\lexers_init.py", line 118, in get_lexer_by_name raise ClassNotFound(‘no lexer for alias %r found’ % _alias) pygments.util.ClassNotFound: no lexer for alias ‘razor-cshtml’ found
Error: Traceback (most recent call last): File “C:\Ruby27-x64\lib\ruby\gems\2.7.0\gems\pygments.rb-2.2.0\lib\pygments\mentos.py”, line 244, in start res = self.get_data(method, lexer, args, kwargs, text) File “C:\Ruby27-x64\lib\ruby\gems\2.7.0\gems\pygments.rb-2.2.0\lib\pygments\mentos.py”, line 157, in get_data res = self.highlight_text(text, lexer, formatter_name, args, convert_keys(opts)) File “C:\Ruby27-x64\lib\ruby\gems\2.7.0\gems\pygments.rb-2.2.0\lib\pygments\mentos.py”, line 113, in highlight_text lexer = self.return_lexer(lexer, args, kwargs, code) File “C:\Ruby27-x64\lib\ruby\gems\2.7.0\gems\pygments.rb-2.2.0\lib\pygments\mentos.py”, line 70, in return_lexer return lexers.get_lexer_by_name(lexer, **inputs) File "C:\Ruby27-x64/lib/ruby/gems/2.7.0/gems/pygments.rb-2.2.0/lib/pygments/…/…/vendor/pygments-main\pygments\lexers_init.py", line 118, in get_lexer_by_name raise ClassNotFound(‘no lexer for alias %r found’ % _alias) pygments.util.ClassNotFound: no lexer for alias ‘razor-cshtml’ found
Error: Run jekyll build --trace for more information.

========================================================================

Could you please help to resolve this or Let me know how to add the razor code snippet in the md file ?

Also let me know any plugins available for that.

Thanks in advance.

Regards,
Poovarasan K

Hi,
The error simply states that your syntax-highlighter (pygments.rb) doesn’t support the given alias (%r and razor-cshtml).

A quick look at the list of supported languages doesn’t show cshtml or razor

So, as of now, you can only highlight the razor code as plaintext (or perhaps try experimenting with various aliases such as, say html or a different syntax-highlighter entirely, if possible).

@{
    void RenderName(string name)
    {
        <p>Name: <strong>@name</strong></p>
    }

    RenderName("Mahatma Gandhi");
    RenderName("Martin Luther King, Jr.");
}
1 Like