This commit is contained in:
2024-03-22 03:47:51 +05:30
parent 8bcf3d211e
commit 89819f6fe2
28440 changed files with 3211033 additions and 2 deletions

14
node_modules/@docusaurus/mdx-loader/lib/format.d.ts generated vendored Normal file
View File

@@ -0,0 +1,14 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import type { MDXFrontMatter } from './frontMatter';
import type { Format, FormatInput } from './index';
export declare function getFormat({ filePath, frontMatterFormat, markdownConfigFormat, }: {
filePath: string;
frontMatterFormat: MDXFrontMatter['format'];
markdownConfigFormat: FormatInput;
}): Format;
//# sourceMappingURL=format.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../src/format.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,eAAe,CAAC;AAClD,OAAO,KAAK,EAAC,MAAM,EAAE,WAAW,EAAC,MAAM,SAAS,CAAC;AAqBjD,wBAAgB,SAAS,CAAC,EACxB,QAAQ,EACR,iBAAiB,EACjB,oBAAoB,GACrB,EAAE;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,iBAAiB,EAAE,cAAc,CAAC,QAAQ,CAAC,CAAC;IAC5C,oBAAoB,EAAE,WAAW,CAAC;CACnC,GAAG,MAAM,CAWT"}

42
node_modules/@docusaurus/mdx-loader/lib/format.js generated vendored Normal file
View File

@@ -0,0 +1,42 @@
"use strict";
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.getFormat = void 0;
const tslib_1 = require("tslib");
const path_1 = tslib_1.__importDefault(require("path"));
// Copied from https://mdxjs.com/packages/mdx/#optionsmdextensions
// Although we are likely to only use .md / .mdx anyway...
const mdFormatExtensions = [
'.md',
'.markdown',
'.mdown',
'.mkdn',
'.mkd',
'.mdwn',
'.mkdown',
'.ron',
];
function getExtensionFormat(filepath) {
const isMDFormat = mdFormatExtensions.includes(path_1.default.extname(filepath));
// Bias toward mdx if unknown extension
return isMDFormat ? 'md' : 'mdx';
}
function getFormat({ filePath, frontMatterFormat, markdownConfigFormat, }) {
if (frontMatterFormat) {
if (frontMatterFormat !== 'detect') {
return frontMatterFormat;
}
return getExtensionFormat(filePath);
}
if (markdownConfigFormat !== 'detect') {
return markdownConfigFormat;
}
return getExtensionFormat(filePath);
}
exports.getFormat = getFormat;
//# sourceMappingURL=format.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"format.js","sourceRoot":"","sources":["../src/format.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,wDAAwB;AAIxB,kEAAkE;AAClE,0DAA0D;AAC1D,MAAM,kBAAkB,GAAG;IACzB,KAAK;IACL,WAAW;IACX,QAAQ;IACR,OAAO;IACP,MAAM;IACN,OAAO;IACP,SAAS;IACT,MAAM;CACP,CAAC;AAEF,SAAS,kBAAkB,CAAC,QAAgB;IAC1C,MAAM,UAAU,GAAG,kBAAkB,CAAC,QAAQ,CAAC,cAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;IACvE,uCAAuC;IACvC,OAAO,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC;AACnC,CAAC;AAED,SAAgB,SAAS,CAAC,EACxB,QAAQ,EACR,iBAAiB,EACjB,oBAAoB,GAKrB;IACC,IAAI,iBAAiB,EAAE;QACrB,IAAI,iBAAiB,KAAK,QAAQ,EAAE;YAClC,OAAO,iBAAiB,CAAC;SAC1B;QACD,OAAO,kBAAkB,CAAC,QAAQ,CAAC,CAAC;KACrC;IACD,IAAI,oBAAoB,KAAK,QAAQ,EAAE;QACrC,OAAO,oBAAoB,CAAC;KAC7B;IACD,OAAO,kBAAkB,CAAC,QAAQ,CAAC,CAAC;AACtC,CAAC;AAnBD,8BAmBC"}

View File

@@ -0,0 +1,13 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import type { FormatInput } from './index';
export type MDXFrontMatter = {
format?: FormatInput;
};
export declare const DefaultMDXFrontMatter: MDXFrontMatter;
export declare function validateMDXFrontMatter(frontMatter: unknown): MDXFrontMatter;
//# sourceMappingURL=frontMatter.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"frontMatter.d.ts","sourceRoot":"","sources":["../src/frontMatter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,SAAS,CAAC;AAEzC,MAAM,MAAM,cAAc,GAAG;IAC3B,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB,CAAC;AAEF,eAAO,MAAM,qBAAqB,EAAE,cAEnC,CAAC;AAMF,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,OAAO,GAAG,cAAc,CAI3E"}

23
node_modules/@docusaurus/mdx-loader/lib/frontMatter.js generated vendored Normal file
View File

@@ -0,0 +1,23 @@
"use strict";
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.validateMDXFrontMatter = exports.DefaultMDXFrontMatter = void 0;
const utils_validation_1 = require("@docusaurus/utils-validation");
exports.DefaultMDXFrontMatter = {
format: undefined,
};
const MDXFrontMatterSchema = utils_validation_1.JoiFrontMatter.object({
format: utils_validation_1.JoiFrontMatter.string().equal('md', 'mdx', 'detect').optional(),
}).default(exports.DefaultMDXFrontMatter);
function validateMDXFrontMatter(frontMatter) {
return (0, utils_validation_1.validateFrontMatter)(frontMatter, MDXFrontMatterSchema, {
allowUnknown: false,
});
}
exports.validateMDXFrontMatter = validateMDXFrontMatter;
//# sourceMappingURL=frontMatter.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"frontMatter.js","sourceRoot":"","sources":["../src/frontMatter.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,mEAGsC;AAQzB,QAAA,qBAAqB,GAAmB;IACnD,MAAM,EAAE,SAAS;CAClB,CAAC;AAEF,MAAM,oBAAoB,GAAG,iCAAG,CAAC,MAAM,CAAiB;IACtD,MAAM,EAAE,iCAAG,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC,QAAQ,EAAE;CAC7D,CAAC,CAAC,OAAO,CAAC,6BAAqB,CAAC,CAAC;AAElC,SAAgB,sBAAsB,CAAC,WAAoB;IACzD,OAAO,IAAA,sCAAmB,EAAC,WAAW,EAAE,oBAAoB,EAAE;QAC5D,YAAY,EAAE,KAAK;KACpB,CAAC,CAAC;AACL,CAAC;AAJD,wDAIC"}

32
node_modules/@docusaurus/mdx-loader/lib/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,32 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import { mdxLoader } from './loader';
import type { TOCItem as TOCItemImported } from './remark/toc';
export default mdxLoader;
export type TOCItem = TOCItemImported;
export type Format = 'md' | 'mdx';
export type FormatInput = Format | 'detect';
export type LoadedMDXContent<FrontMatter, Metadata, Assets = undefined> = {
/** As verbatim declared in the MDX document. */
readonly frontMatter: FrontMatter;
/** As provided by the content plugin. */
readonly metadata: Metadata;
/** A list of TOC items (headings). */
readonly toc: readonly TOCItem[];
/** First h1 title before any content. */
readonly contentTitle: string | undefined;
/**
* Usually image assets that may be collocated like `./img/thumbnail.png`.
* The loader would also bundle these assets and the client should use these
* in priority.
*/
readonly assets: Assets;
(): JSX.Element;
};
export type { Options, MDXPlugin } from './loader';
export type { MDXOptions } from './processor';
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,SAAS,EAAC,MAAM,UAAU,CAAC;AAEnC,OAAO,KAAK,EAAC,OAAO,IAAI,eAAe,EAAC,MAAM,cAAc,CAAC;AAE7D,eAAe,SAAS,CAAC;AAEzB,MAAM,MAAM,OAAO,GAAG,eAAe,CAAC;AAEtC,MAAM,MAAM,MAAM,GAAG,IAAI,GAAG,KAAK,CAAC;AAElC,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,QAAQ,CAAC;AAE5C,MAAM,MAAM,gBAAgB,CAAC,WAAW,EAAE,QAAQ,EAAE,MAAM,GAAG,SAAS,IAAI;IACxE,gDAAgD;IAChD,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;IAClC,yCAAyC;IACzC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,sCAAsC;IACtC,QAAQ,CAAC,GAAG,EAAE,SAAS,OAAO,EAAE,CAAC;IACjC,yCAAyC;IACzC,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1C;;;;OAIG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,IAAI,GAAG,CAAC,OAAO,CAAC;CACjB,CAAC;AAEF,YAAY,EAAC,OAAO,EAAE,SAAS,EAAC,MAAM,UAAU,CAAC;AACjD,YAAY,EAAC,UAAU,EAAC,MAAM,aAAa,CAAC"}

11
node_modules/@docusaurus/mdx-loader/lib/index.js generated vendored Normal file
View File

@@ -0,0 +1,11 @@
"use strict";
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
Object.defineProperty(exports, "__esModule", { value: true });
const loader_1 = require("./loader");
exports.default = loader_1.mdxLoader;
//# sourceMappingURL=index.js.map

1
node_modules/@docusaurus/mdx-loader/lib/index.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAEH,qCAAmC;AAInC,kBAAe,kBAAS,CAAC"}

33
node_modules/@docusaurus/mdx-loader/lib/loader.d.ts generated vendored Normal file
View File

@@ -0,0 +1,33 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import type { MDXOptions } from './processor';
import type { MarkdownConfig } from '@docusaurus/types';
import type { LoaderContext } from 'webpack';
type Pluggable = any;
export type MDXPlugin = Pluggable;
export type Options = Partial<MDXOptions> & {
markdownConfig: MarkdownConfig;
staticDirs: string[];
siteDir: string;
isMDXPartial?: (filePath: string) => boolean;
isMDXPartialFrontMatterWarningDisabled?: boolean;
removeContentTitle?: boolean;
metadataPath?: string | ((filePath: string) => string);
createAssets?: (metadata: {
frontMatter: {
[key: string]: unknown;
};
metadata: {
[key: string]: unknown;
};
}) => {
[key: string]: unknown;
};
};
export declare function mdxLoader(this: LoaderContext<Options>, fileContent: string): Promise<void>;
export {};
//# sourceMappingURL=loader.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAcH,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,aAAa,CAAC;AAE5C,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,SAAS,CAAC;AAK3C,KAAK,SAAS,GAAG,GAAG,CAAC;AAMrB,MAAM,MAAM,SAAS,GAAG,SAAS,CAAC;AAElC,MAAM,MAAM,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,GAAG;IAC1C,cAAc,EAAE,cAAc,CAAC;IAC/B,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC;IAC7C,sCAAsC,CAAC,EAAE,OAAO,CAAC;IACjD,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,YAAY,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,QAAQ,EAAE,MAAM,KAAK,MAAM,CAAC,CAAC;IACvD,YAAY,CAAC,EAAE,CAAC,QAAQ,EAAE;QACxB,WAAW,EAAE;YAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;SAAC,CAAC;QACtC,QAAQ,EAAE;YAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;SAAC,CAAC;KACpC,KAAK;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAC,CAAC;CAChC,CAAC;AAsFF,wBAAsB,SAAS,CAC7B,IAAI,EAAE,aAAa,CAAC,OAAO,CAAC,EAC5B,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,IAAI,CAAC,CAiIf"}

