Skip to content
Merged
Show file tree
Hide file tree
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
121 changes: 64 additions & 57 deletions _includes/renderCommand.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,56 +52,60 @@ export default function renderCommand(

const toc: TableOfContentsItem_[] = [];

let about = command.about!.replaceAll(
SUBSEQUENT_ENCAPSULATED_ANSI_RE,
function (
_,
_opening1,
text1,
_closing1,
space,
opening2,
text2,
closing2,
) {
return `${opening2}${text1}${space}${text2}${closing2}`;
},
).replaceAll(SUBSEQUENT_ANSI_RE, "");
let aboutLines = about.split("\n");
const aboutLinesReadMoreIndex = aboutLines.findLastIndex((line) =>
line.toLowerCase().replaceAll(ANSI_RE, "").trim().startsWith("read more:")
);
if (aboutLinesReadMoreIndex !== -1) {
aboutLines = aboutLines.slice(0, aboutLinesReadMoreIndex);
}

about = aboutLines.join("\n").replaceAll(
ENCAPSULATED_ANSI_RE,
(_, opening, text, _closing, offset, string) => {
if (opening === "\u001b[32m") { // green, used as heading
return `### ${text}`;
} else if (
opening === "\u001b[38;5;245m" || opening === "\u001b[36m" ||
opening === "\u001b[1m" || opening === "\u001b[22m"
) { // gray and cyan used for code and snippets, and we treat yellow and bold as well as such
const lines = string.split("\n");
let line = "";

while (offset > 0) {
line = lines.shift();
offset -= line.length + 1;
}
// Add null check for command.about
let about = "";
if (command.about) {
about = command.about.replaceAll(
SUBSEQUENT_ENCAPSULATED_ANSI_RE,
function (
_,
_opening1,
text1,
_closing1,
space,
opening2,
text2,
closing2,
) {
return `${opening2}${text1}${space}${text2}${closing2}`;
},
).replaceAll(SUBSEQUENT_ANSI_RE, "");
let aboutLines = about.split("\n");
const aboutLinesReadMoreIndex = aboutLines.findLastIndex((line) =>
line.toLowerCase().replaceAll(ANSI_RE, "").trim().startsWith("read more:")
);
if (aboutLinesReadMoreIndex !== -1) {
aboutLines = aboutLines.slice(0, aboutLinesReadMoreIndex);
}

if (START_AND_END_ANSI_RE.test(line.trim())) {
return "\n```\n" + text + "\n```\n\n";
about = aboutLines.join("\n").replaceAll(
ENCAPSULATED_ANSI_RE,
(_, opening, text, _closing, offset, string) => {
if (opening === "\u001b[32m") { // green, used as heading
return `### ${text}`;
} else if (
opening === "\u001b[38;5;245m" || opening === "\u001b[36m" ||
opening === "\u001b[1m" || opening === "\u001b[22m"
) { // gray and cyan used for code and snippets, and we treat yellow and bold as well as such
const lines = string.split("\n");
let line = "";

while (offset > 0) {
line = lines.shift();
offset -= line.length + 1;
}

if (START_AND_END_ANSI_RE.test(line.trim())) {
return "\n```\n" + text + "\n```\n\n";
} else {
return "`" + text + "`";
}
} else {
return "`" + text + "`";
return text;
}
} else {
return text;
}
},
);
},
);
}

const args = [];
const options: Record<string, ArgType[]> = {};
Expand Down Expand Up @@ -171,16 +175,19 @@ function renderOption(group: string, arg: ArgType, helpers: Lume.Helpers) {
const id = `${group}-${arg.name}`;

let docsLink = null;
let help = arg.help.replaceAll(ANSI_RE, "");
const helpLines = help.split("\n");
const helpLinesDocsIndex = helpLines.findLastIndex((line) =>
line.toLowerCase()
.trim()
.startsWith("docs:")
);
if (helpLinesDocsIndex !== -1) {
help = helpLines.slice(0, helpLinesDocsIndex).join("\n");
docsLink = helpLines[helpLinesDocsIndex].trim().slice("docs:".length);
// Add null check for arg.help
let help = arg.help ? arg.help.replaceAll(ANSI_RE, "") : "";
if (help) {
const helpLines = help.split("\n");
const helpLinesDocsIndex = helpLines.findLastIndex((line) =>
line.toLowerCase()
.trim()
.startsWith("docs:")
);
if (helpLinesDocsIndex !== -1) {
help = helpLines.slice(0, helpLinesDocsIndex).join("\n");
docsLink = helpLines[helpLinesDocsIndex].trim().slice("docs:".length);
}
}

return (
Expand Down
2 changes: 1 addition & 1 deletion replacements.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"CLI_VERSION": "2.3.6"
"CLI_VERSION": "2.3.7"
}
Loading