Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(mdx-loader): upgrade to MDX v3 #9451

Merged
merged 24 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 11 additions & 7 deletions jest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,20 @@ export default {
// MDX packages are ESM-only and it is a pain to use in Jest
// So we use them in Jest tests as CJS versions
// see https://mdxjs.com/docs/troubleshooting-mdx/#problems-integrating-mdx
'^unified$': '<rootDir>/jest/vendor/unified@10.1.2.js',
'^@mdx-js/mdx$': '<rootDir>/jest/vendor/@mdx-js__mdx@2.1.5.js',
'^remark$': '<rootDir>/jest/vendor/remark@14.0.2.js',
'^remark-mdx$': '<rootDir>/jest/vendor/remark-mdx@2.1.5.js',
'^remark-directive$': '<rootDir>/jest/vendor/remark-directive@2.0.1.js',
'^remark-gfm$': '<rootDir>/jest/vendor/remark-gfm@3.0.1.js',
'^@mdx-js/mdx$': '<rootDir>/jest/vendor/@mdx-js__mdx@3.0.0.js',
'^remark$': '<rootDir>/jest/vendor/remark@15.0.1.js',
'^remark-rehype$': '<rootDir>/jest/vendor/remark-rehype@11.0.0.js',
'^remark-mdx$': '<rootDir>/jest/vendor/remark-mdx@3.0.0.js',
'^remark-directive$': '<rootDir>/jest/vendor/remark-directive@3.0.0.js',
'^remark-gfm$': '<rootDir>/jest/vendor/remark-gfm@4.0.0.js',
'^estree-util-value-to-estree$':
'<rootDir>/jest/vendor/estree-util-value-to-estree@2.1.0.js',
'^mdast-util-to-string$':
'<rootDir>/jest/vendor/mdast-util-to-string@3.1.0.js',
'<rootDir>/jest/vendor/mdast-util-to-string@4.0.0.js',
'^unist-util-visit$': '<rootDir>/jest/vendor/unist-util-visit@5.0.0.js',
'^unist-util-remove-position$':
'<rootDir>/jest/vendor/unist-util-remove-position@5.0.0.js',
'^rehype-stringify$': '<rootDir>/jest/vendor/rehype-stringify@10.0.0.js',
},
snapshotSerializers: [
'<rootDir>/jest/snapshotPathNormalizer.ts',
Expand Down
31,033 changes: 17,035 additions & 13,998 deletions jest/vendor/@mdx-js__mdx@2.1.5.js → jest/vendor/@mdx-js__mdx@3.0.0.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,43 @@ __export(mdast_util_to_string_exports, {
toString: () => toString
});
module.exports = __toCommonJS(mdast_util_to_string_exports);
function toString(node, options) {
var { includeImageAlt = true } = options || {};
return one(node, includeImageAlt);

// node_modules/mdast-util-to-string/lib/index.js
var emptyOptions = {};
function toString(value, options) {
const settings = options || emptyOptions;
const includeImageAlt = typeof settings.includeImageAlt === "boolean" ? settings.includeImageAlt : true;
const includeHtml = typeof settings.includeHtml === "boolean" ? settings.includeHtml : true;
return one(value, includeImageAlt, includeHtml);
}
function one(node, includeImageAlt) {
return node && typeof node === "object" && (node.value || (includeImageAlt ? node.alt : "") || "children" in node && all(node.children, includeImageAlt) || Array.isArray(node) && all(node, includeImageAlt)) || "";
function one(value, includeImageAlt, includeHtml) {
if (node(value)) {
if ("value" in value) {
return value.type === "html" && !includeHtml ? "" : value.value;
}
if (includeImageAlt && "alt" in value && value.alt) {
return value.alt;
}
if ("children" in value) {
return all(value.children, includeImageAlt, includeHtml);
}
}
if (Array.isArray(value)) {
return all(value, includeImageAlt, includeHtml);
}
return "";
}
function all(values, includeImageAlt) {
var result = [];
var index = -1;
function all(values, includeImageAlt, includeHtml) {
const result = [];
let index = -1;
while (++index < values.length) {
result[index] = one(values[index], includeImageAlt);
result[index] = one(values[index], includeImageAlt, includeHtml);
}
return result.join("");
}
function node(value) {
return Boolean(value && typeof value === "object");
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
toString
Expand Down