Wrap source code in code tags

Open
#35 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
48/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
csharp
Domain
web-dev

Research direction

Start by reading HtmlClassFormatter and the existing WriteHeader and WriteFooter flow. Compare its generated HTML with the referenced CommonMark fenced-code behavior, then verify that code content is wrapped in a code element and that a language receives the specified class attribute. The issue does not name a test file, so check the repository's existing formatter tests or output examples before changing behavior.

Written by the indexing model from the issue text.

Description

Referencing this issue on markdown-colorcode, this package overwrites some of the behavior used in Markdig that appears to be in line with the CommonMark spec, that is, this package does not wrap code using a code element. Additionally, if a language is present, the spec specifies a class="language-[lang]" attribute as well.

I have not started a fork because I am not sure whether this would be a breaking change or not, however, the general change seems rather simple, adding the following methods to HtmlClassFormatter and then wrapping the inner text in WriteHeader and WriteFooter.

private void WriteHeaderCodeStart(ILanguage language)
{
    WriteElementStart("code", language.CssClassName);
}

private void WriteHeaderCodeEnd()
{
    WriteElementEnd("code");
}

In my case, this would make it easier to enforce consistent styling across my app.

Dominant language
C#
Stars
267
Forks
58
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from CommunityToolkit/ColorCode-Universal

All issues in CommunityToolkit/ColorCode-Universal

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.