diff --git a/tools/doc/html.mjs b/tools/doc/html.mjs index ff1c6854b58e22..428a7c761208db 100644 --- a/tools/doc/html.mjs +++ b/tools/doc/html.mjs @@ -205,6 +205,7 @@ function linkJsTypeDocs(text) { } const isJSFlavorSnippet = (node) => node.lang === 'cjs' || node.lang === 'mjs'; +const isPreSnippet = (node) => node.lang === 'pre'; // Preprocess headers, stability blockquotes, and YAML blocks. export function preprocessElements({ filename }) { @@ -265,6 +266,8 @@ export function preprocessElements({ filename }) { // Isolated JS snippet, no need to add the checkbox. node.value = `
${highlighted} ${copyButton}`;
}
+ } else if (isPreSnippet(node)) {
+ node.value = `${node.value}`;
} else {
node.value = `${highlighted} ${copyButton}`;
}
diff --git a/tools/doc/markdown.mjs b/tools/doc/markdown.mjs
index 21104e592b8a24..f148b0ecc6fea6 100644
--- a/tools/doc/markdown.mjs
+++ b/tools/doc/markdown.mjs
@@ -1,6 +1,7 @@
import { visit } from 'unist-util-visit';
export const referenceToLocalMdFile = /^(?![+a-z]+:)([^#?]+)\.md(#.+)?$/i;
+export const referenceToLocalMdFileInPre = //g;
export function replaceLinks({ filename, linksMapper }) {
return (tree) => {
@@ -14,6 +15,14 @@ export function replaceLinks({ filename, linksMapper }) {
);
}
});
+ visit(tree, 'code', (node) => {
+ if (node.meta === 'html') {
+ node.value = node.value.replace(
+ referenceToLocalMdFileInPre,
+ (_, path, fragment) => ``,
+ );
+ }
+ });
visit(tree, 'definition', (node) => {
const htmlUrl = fileHtmlUrls && fileHtmlUrls[node.identifier];
diff --git a/tools/lint-md/lint-md.mjs b/tools/lint-md/lint-md.mjs
index 2130891fe75d43..5758d70c9b5d45 100644
--- a/tools/lint-md/lint-md.mjs
+++ b/tools/lint-md/lint-md.mjs
@@ -23409,6 +23409,7 @@ const plugins = [
"markdown",
"mjs",
"powershell",
+ "pre",
"r",
"text",
"ts",