189
node_modules/@docusaurus/mdx-loader/lib/loader.js generated vendored Normal file
View File

@@ -0,0 +1,189 @@
"use strict";
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.mdxLoader = void 0;
const tslib_1 = require("tslib");
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
const utils_1 = require("@docusaurus/utils");
const stringify_object_1 = tslib_1.__importDefault(require("stringify-object"));
const preprocessor_1 = tslib_1.__importDefault(require("./preprocessor"));
const frontMatter_1 = require("./frontMatter");
const processor_1 = require("./processor");
const { loaders: { inlineMarkdownAssetImageFileLoader }, } = (0, utils_1.getFileLoaderUtils)();
/**
* When this throws, it generally means that there's no metadata file associated
* with this MDX document. It can happen when using MDX partials (usually
* starting with _). That's why it's important to provide the `isMDXPartial`
* function in config
*/
async function readMetadataPath(metadataPath) {
try {
return await fs_extra_1.default.readFile(metadataPath, 'utf8');
}
catch (err) {
logger_1.default.error `MDX loader can't read MDX metadata file path=${metadataPath}. Maybe the isMDXPartial option function was not provided?`;
throw err;
}
}
/**
* Converts assets an object with Webpack require calls code.
* This is useful for mdx files to reference co-located assets using relative
* paths. Those assets should enter the Webpack assets pipeline and be hashed.
* For now, we only handle that for images and paths starting with `./`:
*
* `{image: "./myImage.png"}` => `{image: require("./myImage.png")}`
*/
function createAssetsExportCode(assets) {
if (typeof assets !== 'object' ||
!assets ||
Object.keys(assets).length === 0) {
return 'undefined';
}
// TODO implementation can be completed/enhanced
function createAssetValueCode(assetValue) {
if (Array.isArray(assetValue)) {
const arrayItemCodes = assetValue.map((item) => createAssetValueCode(item) ?? 'undefined');
return `[${arrayItemCodes.join(', ')}]`;
}
// Only process string values starting with ./
// We could enhance this logic and check if file exists on disc?
if (typeof assetValue === 'string' && assetValue.startsWith('./')) {
// TODO do we have other use-cases than image assets?
// Probably not worth adding more support, as we want to move to Webpack 5 new asset system (https://github.com/facebook/docusaurus/pull/4708)
return `require("${inlineMarkdownAssetImageFileLoader}${(0, utils_1.escapePath)(assetValue)}").default`;
}
return undefined;
}
const assetEntries = Object.entries(assets);
const codeLines = assetEntries
.map(([key, value]) => {
const assetRequireCode = createAssetValueCode(value);
return assetRequireCode ? `"${key}": ${assetRequireCode},` : undefined;
})
.filter(Boolean);
return `{\n${codeLines.join('\n')}\n}`;
}
// TODO temporary, remove this after v3.1?
// Some plugin authors use our mdx-loader, despite it not being public API
// see https://github.com/facebook/docusaurus/issues/8298
function ensureMarkdownConfig(reqOptions) {
if (!reqOptions.markdownConfig) {
throw new Error('Docusaurus v3+ requires MDX loader options.markdownConfig - plugin authors using the MDX loader should make sure to provide that option');
}
}
/**
* data.contentTitle is set by the remark contentTitle plugin
*/
function extractContentTitleData(data) {
return data.contentTitle;
}
async function mdxLoader(fileContent) {
const compilerName = (0, utils_1.getWebpackLoaderCompilerName)(this);
const callback = this.async();
const filePath = this.resourcePath;
const reqOptions = this.getOptions();
const { query } = this;
ensureMarkdownConfig(reqOptions);
const { frontMatter } = await reqOptions.markdownConfig.parseFrontMatter({
filePath,
fileContent,
defaultParseFrontMatter: utils_1.DEFAULT_PARSE_FRONT_MATTER,
});
const mdxFrontMatter = (0, frontMatter_1.validateMDXFrontMatter)(frontMatter.mdx);
const preprocessedContent = (0, preprocessor_1.default)({
fileContent,
filePath,
admonitions: reqOptions.admonitions,
markdownConfig: reqOptions.markdownConfig,
});
const hasFrontMatter = Object.keys(frontMatter).length > 0;
const processor = await (0, processor_1.createProcessorCached)({
filePath,
reqOptions,
query,
mdxFrontMatter,
});
let result;
try {
result = await processor.process({
content: preprocessedContent,
filePath,
frontMatter,
compilerName,
});
}
catch (errorUnknown) {
const error = errorUnknown;
// MDX can emit errors that have useful extra attributes
const errorJSON = JSON.stringify(error, null, 2);
const errorDetails = errorJSON === '{}'
? // regular JS error case: print stacktrace
error.stack ?? 'N/A'
: // MDX error: print extra attributes + stacktrace
`${errorJSON}\n${error.stack}`;
return callback(new Error(`MDX compilation failed for file ${logger_1.default.path(filePath)}\nCause: ${error.message}\nDetails:\n${errorDetails}`,
// TODO error cause doesn't seem to be used by Webpack stats.errors :s
{ cause: error }));
}
const contentTitle = extractContentTitleData(result.data);
// MDX partials are MDX files starting with _ or in a folder starting with _
// Partial are not expected to have associated metadata files or front matter
const isMDXPartial = reqOptions.isMDXPartial?.(filePath);
if (isMDXPartial && hasFrontMatter) {
const errorMessage = `Docusaurus MDX partial files should not contain front matter.
Those partial files use the _ prefix as a convention by default, but this is configurable.
File at ${filePath} contains front matter that will be ignored:
${JSON.stringify(frontMatter, null, 2)}`;
if (!reqOptions.isMDXPartialFrontMatterWarningDisabled) {
const shouldError = process.env.NODE_ENV === 'test' || process.env.CI;
if (shouldError) {
return callback(new Error(errorMessage));
}
logger_1.default.warn(errorMessage);
}
}
function getMetadataPath() {
if (!isMDXPartial) {
// Read metadata for this MDX and export it.
if (reqOptions.metadataPath &&
typeof reqOptions.metadataPath === 'function') {
return reqOptions.metadataPath(filePath);
}
}
return undefined;
}
const metadataPath = getMetadataPath();
if (metadataPath) {
this.addDependency(metadataPath);
}
const metadataJsonString = metadataPath
? await readMetadataPath(metadataPath)
: undefined;
const metadata = metadataJsonString
? JSON.parse(metadataJsonString)
: undefined;
const assets = reqOptions.createAssets && metadata
? reqOptions.createAssets({ frontMatter, metadata })
: undefined;
// TODO use remark plugins to insert extra exports instead of string concat?
// cf how the toc is exported
const exportsCode = `
export const frontMatter = ${(0, stringify_object_1.default)(frontMatter)};
export const contentTitle = ${(0, stringify_object_1.default)(contentTitle)};
${metadataJsonString ? `export const metadata = ${metadataJsonString};` : ''}
${assets ? `export const assets = ${createAssetsExportCode(assets)};` : ''}
`;
const code = `
${exportsCode}
${result.content}
`;
return callback(null, code);
}
exports.mdxLoader = mdxLoader;
//# sourceMappingURL=loader.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,gEAA0B;AAC1B,wEAAwC;AACxC,6CAK2B;AAC3B,gFAA+C;AAC/C,0EAA0C;AAC1C,+CAAqD;AACrD,2CAAkD;AAWlD,MAAM,EACJ,OAAO,EAAE,EAAC,kCAAkC,EAAC,GAC9C,GAAG,IAAA,0BAAkB,GAAE,CAAC;AAkBzB;;;;;GAKG;AACH,KAAK,UAAU,gBAAgB,CAAC,YAAoB;IAClD,IAAI;QACF,OAAO,MAAM,kBAAE,CAAC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;KAChD;IAAC,OAAO,GAAG,EAAE;QACZ,gBAAM,CAAC,KAAK,CAAA,gDAAgD,YAAY,4DAA4D,CAAC;QACrI,MAAM,GAAG,CAAC;KACX;AACH,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,sBAAsB,CAAC,MAAe;IAC7C,IACE,OAAO,MAAM,KAAK,QAAQ;QAC1B,CAAC,MAAM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AAC;AApID,8BAoIC"}

View File

@@ -0,0 +1,18 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import type { Options } from './loader';
/**
* Preprocess the string before passing it to MDX
* This is not particularly recommended but makes it easier to upgrade to MDX 2
*/
export default function preprocessContent({ fileContent: initialFileContent, filePath, markdownConfig, admonitions, }: {
fileContent: string;
filePath: string;
markdownConfig: Options['markdownConfig'];
admonitions: Options['admonitions'] | undefined;
}): string;
//# sourceMappingURL=preprocessor.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"preprocessor.d.ts","sourceRoot":"","sources":["../src/preprocessor.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAQH,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,UAAU,CAAC;AAEtC;;;GAGG;AACH,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,EACxC,WAAW,EAAE,kBAAkB,EAC/B,QAAQ,EACR,cAAc,EACd,WAAW,GACZ,EAAE;IACD,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAC1C,WAAW,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG,SAAS,CAAC;CACjD,GAAG,MAAM,CAiBT"}

View File

