Add HTML code element for code samples to enable syntax highlight. #762
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
Enabling syntax highlights on XML documentation code samples will make it easy for readers and users of an API to understand the code samples quickly and without much effort. The current published version of
fsdocs
enable syntax highlight on comments written in markdown format. However, following the guidelines in F# Recommended XML doc extensions for F# documentation tooling RFC produces an output that has no syntax highlight nor we can add syntax highlight to it due to the HTML structure that the samples are written on, the structure is not the convention so, other libraries will not detect it.Following the conventions from syntax highlighting libraries like highlightjs and prismjs and w3.org site samples, the code samples should be put in a
code
element inside thepre
element.This PR attempt to add this to enable syntax lighlight.
Fixes #761
Example
For example, for the following standard XML documentation code:
The result after using the tool to generate API documentation is as follows:
Note that the language on XML
code
element has transferred and been mapped to the correspondingHTML
element for syntax highlighters to get and operate on. In this way, users can pull a syntax highlighter and it will work out of the box.By this, the XML documentation will be kept with no changes. However, the output HTML will be as follows with changes highlighted.