Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions packages/cli/docsgen/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,23 @@ import {toKebab} from "./changeCase.js";
const DEFAULT_SEPARATOR = "\n\n";
const LINE_BREAK = "\n\n";

const HTML_ENTITIES: Record<string, string> = {
"<": "&lt;",
">": "&gt;",
"{": "&#123;",
"}": "&#125;",
};

// Encode characters that the docs renderer (MDX) would otherwise interpret as JSX/HTML.
// Skip content inside backtick code spans — markdown code spans render literal text and do
// NOT decode HTML entities, so encoding inside backticks would surface entity strings (e.g.
// `&#123;state_id&#125;`) on the docs page. MDX also treats inline code as literal, so braces
// inside backticks are safe to leave alone.
function sanitizeDescription(description: string): string {
return description
.replaceAll("<", "&lt;")
.replaceAll(">", "&gt;")
.replaceAll("{", "&#123;")
.replaceAll("}", "&#125;");
return description.replace(/`[^`]*`|[<>{}]/g, (match) => {
if (match.startsWith("`")) return match;
return HTML_ENTITIES[match] ?? match;
});
}

function renderExampleBody(example: CliExample, lodestarCommand?: string): string {
Expand Down
Loading