@@ -0,0 +1,34 @@
"use strict";
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
Object.defineProperty(exports, "__esModule", { value: true });
const utils_1 = require("@docusaurus/utils");
const admonitions_1 = require("./remark/admonitions");
/**
* Preprocess the string before passing it to MDX
* This is not particularly recommended but makes it easier to upgrade to MDX 2
*/
function preprocessContent({ fileContent: initialFileContent, filePath, markdownConfig, admonitions, }) {
let fileContent = initialFileContent;
if (markdownConfig.preprocessor) {
fileContent = markdownConfig.preprocessor({
fileContent,
filePath,
});
}
fileContent = (0, utils_1.unwrapMdxCodeBlocks)(fileContent);
if (markdownConfig.mdx1Compat.headingIds) {
fileContent = (0, utils_1.escapeMarkdownHeadingIds)(fileContent);
}
if (markdownConfig.mdx1Compat.admonitions && admonitions) {
const { keywords } = (0, admonitions_1.normalizeAdmonitionOptions)(admonitions);
fileContent = (0, utils_1.admonitionTitleToDirectiveLabel)(fileContent, keywords);
}
return fileContent;
}
exports.default = preprocessContent;
//# sourceMappingURL=preprocessor.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"preprocessor.js","sourceRoot":"","sources":["../src/preprocessor.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAEH,6CAI2B;AAC3B,sDAAgE;AAGhE;;;GAGG;AACH,SAAwB,iBAAiB,CAAC,EACxC,WAAW,EAAE,kBAAkB,EAC/B,QAAQ,EACR,cAAc,EACd,WAAW,GAMZ;IACC,IAAI,WAAW,GAAG,kBAAkB,CAAC;IACrC,IAAI,cAAc,CAAC,YAAY,EAAE;QAC/B,WAAW,GAAG,cAAc,CAAC,YAAY,CAAC;YACxC,WAAW;YACX,QAAQ;SACT,CAAC,CAAC;KACJ;IACD,WAAW,GAAG,IAAA,2BAAmB,EAAC,WAAW,CAAC,CAAC;IAC/C,IAAI,cAAc,CAAC,UAAU,CAAC,UAAU,EAAE;QACxC,WAAW,GAAG,IAAA,gCAAwB,EAAC,WAAW,CAAC,CAAC;KACrD;IACD,IAAI,cAAc,CAAC,UAAU,CAAC,WAAW,IAAI,WAAW,EAAE;QACxD,MAAM,EAAC,QAAQ,EAAC,GAAG,IAAA,wCAA0B,EAAC,WAAW,CAAC,CAAC;QAC3D,WAAW,GAAG,IAAA,uCAA+B,EAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;KACtE;IACD,OAAO,WAAW,CAAC;AACrB,CAAC;AA3BD,oCA2BC"}

47
node_modules/@docusaurus/mdx-loader/lib/processor.d.ts generated vendored Normal file
View File

@@ -0,0 +1,47 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import type { WebpackCompilerName } from '@docusaurus/utils';
import type { MDXFrontMatter } from './frontMatter';
import type { Options } from './loader';
import type { AdmonitionOptions } from './remark/admonitions';
type Pluggable = any;
type SimpleProcessorResult = {
content: string;
data: {
[key: string]: unknown;
};
};
type SimpleProcessor = {
process: ({ content, filePath, frontMatter, compilerName, }: {
content: string;
filePath: string;
frontMatter: {
[key: string]: unknown;
};
compilerName: WebpackCompilerName;
}) => Promise<SimpleProcessorResult>;
};
export type MDXPlugin = Pluggable;
export type MDXOptions = {
admonitions: boolean | Partial<AdmonitionOptions>;
remarkPlugins: MDXPlugin[];
rehypePlugins: MDXPlugin[];
beforeDefaultRemarkPlugins: MDXPlugin[];
beforeDefaultRehypePlugins: MDXPlugin[];
};
export declare function createProcessorUncached(parameters: {
options: Options;
format: 'md' | 'mdx';
}): Promise<SimpleProcessor>;
export declare function createProcessorCached({ filePath, mdxFrontMatter, query, reqOptions, }: {
filePath: string;
mdxFrontMatter: MDXFrontMatter;
query: string | Options;
reqOptions: Options;
}): Promise<SimpleProcessor>;
export {};
//# sourceMappingURL=processor.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"processor.d.ts","sourceRoot":"","sources":["../src/processor.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAcH,OAAO,KAAK,EAAC,mBAAmB,EAAC,MAAM,mBAAmB,CAAC;AAC3D,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,eAAe,CAAC;AAClD,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,UAAU,CAAC;AACtC,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,sBAAsB,CAAC;AAQ5D,KAAK,SAAS,GAAG,GAAG,CAAC;AAErB,KAAK,qBAAqB,GAAG;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAC,CAAA;CAAC,CAAC;AAG/E,KAAK,eAAe,GAAG;IACrB,OAAO,EAAE,CAAC,EACR,OAAO,EACP,QAAQ,EACR,WAAW,EACX,YAAY,GACb,EAAE;QACD,OAAO,EAAE,MAAM,CAAC;QAChB,QAAQ,EAAE,MAAM,CAAC;QACjB,WAAW,EAAE;YAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;SAAC,CAAC;QACtC,YAAY,EAAE,mBAAmB,CAAC;KACnC,KAAK,OAAO,CAAC,qBAAqB,CAAC,CAAC;CACtC,CAAC;AAOF,MAAM,MAAM,SAAS,GAAG,SAAS,CAAC;AAElC,MAAM,MAAM,UAAU,GAAG;IACvB,WAAW,EAAE,OAAO,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAClD,aAAa,EAAE,SAAS,EAAE,CAAC;IAC3B,aAAa,EAAE,SAAS,EAAE,CAAC;IAC3B,0BAA0B,EAAE,SAAS,EAAE,CAAC;IACxC,0BAA0B,EAAE,SAAS,EAAE,CAAC;CACzC,CAAC;AAmIF,wBAAsB,uBAAuB,CAAC,UAAU,EAAE;IACxD,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,IAAI,GAAG,KAAK,CAAC;CACtB,GAAG,OAAO,CAAC,eAAe,CAAC,CAG3B;AA0CD,wBAAsB,qBAAqB,CAAC,EAC1C,QAAQ,EACR,cAAc,EACd,KAAK,EACL,UAAU,GACX,EAAE;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,cAAc,CAAC;IAC/B,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;IACxB,UAAU,EAAE,OAAO,CAAC;CACrB,GAAG,OAAO,CAAC,eAAe,CAAC,CAU3B"}

172
node_modules/@docusaurus/mdx-loader/lib/processor.js generated vendored Normal file
View File

@@ -0,0 +1,172 @@
"use strict";
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.createProcessorCached = exports.createProcessorUncached = void 0;
const tslib_1 = require("tslib");
const headings_1 = tslib_1.__importDefault(require("./remark/headings"));
const contentTitle_1 = tslib_1.__importDefault(require("./remark/contentTitle"));
const toc_1 = tslib_1.__importDefault(require("./remark/toc"));
const transformImage_1 = tslib_1.__importDefault(require("./remark/transformImage"));
const transformLinks_1 = tslib_1.__importDefault(require("./remark/transformLinks"));
const details_1 = tslib_1.__importDefault(require("./remark/details"));
const head_1 = tslib_1.__importDefault(require("./remark/head"));
const mermaid_1 = tslib_1.__importDefault(require("./remark/mermaid"));
const admonitions_1 = tslib_1.__importDefault(require("./remark/admonitions"));
const unusedDirectives_1 = tslib_1.__importDefault(require("./remark/unusedDirectives"));
const codeCompatPlugin_1 = tslib_1.__importDefault(require("./remark/mdx1Compat/codeCompatPlugin"));
const format_1 = require("./format");
async function getDefaultRemarkPlugins() {
const { default: emoji } = await import('remark-emoji');
return [headings_1.default, emoji, toc_1.default];
}
function getAdmonitionsPlugins(admonitionsOption) {
if (admonitionsOption) {
const plugin = admonitionsOption === true
? admonitions_1.default
: [admonitions_1.default, admonitionsOption];
return [plugin];
}
return [];
}
// Need to be async due to ESM dynamic imports...
async function createProcessorFactory() {
const { createProcessor: createMdxProcessor } = await import('@mdx-js/mdx');
const { default: frontmatter } = await import('remark-frontmatter');
const { default: rehypeRaw } = await import('rehype-raw');
const { default: gfm } = await import('remark-gfm');
// TODO using fork until PR merged: https://github.com/leebyron/remark-comment/pull/3
const { default: comment } = await import('@slorber/remark-comment');
const { default: directive } = await import('remark-directive');
const { VFile } = await import('vfile');
const defaultRemarkPlugins = await getDefaultRemarkPlugins();
// /!\ this method is synchronous on purpose
// Using async code here can create cache entry race conditions!
function createProcessorSync({ options, format, }) {
const remarkPlugins = [
...(options.beforeDefaultRemarkPlugins ?? []),
frontmatter,
directive,
[contentTitle_1.default, { removeContentTitle: options.removeContentTitle }],
...getAdmonitionsPlugins(options.admonitions ?? false),
...defaultRemarkPlugins,
details_1.default,
head_1.default,
...(options.markdownConfig.mermaid ? [mermaid_1.default] : []),
[
transformImage_1.default,
{
staticDirs: options.staticDirs,
siteDir: options.siteDir,
},
],
[
transformLinks_1.default,
{
staticDirs: options.staticDirs,
siteDir: options.siteDir,
},
],
gfm,
options.markdownConfig.mdx1Compat.comments ? comment : null,
...(options.remarkPlugins ?? []),
unusedDirectives_1.default,
].filter((plugin) => Boolean(plugin));
// codeCompatPlugin needs to be applied last after user-provided plugins
// (after npm2yarn for example)
remarkPlugins.push(codeCompatPlugin_1.default);
const rehypePlugins = [
...(options.beforeDefaultRehypePlugins ?? []),
...(options.rehypePlugins ?? []),
];
if (format === 'md') {
// This is what permits to embed HTML elements with format 'md'
// See https://github.com/facebook/docusaurus/pull/8960
// See https://github.com/mdx-js/mdx/pull/2295#issuecomment-1540085960
const rehypeRawPlugin = [
rehypeRaw,
{
passThrough: [
'mdxFlowExpression',
'mdxJsxFlowElement',
'mdxJsxTextElement',
'mdxTextExpression',
'mdxjsEsm',
],
},
];
rehypePlugins.unshift(rehypeRawPlugin);
}
const processorOptions = {
...options,
remarkPlugins,
rehypePlugins,
providerImportSource: '@mdx-js/react',
};
const mdxProcessor = createMdxProcessor({
...processorOptions,
remarkRehypeOptions: options.markdownConfig.remarkRehypeOptions,
format,
});
return {
process: async ({ content, filePath, frontMatter, compilerName }) => {
const vfile = new VFile({
value: content,
path: filePath,
data: {
frontMatter,
compilerName,
},
});
return mdxProcessor.process(vfile).then((result) => ({
content: result.toString(),
data: result.data,
}));
},
};
}
return { createProcessorSync };
}
// Will be useful for tests
async function createProcessorUncached(parameters) {
const { createProcessorSync } = await createProcessorFactory();
return createProcessorSync(parameters);
}
exports.createProcessorUncached = createProcessorUncached;
// Compilers are cached so that Remark/Rehype plugins can run
// expensive code during initialization
const ProcessorsCache = new Map();
async function createProcessorsCacheEntry({ query, reqOptions, }) {
const { createProcessorSync } = await createProcessorFactory();
const compilers = ProcessorsCache.get(query);
if (compilers) {
return compilers;
}
const compilerCacheEntry = {
mdProcessor: createProcessorSync({
options: reqOptions,
format: 'md',
}),
mdxProcessor: createProcessorSync({
options: reqOptions,
format: 'mdx',
}),
};
ProcessorsCache.set(query, compilerCacheEntry);
return compilerCacheEntry;
}
async function createProcessorCached({ filePath, mdxFrontMatter, query, reqOptions, }) {
const compilers = await createProcessorsCacheEntry({ query, reqOptions });
const format = (0, format_1.getFormat)({
filePath,
frontMatterFormat: mdxFrontMatter.format,
markdownConfigFormat: reqOptions.markdownConfig.format,
});
return format === 'md' ? compilers.mdProcessor : compilers.mdxProcessor;
}
exports.createProcessorCached = createProcessorCached;
//# sourceMappingURL=processor.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"processor.js","sourceRoot":"","sources":["../src/processor.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,yEAAyC;AACzC,iFAAiD;AACjD,+DAA+B;AAC/B,qFAAqD;AACrD,qFAAqD;AACrD,uEAAuC;AACvC,iEAAiC;AACjC,uEAAuC;AACvC,+EAAwD;AACxD,yFAAgE;AAChE,oGAAoE;AACpE,qCAAmC;AA+BnC,KAAK,UAAU,uBAAuB;IACpC,MAAM,EAAC,OAAO,EAAE,KAAK,EAAC,GAAG,MAAM,MAAM,CAAC,cAAc,CAAC,CAAC;IACtD,OAAO,CAAC,kBAAQ,EAAE,KAAK,EAAE,aAAG,CAAC,CAAC;AAChC,CAAC;AAYD,SAAS,qBAAqB,CAC5B,iBAA4C;IAE5C,IAAI,iBAAiB,EAAE;QACrB,MAAM,MAAM,GACV,iBAAiB,KAAK,IAAI;YACxB,CAAC,CAAC,qBAAoB;YACtB,CAAC,CAAC,CAAC,qBAAoB,EAAE,iBAAiB,CAAC,CAAC;QAChD,OAAO,CAAC,MAAM,CAAC,CAAC;KACjB;IAED,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,iDAAiD;AACjD,KAAK,UAAU,sBAAsB;IACnC,MAAM,EAAC,eAAe,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,CAAC,GAAG,CAAC,KAAK,EAAE,kBAAkB,CAAC,CAAC;IAE/C,OAAO,kBAAkB,CAAC;AAC5B,CAAC;AAEM,KAAK,UAAU,qBAAqB,CAAC,EAC1C,QAAQ,EACR,cAAc,EACd,KAAK,EACL,UAAU,GAMX;IACC,MAAM,SAAS,GAAG,MAAM,0BAA0B,CAAC,EAAC,KAAK,EAAE,UAAU,EAAC,CAAC,CAAC;IAExE,MAAM,MAAM,GAAG,IAAA,kBAAS,EAAC;QACvB,QAAQ;QACR,iBAAiB,EAAE,cAAc,CAAC,MAAM;QACxC,oBAAoB,EAAE,UAAU,CAAC,cAAc,CAAC,MAAM;KACvD,CAAC,CAAC;IAEH,OAAO,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,YAAY,CAAC;AAC1E,CAAC;AApBD,sDAoBC"}

