docs: update markdown_process_inline_directive to work with indentations (#13590)

This commit is contained in:
Hyejin Yoon 2025-05-22 17:35:14 +09:00 committed by GitHub
parent a02d31c604
commit 76e952f4ac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -416,8 +416,15 @@ function markdown_process_inline_directives(
filepath: string
): void {
const new_content = contents.content.replace(
/^{{\s+inline\s+(\S+)\s+(show_path_as_comment\s+)?\s*}}$/gm,
(_, inline_file_path: string, show_path_as_comment: string) => {
/^(\s*){{(\s*)inline\s+(\S+)(\s+)(show_path_as_comment\s+)?(\s*)}}$/gm,
(
_,
indent: string,
__,
inline_file_path: string,
___,
show_path_as_comment: string
) => {
if (!inline_file_path.startsWith("/")) {
throw new Error(`inline path must be absolute: ${inline_file_path}`);
}
@ -432,9 +439,14 @@ function markdown_process_inline_directives(
// that can be used to limit the inlined content to a specific range of lines.
let new_contents = "";
if (show_path_as_comment) {
new_contents += `# Inlined from ${inline_file_path}\n`;
new_contents += `${indent}# Inlined from ${inline_file_path}\n`;
}
new_contents += referenced_file;
// Add indentation to each line of the referenced file
new_contents += referenced_file
.split("\n")
.map((line) => `${indent}${line}`)
.join("\n");
return new_contents;
}