feat: autogenerate keyboard shortcut docs (#12944)

This commit is contained in:
cornmander
2025-11-12 16:07:14 -05:00
committed by GitHub
parent 0075b4f118
commit aa9922bc98
9 changed files with 629 additions and 87 deletions

View File

@@ -81,3 +81,39 @@ export function formatDefaultValue(
return String(value);
}
}
interface MarkerInsertionOptions {
document: string;
startMarker: string;
endMarker: string;
newContent: string;
paddingBefore?: string;
paddingAfter?: string;
}
/**
* Replaces the content between two markers with `newContent`, preserving the
* original document outside the markers and applying optional padding.
*/
export function injectBetweenMarkers({
document,
startMarker,
endMarker,
newContent,
paddingBefore = '\n',
paddingAfter = '\n',
}: MarkerInsertionOptions): string {
const startIndex = document.indexOf(startMarker);
const endIndex = document.indexOf(endMarker);
if (startIndex === -1 || endIndex === -1 || startIndex >= endIndex) {
throw new Error(
`Could not locate documentation markers (${startMarker}, ${endMarker}).`,
);
}
const before = document.slice(0, startIndex + startMarker.length);
const after = document.slice(endIndex);
return `${before}${paddingBefore}${newContent}${paddingAfter}${after}`;
}