View File

@@ -0,0 +1,10 @@
type Plugin = any;
export type AdmonitionOptions = {
keywords: string[];
extendDefaults: boolean;
};
export declare const DefaultAdmonitionOptions: AdmonitionOptions;
export declare function normalizeAdmonitionOptions(providedOptions: Partial<AdmonitionOptions> | true): AdmonitionOptions;
declare const plugin: Plugin;
export default plugin;
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/remark/admonitions/index.ts"],"names":[],"mappings":"AAiBA,KAAK,MAAM,GAAG,GAAG,CAAC;AAElB,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,cAAc,EAAE,OAAO,CAAC;CACzB,CAAC;AAEF,eAAO,MAAM,wBAAwB,EAAE,iBAatC,CAAC;AAEF,wBAAgB,0BAA0B,CACxC,eAAe,EAAE,OAAO,CAAC,iBAAiB,CAAC,GAAG,IAAI,GACjD,iBAAiB,CAiBnB;AA6BD,QAAA,MAAM,MAAM,EAAE,MAuDb,CAAC;AAEF,eAAe,MAAM,CAAC"}

View File

@@ -0,0 +1,98 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.normalizeAdmonitionOptions = exports.DefaultAdmonitionOptions = void 0;
exports.DefaultAdmonitionOptions = {
keywords: [
'secondary',
'info',
'success',
'danger',
'note',
'tip',
'warning',
'important',
'caution',
],
extendDefaults: true,
};
function normalizeAdmonitionOptions(providedOptions) {
if (providedOptions === true) {
return exports.DefaultAdmonitionOptions;
}
const options = { ...exports.DefaultAdmonitionOptions, ...providedOptions };
// By default it makes more sense to append keywords to the default ones
// Adding custom keywords is more common than disabling existing ones
if (options.extendDefaults) {
options.keywords = [
...exports.DefaultAdmonitionOptions.keywords,
...options.keywords,
];
}
return options;
}
exports.normalizeAdmonitionOptions = normalizeAdmonitionOptions;
function parseDirective(directive) {
const hasDirectiveLabel =
// @ts-expect-error: fine
directive.children?.[0]?.data?.directiveLabel === true;
if (hasDirectiveLabel) {
const [directiveLabel, ...contentNodes] = directive.children;
return { directiveLabel: directiveLabel, contentNodes };
}
return { directiveLabel: undefined, contentNodes: directive.children };
}
function getTextOnlyTitle(directiveLabel) {
const isTextOnlyTitle = directiveLabel?.children?.length === 1 &&
directiveLabel?.children?.[0]?.type === 'text';
return isTextOnlyTitle
? // @ts-expect-error: todo type
directiveLabel?.children?.[0].value
: undefined;
}
const plugin = function plugin(optionsInput = {}) {
const { keywords } = normalizeAdmonitionOptions(optionsInput);
return async (root) => {
const { visit } = await import('unist-util-visit');
visit(root, (node) => {
if (node.type === 'containerDirective') {
const directive = node;
const isAdmonition = keywords.includes(directive.name);
if (!isAdmonition) {
return;
}
const { directiveLabel, contentNodes } = parseDirective(directive);
const textOnlyTitle = directive.attributes?.title ??
(directiveLabel ? getTextOnlyTitle(directiveLabel) : undefined);
// Transform the mdast directive node to a hast admonition node
// See https://github.com/syntax-tree/mdast-util-to-hast#fields-on-nodes
// TODO in MDX v2 we should transform the whole directive to
// mdxJsxFlowElement instead of using hast
directive.data = {
hName: 'admonition',
hProperties: {
...(textOnlyTitle && { title: textOnlyTitle }),
type: directive.name,
},
};
directive.children = contentNodes;
// TODO legacy MDX v1 <mdxAdmonitionTitle> workaround
// v1: not possible to inject complex JSX elements as props
// v2: now possible: use a mdxJsxFlowElement element
if (directiveLabel && !textOnlyTitle) {
const complexTitleNode = {
type: 'mdxAdmonitionTitle',
data: {
hName: 'mdxAdmonitionTitle',
hProperties: {},
},
children: directiveLabel.children,
};
// @ts-expect-error: invented node type
directive.children.unshift(complexTitleNode);
}
}
});
};
};
exports.default = plugin;
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/remark/admonitions/index.ts"],"names":[],"mappings":";;;AAwBa,QAAA,wBAAwB,GAAsB;IACzD,QAAQ,EAAE;QACR,WAAW;QACX,MAAM;QACN,SAAS;QACT,QAAQ;QACR,MAAM;QACN,KAAK;QACL,SAAS;QACT,WAAW;QACX,SAAS;KACV;IACD,cAAc,EAAE,IAAI;CACrB,CAAC;AAEF,SAAgB,0BAA0B,CACxC,eAAkD;IAElD,IAAI,eAAe,KAAK,IAAI,EAAE;QAC5B,OAAO,gCAAwB,CAAC;KACjC;IAED,MAAM,OAAO,GAAG,EAAC,GAAG,gCAAwB,EAAE,GAAG,eAAe,EAAC,CAAC;IAElE,wEAAwE;IACxE,qEAAqE;IACrE,IAAI,OAAO,CAAC,cAAc,EAAE;QAC1B,OAAO,CAAC,QAAQ,GAAG;YACjB,GAAG,gCAAwB,CAAC,QAAQ;YACpC,GAAG,OAAO,CAAC,QAAQ;SACpB,CAAC;KACH;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAnBD,gEAmBC;AAKD,SAAS,cAAc,CAAC,SAA6B;IAInD,MAAM,iBAAiB;IACrB,yBAAyB;IACzB,SAAS,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,cAAc,KAAK,IAAI,CAAC;IACzD,IAAI,iBAAiB,EAAE;QAC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AC3B,CAAC,cAAc,CAAC,CAAC,CAAC,gBAAgB,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;gBAElE,+DAA+D;gBAC/D,wEAAwE;gBACxE,4DAA4D;gBAC5D,0CAA0C;gBAC1C,SAAS,CAAC,IAAI,GAAG;oBACf,KAAK,EAAE,YAAY;oBACnB,WAAW,EAAE;wBACX,GAAG,CAAC,aAAa,IAAI,EAAC,KAAK,EAAE,aAAa,EAAC,CAAC;wBAC5C,IAAI,EAAE,SAAS,CAAC,IAAI;qBACrB;iBACF,CAAC;gBACF,SAAS,CAAC,QAAQ,GAAG,YAAY,CAAC;gBAElC,qDAAqD;gBACrD,2DAA2D;gBAC3D,oDAAoD;gBACpD,IAAI,cAAc,IAAI,CAAC,aAAa,EAAE;oBACpC,MAAM,gBAAgB,GAAG;wBACvB,IAAI,EAAE,oBAAoB;wBAC1B,IAAI,EAAE;4BACJ,KAAK,EAAE,oBAAoB;4BAC3B,WAAW,EAAE,EAAE;yBAChB;wBACD,QAAQ,EAAE,cAAc,CAAC,QAAQ;qBAClC,CAAC;oBACF,uCAAuC;oBACvC,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;iBAC9C;aACF;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,MAAM,CAAC"}

