-
Notifications
You must be signed in to change notification settings - Fork 27
Fix angle brackets escaped in web help code blocks #731
Conversation
Signed-off-by: Timothy Johnson <timothy.johnson@broadcom.com>
} else if (/^\s*#{4}\s*COMMANDS\s*$/i.test(line)) { | ||
return `${(index > 0) ? "\n" : ""}<h4>Commands</h4>\n`; | ||
} else if (/^\s*#{4}\s*GROUPS\s*$/i.test(line)) { | ||
return `${(index > 0) ? "\n" : ""}<h4>Groups</h4>\n`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This "hack" is no longer needed, because I fixed the casing of "Commands" and "Groups" in DefaultHelpGenerator.
@@ -320,17 +315,13 @@ export class WebHelpGenerator { | |||
{ commandDefinition: definition, fullCommandTree: this.mFullCommandTree, skipTextWrap: true }); | |||
|
|||
let markdownContent = helpGen.buildHelp() + "\n"; | |||
markdownContent = markdownContent.replace(/</g, "<").replace(/>/g, ">"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This "hack" is no longer needed, since markdown-it
handles angle brackets correctly. It seems to have been left behind as a remnant from when we were using marked
.
if (definition.type === "group") { | ||
// this is disabled for the CLIReadme.md but we want to show children here | ||
// so we'll call the help generator's children summary function even though | ||
// it's usually skipped when producing markdown | ||
markdownContent += this.buildChildrenSummaryTables(helpGen, rootCommandName + "_" + fullCommandName); | ||
} | ||
|
||
// Prevent line breaks from being lost during Markdown to HTML conversion | ||
markdownContent = markdownContent.replace(/^(\s+Default value:.+$)(\s+Allowed values:.+$)/gm, "$1\n$2"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This "hack" is no longer needed, thanks to zowe/zowe-cli#1275
Codecov Report
@@ Coverage Diff @@
## master #731 +/- ##
==========================================
- Coverage 82.53% 82.52% -0.02%
==========================================
Files 163 163
Lines 7937 7931 -6
Branches 1403 1400 -3
==========================================
- Hits 6551 6545 -6
Misses 1382 1382
Partials 4 4
Continue to review full report at Codecov.
|
Signed-off-by: Timothy Johnson <timothy.johnson@broadcom.com>
Kudos, SonarCloud Quality Gate passed! |
Both the
markdown-it
andsanitize-html
packages used to generate web help should handle angle brackets correctly.The problem seems to have been we were calling them in the wrong order - sanitizing an MD/HTML mix before passing it to
markdown-it
rather than sanitizing the output HTML resulted in some unexpected behavior.While investigating this, I realized the amount of HTML tags being injected into the MD we feed to
markdown-it
was very small (only in the methodbuildChildrenSummaryTables
). So this PR replaces those HTML tags with Markdown, removes thehtml: true
option from themarkdown-it
parser, and no longer requires thesanitize-html
package 🙂Here is a diff showing the changes introduced by this branch to the
all.html
file in web help: web-help-730.patch