Skip to content

<code> tag extension to support a 'lang' or 'language' attribute.#127

Open
WetHat wants to merge 3 commits intoejball:masterfrom
WetHat:CodeTagExtension
Open

<code> tag extension to support a 'lang' or 'language' attribute.#127
WetHat wants to merge 3 commits intoejball:masterfrom
WetHat:CodeTagExtension

Conversation

@WetHat
Copy link
Copy Markdown

@WetHat WetHat commented Jan 19, 2023

The motivation for this pull request is the poor (non-existing) support for code language in <code> sections by the XML documentation specification: D.3.3 <code>. Oftentimes it is necessary to include code fragments in the documentation which are not CSHARP. Typical examples include XML, HTML, Javascript , or mermaid diagram code. To support these use cases the other tools such as the Sandcastle help file build allow
additional lang or language attributes on the <code> tag.

Example:

<code lang="Javascript">
if (/\S+@\S+\.\S+/.test('david@codeshack.io')) {
    console.log('Email is valid!');
} else {
    console.log('Email is invalid!');
}
</code>

would be converted to this Markdown fenced block:

``` Javascript
if (/\S+@\S+\.\S+/.test('david@codeshack.io')) {
    console.log('Email is valid!');
} else {
    console.log('Email is invalid!');
}
```

In the code changes provided in this pull request I have:

  • added support for lang or language attributes to generate Markdown output as shown in the example above.
  • improved the TrimCode method to be smarter about finding the optimal indent length of a code block.

I hope you find this contribution useful.

WetHat

inspecting the 'lang' or 'language' attribute of the tag.
Enhanced the TrimCode method to inspect the entire code
(not just the first line) to figure out the optimal indentation length.
@WetHat WetHat changed the title Code tag extension to support a 'lang' or 'language' attribute. <code> tag extension to support a 'lang' or 'language' attribute. Jan 20, 2023
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

Successfully merging this pull request may close these issues.

1 participant