View File

@@ -0,0 +1,15 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
type Plugin = any;
/**
* A remark plugin to extract the h1 heading found in Markdown files
* This is exposed as "data.contentTitle" to the processed vfile
* Also gives the ability to strip that content title (used for the blog plugin)
*/
declare const plugin: Plugin;
export default plugin;
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/remark/contentTitle/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAUH,KAAK,MAAM,GAAG,GAAG,CAAC;AAMlB;;;;GAIG;AACH,QAAA,MAAM,MAAM,EAAE,MA0Bb,CAAC;AAEF,eAAe,MAAM,CAAC"}

View File

@@ -0,0 +1,38 @@
"use strict";
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
Object.defineProperty(exports, "__esModule", { value: true });
/**
* A remark plugin to extract the h1 heading found in Markdown files
* This is exposed as "data.contentTitle" to the processed vfile
* Also gives the ability to strip that content title (used for the blog plugin)
*/
const plugin = function plugin(options = {}) {
// content title is
const removeContentTitle = options.removeContentTitle ?? false;
return async (root, vfile) => {
const { toString } = await import('mdast-util-to-string');
const { visit, EXIT } = await import('unist-util-visit');
visit(root, 'heading', (headingNode, index, parent) => {
if (headingNode.depth === 1) {
vfile.data.contentTitle = toString(headingNode);
if (removeContentTitle) {
// @ts-expect-error: TODO how to fix?
parent.children.splice(index, 1);
}
return EXIT; // We only handle the very first heading
}
// We only handle contentTitle if it's the very first heading found
if (headingNode.depth >= 1) {
return EXIT;
}
return undefined;
});
};
};
exports.default = plugin;
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/remark/contentTitle/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAgBH;;;;GAIG;AACH,MAAM,MAAM,GAAW,SAAS,MAAM,CACpC,UAAyB,EAAE;IAE3B,mBAAmB;IACnB,MAAM,kBAAkB,GAAG,OAAO,CAAC,kBAAkB,IAAI,KAAK,CAAC;IAE/D,OAAO,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE;QAC3B,MAAM,EAAC,QAAQ,EAAC,GAAG,MAAM,MAAM,CAAC,sBAAsB,CAAC,CAAC;QACxD,MAAM,EAAC,KAAK,EAAE,IAAI,EAAC,GAAG,MAAM,MAAM,CAAC,kBAAkB,CAAC,CAAC;QAEvD,KAAK,CAAC,IAAI,EAAE,SAAS,EAAE,CAAC,WAAoB,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;YAC7D,IAAI,WAAW,CAAC,KAAK,KAAK,CAAC,EAAE;gBAC3B,KAAK,CAAC,IAAI,CAAC,YAAY,GAAG,QAAQ,CAAC,WAAW,CAAC,CAAC;gBAChD,IAAI,kBAAkB,EAAE;oBACtB,qCAAqC;oBACrC,MAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;iBACnC;gBACD,OAAO,IAAI,CAAC,CAAC,wCAAwC;aACtD;YACD,mEAAmE;YACnE,IAAI,WAAW,CAAC,KAAK,IAAI,CAAC,EAAE;gBAC1B,OAAO,IAAI,CAAC;aACb;YACD,OAAO,SAAS,CAAC;QACnB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,MAAM,CAAC"}

View File

@@ -0,0 +1,9 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import type { Transformer } from 'unified';
export default function plugin(): Transformer;
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/remark/details/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,SAAS,CAAC;AAOzC,MAAM,CAAC,OAAO,UAAU,MAAM,IAAI,WAAW,CAS5C"}

View File

@@ -0,0 +1,22 @@
"use strict";
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
Object.defineProperty(exports, "__esModule", { value: true });
// Transform <details> to <Details>
// MDX 2 doesn't allow to substitute html elements with the provider anymore
function plugin() {
return async (root) => {
const { visit } = await import('unist-util-visit');
visit(root, 'mdxJsxFlowElement', (node) => {
if (node.name === 'details') {
node.name = 'Details';
}
});
};
}
exports.default = plugin;
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/remark/details/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAQH,mCAAmC;AACnC,4EAA4E;AAC5E,SAAwB,MAAM;IAC5B,OAAO,KAAK,EAAE,IAAI,EAAE,EAAE;QACpB,MAAM,EAAC,KAAK,EAAC,GAAG,MAAM,MAAM,CAAC,kBAAkB,CAAC,CAAC;QACjD,KAAK,CAAC,IAAI,EAAE,mBAAmB,EAAE,CAAC,IAAuB,EAAE,EAAE;YAC3D,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,EAAE;gBAC3B,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC;aACvB;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AATD,yBASC"}

View File

@@ -0,0 +1,9 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import type { Transformer } from 'unified';
export default function plugin(): Transformer;
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/remark/head/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,SAAS,CAAC;AAOzC,MAAM,CAAC,OAAO,UAAU,MAAM,IAAI,WAAW,CAS5C"}

View File

@@ -0,0 +1,22 @@
"use strict";
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
Object.defineProperty(exports, "__esModule", { value: true });
// Transform <head> to <Head>
// MDX 2 doesn't allow to substitute html elements with the provider anymore
function plugin() {
return async (root) => {
const { visit } = await import('unist-util-visit');
visit(root, 'mdxJsxFlowElement', (node) => {
if (node.name === 'head') {
node.name = 'Head';
}
});
};
}
exports.default = plugin;
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/remark/head/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAQH,6BAA6B;AAC7B,4EAA4E;AAC5E,SAAwB,MAAM;IAC5B,OAAO,KAAK,EAAE,IAAI,EAAE,EAAE;QACpB,MAAM,EAAC,KAAK,EAAC,GAAG,MAAM,MAAM,CAAC,kBAAkB,CAAC,CAAC;QACjD,KAAK,CAAC,IAAI,EAAE,mBAAmB,EAAE,CAAC,IAAuB,EAAE,EAAE;YAC3D,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,EAAE;gBACxB,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC;aACpB;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AATD,yBASC"}

View File

@@ -0,0 +1,9 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import type { Transformer } from 'unified';
export default function plugin(): Transformer;
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/remark/headings/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,SAAS,CAAC;AAGzC,MAAM,CAAC,OAAO,UAAU,MAAM,IAAI,WAAW,CAyD5C"}

View File

@@ -0,0 +1,57 @@
"use strict";
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
Object.defineProperty(exports, "__esModule", { value: true });
/* Based on remark-slug (https://github.com/remarkjs/remark-slug) and gatsby-remark-autolink-headers (https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-remark-autolink-headers) */
const utils_1 = require("@docusaurus/utils");
function plugin() {
return async (root) => {
const { toString } = await import('mdast-util-to-string');
const { visit } = await import('unist-util-visit');
const slugs = (0, utils_1.createSlugger)();
visit(root, 'heading', (headingNode) => {
const data = headingNode.data ?? (headingNode.data = {});
const properties = (data.hProperties || (data.hProperties = {}));
let { id } = properties;
if (id) {
id = slugs.slug(id, { maintainCase: true });
}
else {
const headingTextNodes = headingNode.children.filter(({ type }) => !['html', 'jsx'].includes(type));
const heading = toString(headingTextNodes.length > 0 ? headingTextNodes : headingNode);
// Support explicit heading IDs
const parsedHeading = (0, utils_1.parseMarkdownHeadingId)(heading);
id = parsedHeading.id ?? slugs.slug(heading);
if (parsedHeading.id) {
// When there's an id, it is always in the last child node
// Sometimes heading is in multiple "parts" (** syntax creates a child
// node):
// ## part1 *part2* part3 {#id}
const lastNode = headingNode.children[headingNode.children.length - 1];
if (headingNode.children.length > 1) {
const lastNodeText = (0, utils_1.parseMarkdownHeadingId)(lastNode.value).text;
// When last part contains test+id, remove the id
if (lastNodeText) {
lastNode.value = lastNodeText;
}
// When last part contains only the id: completely remove that node
else {
headingNode.children.pop();
}
}
else {
lastNode.value = parsedHeading.text;
}
}
}
data.id = id;
properties.id = id;
});
};
}
exports.default = plugin;
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/remark/headings/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAEH,gMAAgM;AAEhM,6CAAwE;AAKxE,SAAwB,MAAM;IAC5B,OAAO,KAAK,EAAE,IAAI,EAAE,EAAE;QACpB,MAAM,EAAC,QAAQ,EAAC,GAAG,MAAM,MAAM,CAAC,sBAAsB,CAAC,CAAC;QACxD,MAAM,EAAC,KAAK,EAAC,GAAG,MAAM,MAAM,CAAC,kBAAkB,CAAC,CAAC;QAEjD,MAAM,KAAK,GAAG,IAAA,qBAAa,GAAE,CAAC;QAC9B,KAAK,CAAC,IAAI,EAAE,SAAS,EAAE,CAAC,WAAoB,EAAE,EAAE;YAC9C,M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E,iDAAiD;wBACjD,IAAI,YAAY,EAAE;4BAChB,QAAQ,CAAC,KAAK,GAAG,YAAY,CAAC;yBAC/B;wBACD,mEAAmE;6BAC9D;4BACH,WAAW,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC;yBAC5B;qBACF;yBAAM;wBACL,QAAQ,CAAC,KAAK,GAAG,aAAa,CAAC,IAAI,CAAC;qBACrC;iBACF;aACF;YAED,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;YACb,UAAU,CAAC,EAAE,GAAG,EAAE,CAAC;QACrB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAzDD,yBAyDC"}

View File

@@ -0,0 +1,9 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import type { Transformer, Processor } from 'unified';
export default function codeCompatPlugin(this: Processor): Transformer;
//# sourceMappingURL=codeCompatPlugin.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"codeCompatPlugin.d.ts","sourceRoot":"","sources":["../../../src/remark/mdx1Compat/codeCompatPlugin.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAC,WAAW,EAAE,SAAS,EAAC,MAAM,SAAS,CAAC;AAUpD,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,IAAI,EAAE,SAAS,GAAG,WAAW,CAerE"}

View File

