fix: Render <important> and <note> XML doc tags in generated API reference#4353
fix: Render <important> and <note> XML doc tags in generated API reference#4353AlexDaines merged 2 commits intodevelopmentfrom
Conversation
68460c4 to
da80b4c
Compare
da80b4c to
6324c97
Compare
|
Screenshots on this PR would be helpful to understand what the pages will look like (you can get the artifacts from the doc updater step). |
Good idea. Added an example screenshot |
|
I thought we will use |
There was a problem hiding this comment.
Pull request overview
Updates the SDK documentation generator’s XML-doc-to-HTML transformation so <important> and <note> tags render as the existing “noteblock” callout UI used elsewhere in the doc output.
Changes:
- Add callout-element handling to map
<important>/<note>into<div class="noteblock">with a header label. - Emit a standardized
<div class="noteheader">Important:</div>/Note:header inside those blocks. - Add unit tests verifying the generated HTML output for common and edge cases.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| generator/.DevConfigs/4638aac9-482b-475c-a414-a34014955753.json | Adds required dev config entry for a patch-level doc generator fix. |
| docgenerator/SDKDocGeneratorLib/NDocUtilities.cs | Implements the new <important> / <note> element-to-HTML transformation behavior. |
| docgenerator/SDKDocGenerator.UnitTests/NDocUtilitiesHtmlTests.cs | Adds unit tests covering callout rendering, nested markup, and attribute preservation. |
| } | ||
|
|
||
| [Fact] | ||
| public void NoteTagWithTypeAttribute_DoesNotThrow() |
There was a problem hiding this comment.
PR description says "5 unit tests added" but this file contains 6 [Fact] tests (including this one). Please update the PR description/testing section to match the actual test additions.
| // Write callout header after all attributes are written | ||
| if (isCallout) | ||
| { | ||
| writer.WriteRaw("<div class=\"noteheader\">" + calloutHeader + "</div>"); |
There was a problem hiding this comment.
writer.WriteRaw("<div class=\"noteheader\">" + calloutHeader + "</div>") bypasses XmlWriter escaping and structure checks. Consider writing the header using WriteStartElement/WriteAttributeString/WriteString instead, so any future header text changes are safely escaped and the output remains well-formed.
| writer.WriteRaw("<div class=\"noteheader\">" + calloutHeader + "</div>"); | |
| writer.WriteStartElement("div"); | |
| writer.WriteAttributeString("class", "noteheader"); | |
| writer.WriteString(calloutHeader); | |
| writer.WriteEndElement(); |
| [Fact] | ||
| public void NoteTagWithTypeAttribute_DoesNotThrow() | ||
| { | ||
| var result = TransformSummary("<note type=\"caution\"><para>Be careful.</para></note>"); | ||
|
|
||
| Assert.Equal( | ||
| "<p><div class=\"noteblock\" type=\"caution\"><div class=\"noteheader\">Note:</div><p>Be careful.</p></div></p>", | ||
| result); |
There was a problem hiding this comment.
The test name NoteTagWithTypeAttribute_DoesNotThrow is misleading because the test asserts exact rendered HTML, not just that no exception is thrown. Renaming it to reflect the expected rendering (e.g., that attributes are preserved) would make failures easier to interpret.
|
I do kind of agree with Muhammad's general comment that the tag should wrap the text in bold using or something like that. Don't feel too strongly about keeping or removing "Important" but i think the text should be bolded at least |
I agree with this assessment. I went ahead and revised to use css changes to emphasize and sections and updated screenshots with the new implementation. |
muhammad-othman
left a comment
There was a problem hiding this comment.
Added few other comments but they are suggestions and not blocking so I'm approving the PR anyway.
| writer.WriteStartElement(elementName); | ||
|
|
||
| // Add CSS class if the original element has a class mapping | ||
| string cssClass; |
There was a problem hiding this comment.
nit: not need to define the class beforehand as it isn't used anywhere outside the if condition, you can do this instead
if (NdocToHtmlClassMapping.TryGetValue(originalLocalName, out var cssClass))
{
writer.WriteAttributeString("class", cssClass);
}
| { "see", "a" }, | ||
| { "paramref", "code" } | ||
| { "paramref", "code" }, | ||
| { "important", "div" }, |
There was a problem hiding this comment.
I would prefer if we use another element for important other than div for better accessibility.
| { "paramref", "code" } | ||
| { "paramref", "code" }, | ||
| { "important", "div" }, | ||
| { "note", "div" } |
There was a problem hiding this comment.
maybe we can even use small for note and if we did so we wont need NdocToHtmlClassMapping as important¬e can be identified with html tags and no need for css classes.
Description
Add handling for
<important>and<note>XML doc tags in the doc generator's HTML transformation pipeline. These tags appear across 2,583+ occurrences in the SDK's XML documentation corpus but were previously passed through as unrecognized elements. They now render as styled<div class="noteblock">blocks with an appropriate header (Important:orNote:).Motivation and Context
Service teams use
<important>and<note>tags in their API model documentation to highlight critical information. The doc generator was silently passing these through as raw<important>/<note>HTML elements, which browsers ignore as unknown tags — the content rendered as unstyled inline text with no visual distinction.Testing
Dry-run - Powershell5
Dry-run - Dotnet4
5 unit tests added in
NDocUtilitiesHtmlTests.cs, all using exact output assertions (Assert.Equal):ImportantTag_RendersAsNoteblock— standard<important>with inner<para>NoteTag_RendersAsNoteblock— standard<note>with inner<para>ParaTag_StillRendersAsParagraph— regression test for existing element mappingSelfClosingImportantTag_ProducesEmptyNoteblock— self-closing<important />edge caseImportantTagWithInnerMarkup_PreservesNestedElements—<c>tags nested inside callout, matching real corpus patternsAll 10 tests in
SDKDocGenerator.UnitTestspass.Screenshots (if appropriate)
Types of changes
Checklist
License