wbaldoumas / markdown-colorcode

An extension for Markdig that adds syntax highlighting to code through the power of ColorCode-Universal.
https://wbaldoumas.github.io/markdown-colorcode/
MIT License
28 stars 5 forks source link

Use `HtmlClassFormatter.GetCSSString` #162

Open johnW-ret opened 1 month ago

johnW-ret commented 1 month ago

Problem Statement

Currently,

var builder = new MarkdownPipelineBuilder()
    // ...
    .UseColorCode(HtmlFormatterType.Css, /* ... */)
    // ...
    ;   

outputs HTML of the sort:

<div class="FSharp">
   <pre>
      ...
      <span class="string">"foo"</span>
      ...
   </pre>
</div>

To actually get styling, you need the CSS code from HtmlClassFormatter.GetCSSString from ColorCode.

Forgive me if I just misunderstand the code, but this library never calls HtmlClassFormatter.GetCSSString and HtmlClassFormatter is only stored as a private readonly field in a sealed class, so there is currently no way to get ths CSS styling out of this library.  

Proposed Solution

CSS should be placed in an inline style tag next to the rendered HTML.

Alternatives Considered

The aforementioned solution would cause style duplication (?), but it's also the simplest solution that works.

wbaldoumas commented 1 month ago

@johnW-ret thanks for your interest in Markdown.ColorCode and for opening this issue. This is similar to https://github.com/wbaldoumas/markdown-colorcode/issues/116.

The idea behind HtmlFormatterType.Css is to allow users of this library to customize their syntax coloring using their own CSS files. Rather than forcing the output of HtmlClassFormatter.GetCSSString into the generated HTML, users should specify their own CSS styling.

You can find (and use as-is or customize) the default CSS needed for HtmlFormatterType.Css here.

As a follow up, is there a documentation improvement that can be made that would make this more obvious?

github-actions[bot] commented 1 week ago

Automatically marking issue as stale due to lack of activity