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

Markdown code blocks marked as csharp missing defined syntax highlighting #8184

Closed
TheBoxyBear opened this issue Sep 21, 2022 · 9 comments
Closed

Comments

@TheBoxyBear
Copy link

TheBoxyBear commented Sep 21, 2022

Operating System: (Windows or Linux or MacOS)
Windows 11

DocFX Version Used:
docfx.console NuGet 2.59.4

Template used: (default or statictoc or contain custom template)
SingulinkFX

Steps to Reproduce:

  1. Create a .NET 6 console project with the docfx.console v2.59.4 NuGet Package
  2. Create a markdown with a multi-line C# code block
  3. Build and run the site locally

The SingulinkFX provides full syntax highlithing in config.css. Inspecting the resulting HTML, code blocks generated from assembly have their code split into spans with the respective colors applied. Defining a code block such as

Console.WriteLine("Hello World");

results in <code class="lang-csharp hljs"> tags with the code left as plain text, rather than being parsed and split into spans. The same happens if c# is used instead of cs with the code class being lang-c# hljs Actual example of problematic markdown

Expected Behavior:
Code in markdown code blocks are parsed and converted into spans with styles applied such as here https://www.singulink.com/Docs/Singulink.IO.FileSystem/articles/guides/getting-started.html

Actual Behavior:
Cotents of the code blocks are left are plain text between the opening and closing <code> tags, only applying styles for keywords like "new".

@TheBoxyBear TheBoxyBear changed the title Markdown code blocks marked as csharp missing defined syntax highlithing Markdown code blocks marked as csharp missing defined syntax highlithing Sep 21, 2022
@TheBoxyBear TheBoxyBear changed the title Markdown code blocks marked as csharp missing defined syntax highlithing Markdown code blocks marked as csharp missing defined syntax highlighting Sep 21, 2022
@paulushub
Copy link

@TheBoxyBear I am not sure I understand your issue clearly, but below is a screenshot example of a DocFX output. Is this different from yours?
codes

@TheBoxyBear
Copy link
Author

TheBoxyBear commented Sep 21, 2022

From an article image

Auto-generated for api image

In the article, the HTML for the code block is <code class="lang-csharp hljs">Sont song = Song.FromFile(path); </code>, unlike the code tags in the api pages and https://www.singulink.com/Docs/Singulink.IO.FileSystem/articles/guides/getting-started.html where the code is seprated into tokens with colors applied to each one.

@TheBoxyBear
Copy link
Author

image

@TheBoxyBear
Copy link
Author

TheBoxyBear commented Sep 21, 2022

Not entirely sure if this is a DocFx or template issue. I took a look through the template source files and could not find anything related to code blocks except the style definition for the block and colors for the different types of tokens.

@paulushub
Copy link

paulushub commented Sep 21, 2022

The syntax highlighting support is handled by highlight.js, which dynamically generate the coloring such as the <span class="hljs-keyword">public</span>. If this is what you are referring to, it is a JavaScript generated code so you will not see it in the output HTML file.

If your actual desire is color scheme (try some examples by clicking the style: on the sample demo code at highlight.js), then you will have to customize the template with your desired scheme.

@TheBoxyBear
Copy link
Author

TheBoxyBear commented Sep 21, 2022

Indeed, they are not present in the generated HTML but do when looking at the final HTML from DevTools. There is still a discrepency with how code blocks are generated between articles and api documentation. There are no javascript errors related to highlight.js when articles are loaded.

@TheBoxyBear
Copy link
Author

Seems that now spans do get generated but only for the more complex code. It could be that the blocks I was looking at had no signoficant tokens to be highlighted.

@paulushub
Copy link

There is still a discrepency with how code blocks are generated between articles and api documentation.

For the codes in the screenshot I posted, there is no difference in the outputs.

It could be that the blocks I was looking at had no signoficant tokens to be highlighted.

The level of highlight may also depend on the color scheme, the default may not be that colorful (just click the style: I mentioned earlier until you get style:default and compare to others). So try the scheme that meets your needs and use it in your custom template.

@TheBoxyBear
Copy link
Author

TheBoxyBear commented Sep 21, 2022

None issue, highlight.js applies no syntax highlighting to things like type references in bodies, methods calls, property references and variable references. This can cause certain code blocks appear to not have syntax highlighting while in reality, there is nothing to highlight.

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

No branches or pull requests

2 participants