@@ -0,0 +1,29 @@
"use strict";
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
Object.defineProperty(exports, "__esModule", { value: true });
// Solution inspired by https://github.com/pomber/docusaurus-mdx-2/blob/main/packages/mdx-loader/src/remark/codeCompat/index.ts
// TODO after MDX 2 we probably don't need this - remove soon?
// Only fenced code blocks are swapped by pre/code MDX components
// Using <pre><code> in JSX shouldn't use our MDX components anymore
// To make theme-classic/src/theme/MDXComponents/Pre work
// we need to fill two properties that mdx v2 doesn't provide anymore
function codeCompatPlugin() {
return async (root) => {
const { visit } = await import('unist-util-visit');
visit(root, 'code', (node) => {
node.data = node.data || {};
node.data.hProperties = node.data.hProperties || {};
node.data.hProperties.metastring = node.meta;
// Retrocompatible support for live codeblock metastring
// Not really the appropriate place to handle that :s
node.data.hProperties.live = node.meta?.split(' ').includes('live');
});
};
}
exports.default = codeCompatPlugin;
//# sourceMappingURL=codeCompatPlugin.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"codeCompatPlugin.js","sourceRoot":"","sources":["../../../src/remark/mdx1Compat/codeCompatPlugin.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAMH,+HAA+H;AAC/H,8DAA8D;AAC9D,iEAAiE;AACjE,oEAAoE;AAEpE,yDAAyD;AACzD,qEAAqE;AACrE,SAAwB,gBAAgB;IACtC,OAAO,KAAK,EAAE,IAAI,EAAE,EAAE;QACpB,MAAM,EAAC,KAAK,EAAC,GAAG,MAAM,MAAM,CAAC,kBAAkB,CAAC,CAAC;QAEjD,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,IAAU,EAAE,EAAE;YACjC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,IAAI,EAAE,CAAC;YAE5B,IAAI,CAAC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,IAAI,EAAE,CAAC;YACpD,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC;YAE7C,wDAAwD;YACxD,qDAAqD;YACrD,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QACtE,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAfD,mCAeC"}

View File

@@ -0,0 +1,9 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import type { Transformer } from 'unified';
export default function plugin(): Transformer;
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/remark/mermaid/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,SAAS,CAAC;AAOzC,MAAM,CAAC,OAAO,UAAU,MAAM,IAAI,WAAW,CAmB5C"}

View File

@@ -0,0 +1,34 @@
"use strict";
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
Object.defineProperty(exports, "__esModule", { value: true });
const utils_1 = require("../utils");
// TODO: this plugin shouldn't be in the core MDX loader
// After we allow plugins to provide Remark/Rehype plugins (see
// https://github.com/facebook/docusaurus/issues/6370), this should be provided
// by theme-mermaid itself
function plugin() {
return async (root) => {
const { visit } = await import('unist-util-visit');
visit(root, 'code', (node) => {
if (node.lang === 'mermaid') {
// TODO migrate to mdxJsxFlowElement? cf admonitions
(0, utils_1.transformNode)(node, {
type: 'mermaidCodeBlock',
data: {
hName: 'mermaid',
hProperties: {
value: node.value,
},
},
});
}
});
};
}
exports.default = plugin;
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/remark/mermaid/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAEH,oCAAuC;AAMvC,wDAAwD;AACxD,+DAA+D;AAC/D,+EAA+E;AAC/E,0BAA0B;AAC1B,SAAwB,MAAM;IAC5B,OAAO,KAAK,EAAE,IAAI,EAAE,EAAE;QACpB,MAAM,EAAC,KAAK,EAAC,GAAG,MAAM,MAAM,CAAC,kBAAkB,CAAC,CAAC;QAEjD,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,IAAU,EAAE,EAAE;YACjC,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,EAAE;gBAC3B,oDAAoD;gBACpD,IAAA,qBAAa,EAAC,IAAI,EAAE;oBAClB,IAAI,EAAE,kBAAkB;oBACxB,IAAI,EAAE;wBACJ,KAAK,EAAE,SAAS;wBAChB,WAAW,EAAE;4BACX,KAAK,EAAE,IAAI,CAAC,KAAK;yBAClB;qBACF;iBACF,CAAC,CAAC;aACJ;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAnBD,yBAmBC"}

View File

@@ -0,0 +1,15 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
type Plugin = any;
export type TOCItem = {
readonly value: string;
readonly id: string;
readonly level: number;
};
declare const plugin: Plugin;
export default plugin;
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/remark/toc/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAoBH,KAAK,MAAM,GAAG,GAAG,CAAC;AAElB,MAAM,MAAM,OAAO,GAAG;IACpB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB,CAAC;AAuDF,QAAA,MAAM,MAAM,EAAE,MAiCb,CAAC;AAEF,eAAe,MAAM,CAAC"}

View File

@@ -0,0 +1,111 @@
"use strict";
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const parser_1 = require("@babel/parser");
const traverse_1 = tslib_1.__importDefault(require("@babel/traverse"));
const stringify_object_1 = tslib_1.__importDefault(require("stringify-object"));
const utils_1 = require("../utils");
const parseOptions = {
plugins: ['jsx'],
sourceType: 'module',
};
const isImport = (child) => child.type === 'mdxjsEsm' && child.value.startsWith('import');
const hasImports = (index) => index > -1;
const isExport = (child) => child.type === 'mdxjsEsm' && child.value.startsWith('export');
const isTarget = (child, name) => {
let found = false;
const ast = (0, parser_1.parse)(child.value, parseOptions);
(0, traverse_1.default)(ast, {
VariableDeclarator: (path) => {
if (path.node.id.name === name) {
found = true;
}
},
});
return found;
};
const getOrCreateExistingTargetIndex = async (children, name) => {
let importsIndex = -1;
let targetIndex = -1;
children.forEach((child, index) => {
if (isImport(child)) {
importsIndex = index;
}
else if (isExport(child) && isTarget(child, name)) {
targetIndex = index;
}
});
if (targetIndex === -1) {
const target = await createExportNode(name, []);
targetIndex = hasImports(importsIndex) ? importsIndex + 1 : 0;
children.splice(targetIndex, 0, target);
}
return targetIndex;
};
const plugin = function plugin(options = {}) {
const name = options.name || 'toc';
return async (root) => {
const { toString } = await import('mdast-util-to-string');
const { visit } = await import('unist-util-visit');
const headings = [];
visit(root, 'heading', (child) => {
const value = toString(child);
// depth:1 headings are titles and not included in the TOC
if (!value || child.depth < 2) {
return;
}
headings.push({
value: (0, utils_1.toValue)(child, toString),
id: child.data.id,
level: child.depth,
});
});
const { children } = root;
const targetIndex = await getOrCreateExistingTargetIndex(children, name);
if (headings?.length) {
children[targetIndex] = await createExportNode(name, headings);
}
};
};
exports.default = plugin;
async function createExportNode(name, object) {
const { valueToEstree } = await import('estree-util-value-to-estree');
return {
type: 'mdxjsEsm',
value: `export const ${name} = ${(0, stringify_object_1.default)(object)}`,
data: {
estree: {
type: 'Program',
body: [
{
type: 'ExportNamedDeclaration',
declaration: {
type: 'VariableDeclaration',
declarations: [
{
type: 'VariableDeclarator',
id: {
type: 'Identifier',
name,
},
init: valueToEstree(object),
},
],
kind: 'const',
},
specifiers: [],
source: null,
},
],
sourceType: 'module',
},
},
};
}
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/rem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right (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import type { Transformer } from 'unified';
type PluginOptions = {
staticDirs: string[];
siteDir: string;
};
export default function plugin(options: PluginOptions): Transformer;
export {};
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/remark/transformImage/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAkBH,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,SAAS,CAAC;AAUzC,KAAK,aAAa,GAAG;IACnB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AA2JF,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,OAAO,EAAE,aAAa,GAAG,WAAW,CAelE"}

View File

@@ -0,0 +1,142 @@
"use strict";
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const path_1 = tslib_1.__importDefault(require("path"));
const url_1 = tslib_1.__importDefault(require("url"));
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
const util_1 = require("util");
const utils_1 = require("@docusaurus/utils");
const escape_html_1 = tslib_1.__importDefault(require("escape-html"));
const image_size_1 = tslib_1.__importDefault(require("image-size"));
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
const utils_2 = require("../utils");
const { loaders: { inlineMarkdownImageFileLoader }, } = (0, utils_1.getFileLoaderUtils)();
async function toImageRequireNode([node], imagePath, filePath) {
// MdxJsxTextElement => see https://github.com/facebook/docusaurus/pull/8288#discussion_r1125871405
const jsxNode = node;
const attributes = [];
let relativeImagePath = (0, utils_1.posixPath)(path_1.default.relative(path_1.default.dirname(filePath), imagePath));
relativeImagePath = `./${relativeImagePath}`;
const parsedUrl = url_1.default.parse(node.url);
const hash = parsedUrl.hash ?? '';
const search = parsedUrl.search ?? '';
const requireString = `${inlineMarkdownImageFileLoader}${(0, utils_1.escapePath)(relativeImagePath) + search}`;
if (node.alt) {
attributes.push({
type: 'mdxJsxAttribute',
name: 'alt',
value: (0, escape_html_1.default)(node.alt),
});
}
attributes.push({
type: 'mdxJsxAttribute',
name: 'src',
value: (0, utils_2.assetRequireAttributeValue)(requireString, hash),
});
if (node.title) {
attributes.push({
type: 'mdxJsxAttribute',
name: 'title',
value: (0, escape_html_1.default)(node.title),
});
}
try {
const size = (await (0, util_1.promisify)(image_size_1.default)(imagePath));
if (size.width) {
attributes.push({
type: 'mdxJsxAttribute',
name: 'width',
value: String(size.width),
});
}
if (size.height) {
attributes.push({
type: 'mdxJsxAttribute',
name: 'height',
value: String(size.height),
});
}
}
catch (err) {
// Workaround for https://github.com/yarnpkg/berry/pull/3889#issuecomment-1034469784
// TODO remove this check once fixed in Yarn PnP
if (!process.versions.pnp) {
logger_1.default.warn `The image at path=${imagePath} can't be read correctly. Please ensure it's a valid image.
${err.message}`;
}
}
(0, utils_2.transformNode)(jsxNode, {
type: 'mdxJsxTextElement',
name: 'img',
attributes,
children: [],
});
}
async function ensureImageFileExist(imagePath, sourceFilePath) {
const imageExists = await fs_extra_1.default.pathExists(imagePath);
if (!imageExists) {
throw new Error(`Image ${(0, utils_1.toMessageRelativeFilePath)(imagePath)} used in ${(0, utils_1.toMessageRelativeFilePath)(sourceFilePath)} not found.`);
}
}
async function getImageAbsolutePath(imagePath, { siteDir, filePath, staticDirs }) {
if (imagePath.startsWith('@site/')) {
const imageFilePath = path_1.default.join(siteDir, imagePath.replace('@site/', ''));
await ensureImageFileExist(imageFilePath, filePath);
return imageFilePath;
}
else if (path_1.default.isAbsolute(imagePath)) {
// Absolute paths are expected to exist in the static folder.
const possiblePaths = staticDirs.map((dir) => path_1.default.join(dir, imagePath));
const imageFilePath = await (0, utils_1.findAsyncSequential)(possiblePaths, fs_extra_1.default.pathExists);
if (!imageFilePath) {
throw new Error(`Image ${possiblePaths
.map((p) => (0, utils_1.toMessageRelativeFilePath)(p))
.join(' or ')} used in ${(0, utils_1.toMessageRelativeFilePath)(filePath)} not found.`);
}
return imageFilePath;
}
// relative paths are resolved against the source file's folder
const imageFilePath = path_1.default.join(path_1.default.dirname(filePath), decodeURIComponent(imagePath));
await ensureImageFileExist(imageFilePath, filePath);
return imageFilePath;
}
async function processImageNode(target, context) {
const [node] = target;
if (!node.url) {
throw new Error(`Markdown image URL is mandatory in "${(0, utils_1.toMessageRelativeFilePath)(context.filePath)}" file`);
}
const parsedUrl = url_1.default.parse(node.url);
if (parsedUrl.protocol || !parsedUrl.pathname) {
// pathname:// is an escape hatch, in case user does not want her images to
// be converted to require calls going through webpack loader
if (parsedUrl.protocol === 'pathname:') {
node.url = node.url.replace('pathname://', '');
}
return;
}
// We try to convert image urls without protocol to images with require calls
// going through webpack ensures that image assets exist at build time
const imagePath = await getImageAbsolutePath(parsedUrl.pathname, context);
await toImageRequireNode(target, imagePath, context.filePath);
}
function plugin(options) {
return async (root, vfile) => {
const { visit } = await import('unist-util-visit');
const promises = [];
visit(root, 'image', (node, index, parent) => {
promises.push(processImageNode([node, index, parent], {
...options,
filePath: vfile.path,
}));
});
await Promise.all(promises);
};
}
exports.default = plugin;
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/remark/transformImage/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,wDAAwB;AACxB,sDAAsB;AACtB,gEAA0B;AAC1B,+BAA+B;AAC/B,6CAM2B;AAC3B,sEAAqC;AACrC,oEAAgC;AAChC,wEAAwC;AACxC,oCAAmE;AAQnE,MAAM,EACJ,OAAO,EAAE,EAAC,6BAA6B,EAAC,GACzC,GAAG,IAAA,0BAAkB,GAAE,CAAC;AAazB,KAAK,UAAU,kBAAkB,CAC/B,CAAC,IAAI,CAAS,EACd,SAAiB,EACjB,QAAgB;IAE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
* LICENSE file in the root directory of this source tree.
*/
import type { Transformer } from 'unified';
type PluginOptions = {
staticDirs: string[];
siteDir: string;
};
export default function plugin(options: PluginOptions): Transformer;
export {};
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/remark/transformLinks/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAeH,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,SAAS,CAAC;AAUzC,KAAK,aAAa,GAAG;IACnB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAyKF,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,OAAO,EAAE,aAAa,GAAG,WAAW,CAelE"}

View File

@@ -0,0 +1,153 @@
"use strict";
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const path_1 = tslib_1.__importDefault(require("path"));
const url_1 = tslib_1.__importDefault(require("url"));
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
const utils_1 = require("@docusaurus/utils");
const escape_html_1 = tslib_1.__importDefault(require("escape-html"));
const utils_2 = require("../utils");
const { loaders: { inlineMarkdownLinkFileLoader }, } = (0, utils_1.getFileLoaderUtils)();
/**
* Transforms the link node to a JSX `<a>` element with a `require()` call.
*/
async function toAssetRequireNode([node], assetPath, filePath) {
// MdxJsxTextElement => see https://github.com/facebook/docusaurus/pull/8288#discussion_r1125871405
const jsxNode = node;
const attributes = [];
// require("assets/file.pdf") means requiring from a package called assets
const relativeAssetPath = `./${(0, utils_1.posixPath)(path_1.default.relative(path_1.default.dirname(filePath), assetPath))}`;
const parsedUrl = url_1.default.parse(node.url);
const hash = parsedUrl.hash ?? '';
const search = parsedUrl.search ?? '';
const requireString = `${
// A hack to stop Webpack from using its built-in loader to parse JSON
path_1.default.extname(relativeAssetPath) === '.json'
? `${relativeAssetPath.replace('.json', '.raw')}!=`
: ''}${inlineMarkdownLinkFileLoader}${(0, utils_1.escapePath)(relativeAssetPath) + search}`;
attributes.push({
type: 'mdxJsxAttribute',
name: 'target',
value: '_blank',
});
// Assets are not routes, and are required by Webpack already
// They should not trigger the broken link checker
attributes.push({
type: 'mdxJsxAttribute',
name: 'data-noBrokenLinkCheck',
value: {
type: 'mdxJsxAttributeValueExpression',
value: 'true',
data: {
estree: {
type: 'Program',
body: [
{
type: 'ExpressionStatement',
expression: {
type: 'Literal',
value: true,
raw: 'true',
},
},
],
sourceType: 'module',
comments: [],
},
},
},
});
attributes.push({
type: 'mdxJsxAttribute',
name: 'href',
value: (0, utils_2.assetRequireAttributeValue)(requireString, hash),
});
if (node.title) {
attributes.push({
type: 'mdxJsxAttribute',
name: 'title',
value: (0, escape_html_1.default)(node.title),
});
}
const { children } = node;
(0, utils_2.transformNode)(jsxNode, {
type: 'mdxJsxTextElement',
name: 'a',
attributes,
children,
});
}
async function ensureAssetFileExist(assetPath, sourceFilePath) {
const assetExists = await fs_extra_1.default.pathExists(assetPath);
if (!assetExists) {
throw new Error(`Asset ${(0, utils_1.toMessageRelativeFilePath)(assetPath)} used in ${(0, utils_1.toMessageRelativeFilePath)(sourceFilePath)} not found.`);
}
}
async function getAssetAbsolutePath(assetPath, { siteDir, filePath, staticDirs }) {
if (assetPath.startsWith('@site/')) {
const assetFilePath = path_1.default.join(siteDir, assetPath.replace('@site/', ''));
// The @site alias is the only way to believe that the user wants an asset.
// Everything else can just be a link URL
await ensureAssetFileExist(assetFilePath, filePath);
return assetFilePath;
}
else if (path_1.default.isAbsolute(assetPath)) {
const assetFilePath = await (0, utils_1.findAsyncSequential)(staticDirs.map((dir) => path_1.default.join(dir, assetPath)), fs_extra_1.default.pathExists);
if (assetFilePath) {
return assetFilePath;
}
}
else {
const assetFilePath = path_1.default.join(path_1.default.dirname(filePath), assetPath);
if (await fs_extra_1.default.pathExists(assetFilePath)) {
return assetFilePath;
}
}
return null;
}
async function processLinkNode(target, context) {
const [node] = target;
if (!node.url) {
// Try to improve error feedback
// see https://github.com/facebook/docusaurus/issues/3309#issuecomment-690371675
const title = node.title ?? node.children[0]?.value ?? '?';
const line = node.position?.start.line ?? '?';
throw new Error(`Markdown link URL is mandatory in "${(0, utils_1.toMessageRelativeFilePath)(context.filePath)}" file (title: ${title}, line: ${line}).`);
}
const parsedUrl = url_1.default.parse(node.url);
if (parsedUrl.protocol || !parsedUrl.pathname) {
// Don't process pathname:// here, it's used by the <Link> component
return;
}
const hasSiteAlias = parsedUrl.pathname.startsWith('@site/');
const hasAssetLikeExtension = path_1.default.extname(parsedUrl.pathname) &&
!parsedUrl.pathname.match(/\.(?:mdx?|html)(?:#|$)/);
if (!hasSiteAlias && !hasAssetLikeExtension) {
return;
}
const assetPath = await getAssetAbsolutePath(decodeURIComponent(parsedUrl.pathname), context);
if (assetPath) {
await toAssetRequireNode(target, assetPath, context.filePath);
}
}
function plugin(options) {
return async (root, vfile) => {
const { visit } = await import('unist-util-visit');
const promises = [];
visit(root, 'link', (node, index, parent) => {
promises.push(processLinkNode([node, index, parent], {
...options,
filePath: vfile.path,
}));
});
await Promise.all(promises);
};
}
exports.default = plugin;
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/remark/transformLinks/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,wDAAwB;AACxB,sDAAsB;AACtB,gEAA0B;AAC1B,6CAM2B;AAC3B,sEAAqC;AACrC,oCAAmE;AAQnE,MAAM,EACJ,OAAO,EAAE,EAAC,4BAA4B,EAAC,GACxC,GAAG,IAAA,0BAAkB,GAAE,CAAC;AAazB;;GAEG;AACH,KAAK,UAAU,kBAAkB,CAC/B,CAAC,IAAI,CAAS,EACd,SAAiB,EACjB,QAAgB;IAEhB,mGAAmG;IACnG,MAAM,OAAO,GAAG,IAAoC,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ugin;
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/remark/unusedDirectives/index.ts"],"names":[],"mappings":"AAwBA,KAAK,MAAM,GAAG,GAAG,CAAC;AA4GlB,QAAA,MAAM,MAAM,EAAE,MAgCb,CAAC;AAEF,eAAe,MAAM,CAAC"}

View File

@@ -0,0 +1,117 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const path_1 = tslib_1.__importDefault(require("path"));
const process_1 = tslib_1.__importDefault(require("process"));
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
const utils_1 = require("@docusaurus/utils");
const utils_2 = require("../utils");
const directiveTypes = [
'containerDirective',
'leafDirective',
'textDirective',
];
const directivePrefixMap = {
textDirective: ':',
leafDirective: '::',
containerDirective: ':::',
};
function formatDirectiveName(directive) {
const prefix = directivePrefixMap[directive.type];
if (!prefix) {
throw new Error(`unexpected, no prefix found for directive of type ${directive.type}`);
}
// To simplify we don't display the eventual label/props of directives
return `${prefix}${directive.name}`;
}
function formatDirectivePosition(directive) {
return directive.position?.start
? logger_1.default.interpolate `number=${directive.position.start.line}:number=${directive.position.start.column}`
: undefined;
}
function formatUnusedDirectiveMessage(directive) {
const name = formatDirectiveName(directive);
const position = formatDirectivePosition(directive);
return `- ${name} ${position ? `(${position})` : ''}`;
}
function formatUnusedDirectivesMessage({ directives, filePath, }) {
const supportUrl = 'https://github.com/facebook/docusaurus/pull/9394';
const customPath = (0, utils_1.posixPath)(path_1.default.relative(process_1.default.cwd(), filePath));
const warningTitle = logger_1.default.interpolate `Docusaurus found ${directives.length} unused Markdown directives in file path=${customPath}`;
const customSupportUrl = logger_1.default.interpolate `url=${supportUrl}`;
const warningMessages = directives
.map(formatUnusedDirectiveMessage)
.join('\n');
return `${warningTitle}
${warningMessages}
Your content might render in an unexpected way. Visit ${customSupportUrl} to find out why and how to fix it.`;
}
function logUnusedDirectivesWarning({ directives, filePath, }) {
if (directives.length > 0) {
const message = formatUnusedDirectivesMessage({
directives,
filePath,
});
logger_1.default.warn(message);
}
}
function isTextDirective(directive) {
return directive.type === 'textDirective';
}
// A simple text directive is one without any label/props
function isSimpleTextDirective(directive) {
if (isTextDirective(directive)) {
// Attributes in MDAST = Directive props
const hasAttributes = directive.attributes && Object.keys(directive.attributes).length > 0;
// Children in MDAST = Directive label
const hasChildren = directive.children.length > 0;
return !hasAttributes && !hasChildren;
}
return false;
}
function transformSimpleTextDirectiveToString(textDirective) {
(0, utils_2.transformNode)(textDirective, {
type: 'text',
value: `:${textDirective.name}`, // We ignore label/props on purpose here
});
}
function isUnusedDirective(directive) {
// If directive data is set (notably hName/hProperties set by admonitions)
// this usually means the directive has been handled by another plugin
return !directive.data;
}
const plugin = function plugin() {
return async (tree, file) => {
const { visit } = await import('unist-util-visit');
const unusedDirectives = [];
visit(tree, directiveTypes, (directive) => {
// If directive data is set (hName/hProperties set by admonitions)
// this usually means the directive has been handled by another plugin
if (isUnusedDirective(directive)) {
if (isSimpleTextDirective(directive)) {
transformSimpleTextDirectiveToString(directive);
}
else {
unusedDirectives.push(directive);
}
}
});
// We only enable these warnings for the client compiler
// This avoids emitting duplicate warnings in prod mode
// Note: the client compiler is used in both dev/prod modes
if (file.data.compilerName === 'client') {
logUnusedDirectivesWarning({
directives: unusedDirectives,
filePath: file.path,
});
}
};
};
exports.default = plugin;
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/remark/unusedDirectives/index.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACH,wDAAwB;AACxB,8DAA8B;AAC9B,wEAAwC;AACxC,6CAA4C;AAC5C,oCAAuC;AAkBvC,MAAM,cAAc,GAAoB;IACtC,oBAAoB;IACpB,eAAe;IACf,eAAe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;AACL,CAAC;AAED,SAAS,iBAAiB,CAAC,SAAqB;IAC9C,0EAA0E;IAC1E,sEAAsE;IACtE,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC;AACzB,CAAC;AAED,MAAM,MAAM,GAAW,SAAS,MAAM;IACpC,OAAO,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE;QAC1B,MAAM,EAAC,KAAK,EAAC,GAAG,MAAM,MAAM,CAAC,kBAAkB,CAAC,CAAC;QAEjD,MAAM,gBAAgB,GAAiB,EAAE,CAAC;QAE1C,KAAK,CACH,IAAI,EACJ,cAAc,EACd,CAAC,SAAqB,EAAE,EAAE;YACxB,kEAAkE;YAClE,sEAAsE;YACtE,IAAI,iBAAiB,CAAC,SAAS,CAAC,EAAE;gBAChC,IAAI,qBAAqB,CAAC,SAAS,CAAC,EAAE;oBACpC,oCAAoC,CAAC,SAAS,CAAC,CAAC;iBACjD;qBAAM;oBACL,gBAAgB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;iBAClC;aACF;QACH,CAAC,CACF,CAAC;QAEF,wDAAwD;QACxD,uDAAuD;QACvD,2DAA2D;QAC3D,IAAI,IAAI,CAAC,IAAI,CAAC,YAAY,KAAK,QAAQ,EAAE;YACvC,0BAA0B,CAAC;gBACzB,UAAU,EAAE,gBAAgB;gBAC5B,QAAQ,EAAE,IAAI,CAAC,IAAI;aACpB,CAAC,CAAC;SACJ;IACH,CAAC,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,MAAM,CAAC"}

View File

@@ -0,0 +1,20 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import type { Parent, Node } from 'unist';
import type { PhrasingContent, Heading } from 'mdast';
import type { MdxJsxAttributeValueExpression, MdxJsxTextElement } from 'mdast-util-mdx';
/**
* Util to transform one node type to another node type
* The input node is mutated in place
* @param node the node to mutate
* @param newNode what the original node should become become
*/
export declare function transformNode<NewNode extends Node>(node: Node, newNode: NewNode): NewNode;
export declare function stringifyContent(node: Parent, toString: (param: unknown) => string): string;
export declare function toValue(node: PhrasingContent | Heading | MdxJsxTextElement, toString: (param: unknown) => string): string;
export declare function assetRequireAttributeValue(requireString: string, hash: string): MdxJsxAttributeValueExpression;
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/remark/utils/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAC,MAAM,EAAE,IAAI,EAAC,MAAM,OAAO,CAAC;AACxC,OAAO,KAAK,EAAC,eAAe,EAAE,OAAO,EAAC,MAAM,OAAO,CAAC;AACpD,OAAO,KAAK,EAEV,8BAA8B,EAC9B,iBAAiB,EAElB,MAAM,gBAAgB,CAAC;AAExB;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,OAAO,SAAS,IAAI,EAChD,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,OAAO,GACf,OAAO,CAUT;AAED,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,MAAM,GACnC,MAAM,CAIR;AA8BD,wBAAgB,OAAO,CACrB,IAAI,EAAE,eAAe,GAAG,OAAO,GAAG,iBAAiB,EACnD,QAAQ,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,MAAM,GACnC,MAAM,CAsBR;AAED,wBAAgB,0BAA0B,CACxC,aAAa,EAAE,MAAM,EACrB,IAAI,EAAE,MAAM,GACX,8BAA8B,CAkDhC"}

View File

@@ -0,0 +1,127 @@
"use strict";
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.assetRequireAttributeValue = exports.toValue = exports.stringifyContent = exports.transformNode = void 0;
const tslib_1 = require("tslib");
const escape_html_1 = tslib_1.__importDefault(require("escape-html"));
/**
* Util to transform one node type to another node type
* The input node is mutated in place
* @param node the node to mutate
* @param newNode what the original node should become become
*/
function transformNode(node, newNode) {
Object.keys(node).forEach((key) => {
// @ts-expect-error: unsafe but ok
delete node[key];
});
Object.keys(newNode).forEach((key) => {
// @ts-expect-error: unsafe but ok
node[key] = newNode[key];
});
return node;
}
exports.transformNode = transformNode;
function stringifyContent(node, toString) {
return node.children
.map((item) => toValue(item, toString))
.join('');
}
exports.stringifyContent = stringifyContent;
// TODO This is really a workaround, and not super reliable
// For now we only support serializing tagName, className and content
// Can we implement the TOC with real JSX nodes instead of html strings later?
function mdxJsxTextElementToHtml(element, toString) {
const tag = element.name;
const attributes = element.attributes.filter((child) => child.type === 'mdxJsxAttribute');
const classAttribute = attributes.find((attr) => attr.name === 'className') ??
attributes.find((attr) => attr.name === 'class');
const classAttributeString = classAttribute
? `class="${(0, escape_html_1.default)(String(classAttribute.value))}"`
: ``;
const allAttributes = classAttributeString ? ` ${classAttributeString}` : '';
const content = stringifyContent(element, toString);
return `<${tag}${allAttributes}>${content}</${tag}>`;
}
function toValue(node, toString) {
switch (node.type) {
case 'mdxJsxTextElement': {
return mdxJsxTextElementToHtml(node, toString);
}
case 'text':
return (0, escape_html_1.default)(node.value);
case 'heading':
return stringifyContent(node, toString);
case 'inlineCode':
return `<code>${(0, escape_html_1.default)(node.value)}</code>`;
case 'emphasis':
return `<em>${stringifyContent(node, toString)}</em>`;
case 'strong':
return `<strong>${stringifyContent(node, toString)}</strong>`;
case 'delete':
return `<del>${stringifyContent(node, toString)}</del>`;
case 'link':
return stringifyContent(node, toString);
default:
return toString(node);
}
}
exports.toValue = toValue;
function assetRequireAttributeValue(requireString, hash) {
return {
type: 'mdxJsxAttributeValueExpression',
value: `require("${requireString}").default${hash && ` + '${hash}'`}`,
data: {
estree: {
type: 'Program',
body: [
{
type: 'ExpressionStatement',
expression: {
type: 'BinaryExpression',
left: {
type: 'MemberExpression',
object: {
type: 'CallExpression',
callee: {
type: 'Identifier',
name: 'require',
},
arguments: [
{
type: 'Literal',
value: requireString,
raw: `"${requireString}"`,
},
],
optional: false,
},
property: {
type: 'Identifier',
name: 'default',
},
computed: false,
optional: false,
},
operator: '+',
right: {
type: 'Literal',
value: hash,
raw: `"${hash}"`,
},
},
},
],
sourceType: 'module',
comments: [],
},
},
};
}
exports.assetRequireAttributeValue = assetRequireAttributeValue;
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/remark/utils/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,sEAAqC;AAUrC;;;;;GAKG;AACH,SAAgB,aAAa,CAC3B,IAAU,EACV,OAAgB;IAEhB,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;QAChC,kCAAkC;QAClC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;IACnB,CAAC,CAAC,CAAC;IACH,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;QACnC,kCAAkC;QAClC,IAAI,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC,CAAC,CAAC;IACH,OAAO,IAAe,CAAC;AACzB,CAAC;AAbD,sCAaC;AAED,SAAgB,gBAAgB,CAC9B,IAAY,EACZ,QAAoC;IAEpC,OAAQ,IAAI,CAAC,QAA8B;SACxC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;SACtC,IAAI,CAAC,EAAE,CAAC,CAAC;AACd,CAAC;AAPD,4CAOC;AAED,2DAA2D;AAC3D,qEAAqE;AACrE,8EAA8E;AAC9E,SAAS,uBAAuB,CAC9B,OAA0B,EAC1B,QAAoC;IAEpC,MAAM,GAAG,GAAG,OAAO,CAAC,IAAI,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