@docusaurus/mdx-loader 2.0.0-beta.2 → 2.0.0-beta.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.d.ts +33 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +11 -0
- package/lib/index.js.map +1 -0
- package/lib/loader.d.ts +39 -0
- package/lib/loader.d.ts.map +1 -0
- package/lib/loader.js +194 -0
- package/lib/loader.js.map +1 -0
- package/lib/remark/headings/index.d.ts +9 -0
- package/lib/remark/headings/index.d.ts.map +1 -0
- package/lib/remark/headings/index.js +58 -0
- package/lib/remark/headings/index.js.map +1 -0
- package/lib/remark/toc/index.d.ts +13 -0
- package/lib/remark/toc/index.d.ts.map +1 -0
- package/lib/remark/toc/index.js +81 -0
- package/lib/remark/toc/index.js.map +1 -0
- package/lib/remark/transformImage/index.d.ts +14 -0
- package/lib/remark/transformImage/index.d.ts.map +1 -0
- package/lib/remark/transformImage/index.js +109 -0
- package/lib/remark/transformImage/index.js.map +1 -0
- package/lib/remark/transformLinks/index.d.ts +14 -0
- package/lib/remark/transformLinks/index.d.ts.map +1 -0
- package/lib/remark/transformLinks/index.js +102 -0
- package/lib/remark/transformLinks/index.js.map +1 -0
- package/lib/remark/unwrapMdxCodeBlocks/index.d.ts +9 -0
- package/lib/remark/unwrapMdxCodeBlocks/index.d.ts.map +1 -0
- package/lib/remark/unwrapMdxCodeBlocks/index.js +29 -0
- package/lib/remark/unwrapMdxCodeBlocks/index.js.map +1 -0
- package/lib/remark/utils/index.d.ts +11 -0
- package/lib/remark/utils/index.d.ts.map +1 -0
- package/lib/remark/utils/index.js +38 -0
- package/lib/remark/utils/index.js.map +1 -0
- package/package.json +23 -20
- package/src/deps.d.ts +31 -0
- package/src/index.ts +35 -0
- package/src/loader.ts +253 -0
- package/src/remark/headings/{index.js → index.ts} +22 -26
- package/src/remark/toc/index.ts +102 -0
- package/src/remark/transformImage/index.ts +167 -0
- package/src/remark/transformLinks/index.ts +152 -0
- package/src/remark/unwrapMdxCodeBlocks/{index.js → index.ts} +14 -15
- package/src/remark/utils/index.ts +36 -0
- package/src/index.d.ts +0 -19
- package/src/index.js +0 -107
- package/src/remark/headings/__tests__/index.test.js +0 -315
- package/src/remark/toc/__tests__/__snapshots__/index.test.js.snap +0 -85
- package/src/remark/toc/__tests__/fixtures/empty-headings.md +0 -5
- package/src/remark/toc/__tests__/fixtures/inline-code.md +0 -9
- package/src/remark/toc/__tests__/fixtures/insert-below-imports.md +0 -11
- package/src/remark/toc/__tests__/fixtures/just-content.md +0 -15
- package/src/remark/toc/__tests__/fixtures/name-exist.md +0 -7
- package/src/remark/toc/__tests__/fixtures/non-text-content.md +0 -9
- package/src/remark/toc/__tests__/index.test.js +0 -212
- package/src/remark/toc/index.js +0 -79
- package/src/remark/toc/search.js +0 -73
- package/src/remark/transformImage/__tests__/__snapshots__/index.test.js.snap +0 -31
- package/src/remark/transformImage/__tests__/fixtures/fail.md +0 -1
- package/src/remark/transformImage/__tests__/fixtures/img.md +0 -17
- package/src/remark/transformImage/__tests__/fixtures/img.png +0 -0
- package/src/remark/transformImage/__tests__/fixtures/noUrl.md +0 -1
- package/src/remark/transformImage/__tests__/fixtures/pathname.md +0 -1
- package/src/remark/transformImage/__tests__/index.test.js +0 -59
- package/src/remark/transformImage/index.js +0 -106
- package/src/remark/transformLinks/__tests__/__snapshots__/index.test.js.snap +0 -41
- package/src/remark/transformLinks/__tests__/fixtures/asset.md +0 -29
- package/src/remark/transformLinks/__tests__/fixtures/asset.pdf +0 -0
- package/src/remark/transformLinks/__tests__/fixtures/noUrl.md +0 -1
- package/src/remark/transformLinks/__tests__/fixtures/pathname.md +0 -1
- package/src/remark/transformLinks/__tests__/fixtures/static/staticAsset.pdf +0 -0
- package/src/remark/transformLinks/__tests__/fixtures/static/staticAssetImage.png +0 -0
- package/src/remark/transformLinks/__tests__/index.test.js +0 -44
- package/src/remark/transformLinks/index.js +0 -143
- package/src/remark/unwrapMdxCodeBlocks/__tests__/__snapshots__/index.test.js.snap +0 -819
- package/src/remark/unwrapMdxCodeBlocks/__tests__/fixtures/has-mdx-code-blocks.mdx +0 -95
- package/src/remark/unwrapMdxCodeBlocks/__tests__/index.test.js +0 -38
- package/src/remark/utils/index.js +0 -39
- package/tsconfig.json +0 -9
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
/// <reference types="react" />
|
|
8
|
+
import { mdxLoader } from './loader';
|
|
9
|
+
export default mdxLoader;
|
|
10
|
+
export declare type TOCItem = {
|
|
11
|
+
readonly value: string;
|
|
12
|
+
readonly id: string;
|
|
13
|
+
readonly level: number;
|
|
14
|
+
};
|
|
15
|
+
export declare type LoadedMDXContent<FrontMatter, Metadata, Assets = undefined> = {
|
|
16
|
+
/** As verbatim declared in the MDX document. */
|
|
17
|
+
readonly frontMatter: FrontMatter;
|
|
18
|
+
/** As provided by the content plugin. */
|
|
19
|
+
readonly metadata: Metadata;
|
|
20
|
+
/** A list of TOC items (headings). */
|
|
21
|
+
readonly toc: readonly TOCItem[];
|
|
22
|
+
/** First h1 title before any content. */
|
|
23
|
+
readonly contentTitle: string | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Usually image assets that may be collocated like `./img/thumbnail.png`.
|
|
26
|
+
* The loader would also bundle these assets and the client should use these
|
|
27
|
+
* in priority.
|
|
28
|
+
*/
|
|
29
|
+
readonly assets: Assets;
|
|
30
|
+
(): JSX.Element;
|
|
31
|
+
};
|
|
32
|
+
export type { Options, MDXPlugin, MDXOptions } from './loader';
|
|
33
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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,eAAe,SAAS,CAAC;AAEzB,oBAAY,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;AAEF,oBAAY,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;AACF,YAAY,EAAC,OAAO,EAAE,SAAS,EAAE,UAAU,EAAC,MAAM,UAAU,CAAC"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
const loader_1 = require("./loader");
|
|
10
|
+
exports.default = loader_1.mdxLoader;
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAEH,qCAAmC;AAEnC,kBAAe,kBAAS,CAAC"}
|
package/lib/loader.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import type { LoaderContext } from 'webpack';
|
|
8
|
+
import type { Plugin } from 'unified';
|
|
9
|
+
export declare type MDXPlugin = [
|
|
10
|
+
Plugin<any[]>,
|
|
11
|
+
any
|
|
12
|
+
] | Plugin<any[]>;
|
|
13
|
+
export declare type MDXOptions = {
|
|
14
|
+
remarkPlugins: MDXPlugin[];
|
|
15
|
+
rehypePlugins: MDXPlugin[];
|
|
16
|
+
beforeDefaultRemarkPlugins: MDXPlugin[];
|
|
17
|
+
beforeDefaultRehypePlugins: MDXPlugin[];
|
|
18
|
+
};
|
|
19
|
+
export declare type Options = MDXOptions & {
|
|
20
|
+
staticDirs: string[];
|
|
21
|
+
siteDir: string;
|
|
22
|
+
isMDXPartial?: (filePath: string) => boolean;
|
|
23
|
+
isMDXPartialFrontMatterWarningDisabled?: boolean;
|
|
24
|
+
removeContentTitle?: boolean;
|
|
25
|
+
metadataPath?: string | ((filePath: string) => string);
|
|
26
|
+
createAssets?: (metadata: {
|
|
27
|
+
frontMatter: {
|
|
28
|
+
[key: string]: unknown;
|
|
29
|
+
};
|
|
30
|
+
metadata: {
|
|
31
|
+
[key: string]: unknown;
|
|
32
|
+
};
|
|
33
|
+
}) => {
|
|
34
|
+
[key: string]: unknown;
|
|
35
|
+
};
|
|
36
|
+
filepath: string;
|
|
37
|
+
};
|
|
38
|
+
export declare function mdxLoader(this: LoaderContext<Options>, fileString: string): Promise<void>;
|
|
39
|
+
//# sourceMappingURL=loader.d.ts.map
|
|
@@ -0,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a,CAAC,OAAO,CAAC,EAC5B,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,IAAI,CAAC,CAyHf"}
|
package/lib/loader.js
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.mdxLoader = void 0;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
12
|
+
const mdx_1 = require("@mdx-js/mdx");
|
|
13
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
14
|
+
const remark_emoji_1 = tslib_1.__importDefault(require("remark-emoji"));
|
|
15
|
+
const utils_1 = require("@docusaurus/utils");
|
|
16
|
+
const stringify_object_1 = tslib_1.__importDefault(require("stringify-object"));
|
|
17
|
+
const headings_1 = tslib_1.__importDefault(require("./remark/headings"));
|
|
18
|
+
const toc_1 = tslib_1.__importDefault(require("./remark/toc"));
|
|
19
|
+
const unwrapMdxCodeBlocks_1 = tslib_1.__importDefault(require("./remark/unwrapMdxCodeBlocks"));
|
|
20
|
+
const transformImage_1 = tslib_1.__importDefault(require("./remark/transformImage"));
|
|
21
|
+
const transformLinks_1 = tslib_1.__importDefault(require("./remark/transformLinks"));
|
|
22
|
+
const { loaders: { inlineMarkdownImageFileLoader }, } = (0, utils_1.getFileLoaderUtils)();
|
|
23
|
+
const pragma = `
|
|
24
|
+
/* @jsxRuntime classic */
|
|
25
|
+
/* @jsx mdx */
|
|
26
|
+
/* @jsxFrag mdx.Fragment */
|
|
27
|
+
`;
|
|
28
|
+
const DEFAULT_OPTIONS = {
|
|
29
|
+
rehypePlugins: [],
|
|
30
|
+
remarkPlugins: [unwrapMdxCodeBlocks_1.default, remark_emoji_1.default, headings_1.default, toc_1.default],
|
|
31
|
+
beforeDefaultRemarkPlugins: [],
|
|
32
|
+
beforeDefaultRehypePlugins: [],
|
|
33
|
+
};
|
|
34
|
+
const compilerCache = new Map();
|
|
35
|
+
/**
|
|
36
|
+
* When this throws, it generally means that there's no metadata file associated
|
|
37
|
+
* with this MDX document. It can happen when using MDX partials (usually
|
|
38
|
+
* starting with _). That's why it's important to provide the `isMDXPartial`
|
|
39
|
+
* function in config
|
|
40
|
+
*/
|
|
41
|
+
async function readMetadataPath(metadataPath) {
|
|
42
|
+
try {
|
|
43
|
+
return await fs_extra_1.default.readFile(metadataPath, 'utf8');
|
|
44
|
+
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
logger_1.default.error `MDX loader can't read MDX metadata file path=${metadataPath}. Maybe the isMDXPartial option function was not provided?`;
|
|
47
|
+
throw err;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Converts assets an object with Webpack require calls code.
|
|
52
|
+
* This is useful for mdx files to reference co-located assets using relative
|
|
53
|
+
* paths. Those assets should enter the Webpack assets pipeline and be hashed.
|
|
54
|
+
* For now, we only handle that for images and paths starting with `./`:
|
|
55
|
+
*
|
|
56
|
+
* `{image: "./myImage.png"}` => `{image: require("./myImage.png")}`
|
|
57
|
+
*/
|
|
58
|
+
function createAssetsExportCode(assets) {
|
|
59
|
+
if (Object.keys(assets).length === 0) {
|
|
60
|
+
return 'undefined';
|
|
61
|
+
}
|
|
62
|
+
// TODO implementation can be completed/enhanced
|
|
63
|
+
function createAssetValueCode(assetValue) {
|
|
64
|
+
if (Array.isArray(assetValue)) {
|
|
65
|
+
const arrayItemCodes = assetValue.map((item) => createAssetValueCode(item) ?? 'undefined');
|
|
66
|
+
return `[${arrayItemCodes.join(', ')}]`;
|
|
67
|
+
}
|
|
68
|
+
// Only process string values starting with ./
|
|
69
|
+
// We could enhance this logic and check if file exists on disc?
|
|
70
|
+
if (typeof assetValue === 'string' && assetValue.startsWith('./')) {
|
|
71
|
+
// TODO do we have other use-cases than image assets?
|
|
72
|
+
// Probably not worth adding more support, as we want to move to Webpack 5 new asset system (https://github.com/facebook/docusaurus/pull/4708)
|
|
73
|
+
const inlineLoader = inlineMarkdownImageFileLoader;
|
|
74
|
+
return `require("${inlineLoader}${(0, utils_1.escapePath)(assetValue)}").default`;
|
|
75
|
+
}
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
const assetEntries = Object.entries(assets);
|
|
79
|
+
const codeLines = assetEntries
|
|
80
|
+
.map(([key, value]) => {
|
|
81
|
+
const assetRequireCode = createAssetValueCode(value);
|
|
82
|
+
return assetRequireCode ? `"${key}": ${assetRequireCode},` : undefined;
|
|
83
|
+
})
|
|
84
|
+
.filter(Boolean);
|
|
85
|
+
return `{\n${codeLines.join('\n')}\n}`;
|
|
86
|
+
}
|
|
87
|
+
async function mdxLoader(fileString) {
|
|
88
|
+
const callback = this.async();
|
|
89
|
+
const filePath = this.resourcePath;
|
|
90
|
+
const reqOptions = this.getOptions() ?? {};
|
|
91
|
+
const { frontMatter, content: contentWithTitle } = (0, utils_1.parseFrontMatter)(fileString);
|
|
92
|
+
const { content, contentTitle } = (0, utils_1.parseMarkdownContentTitle)(contentWithTitle, {
|
|
93
|
+
removeContentTitle: reqOptions.removeContentTitle,
|
|
94
|
+
});
|
|
95
|
+
const hasFrontMatter = Object.keys(frontMatter).length > 0;
|
|
96
|
+
if (!compilerCache.has(this.query)) {
|
|
97
|
+
const options = {
|
|
98
|
+
...reqOptions,
|
|
99
|
+
remarkPlugins: [
|
|
100
|
+
...(reqOptions.beforeDefaultRemarkPlugins ?? []),
|
|
101
|
+
...DEFAULT_OPTIONS.remarkPlugins,
|
|
102
|
+
[
|
|
103
|
+
transformImage_1.default,
|
|
104
|
+
{
|
|
105
|
+
staticDirs: reqOptions.staticDirs,
|
|
106
|
+
siteDir: reqOptions.siteDir,
|
|
107
|
+
},
|
|
108
|
+
],
|
|
109
|
+
[
|
|
110
|
+
transformLinks_1.default,
|
|
111
|
+
{
|
|
112
|
+
staticDirs: reqOptions.staticDirs,
|
|
113
|
+
siteDir: reqOptions.siteDir,
|
|
114
|
+
},
|
|
115
|
+
],
|
|
116
|
+
...(reqOptions.remarkPlugins ?? []),
|
|
117
|
+
],
|
|
118
|
+
rehypePlugins: [
|
|
119
|
+
...(reqOptions.beforeDefaultRehypePlugins ?? []),
|
|
120
|
+
...DEFAULT_OPTIONS.rehypePlugins,
|
|
121
|
+
...(reqOptions.rehypePlugins ?? []),
|
|
122
|
+
],
|
|
123
|
+
};
|
|
124
|
+
compilerCache.set(this.query, [(0, mdx_1.createCompiler)(options), options]);
|
|
125
|
+
}
|
|
126
|
+
const [compiler, options] = compilerCache.get(this.query);
|
|
127
|
+
let result;
|
|
128
|
+
try {
|
|
129
|
+
result = await compiler
|
|
130
|
+
.process({
|
|
131
|
+
contents: content,
|
|
132
|
+
path: this.resourcePath,
|
|
133
|
+
})
|
|
134
|
+
.then((res) => res.toString());
|
|
135
|
+
}
|
|
136
|
+
catch (err) {
|
|
137
|
+
return callback(err);
|
|
138
|
+
}
|
|
139
|
+
// MDX partials are MDX files starting with _ or in a folder starting with _
|
|
140
|
+
// Partial are not expected to have associated metadata files or front matter
|
|
141
|
+
const isMDXPartial = options.isMDXPartial?.(filePath);
|
|
142
|
+
if (isMDXPartial && hasFrontMatter) {
|
|
143
|
+
const errorMessage = `Docusaurus MDX partial files should not contain front matter.
|
|
144
|
+
Those partial files use the _ prefix as a convention by default, but this is configurable.
|
|
145
|
+
File at ${filePath} contains front matter that will be ignored:
|
|
146
|
+
${JSON.stringify(frontMatter, null, 2)}`;
|
|
147
|
+
if (!options.isMDXPartialFrontMatterWarningDisabled) {
|
|
148
|
+
const shouldError = process.env.NODE_ENV === 'test' || process.env.CI;
|
|
149
|
+
if (shouldError) {
|
|
150
|
+
return callback(new Error(errorMessage));
|
|
151
|
+
}
|
|
152
|
+
logger_1.default.warn(errorMessage);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
function getMetadataPath() {
|
|
156
|
+
if (!isMDXPartial) {
|
|
157
|
+
// Read metadata for this MDX and export it.
|
|
158
|
+
if (options.metadataPath && typeof options.metadataPath === 'function') {
|
|
159
|
+
return options.metadataPath(filePath);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return undefined;
|
|
163
|
+
}
|
|
164
|
+
const metadataPath = getMetadataPath();
|
|
165
|
+
if (metadataPath) {
|
|
166
|
+
this.addDependency(metadataPath);
|
|
167
|
+
}
|
|
168
|
+
const metadataJsonString = metadataPath
|
|
169
|
+
? await readMetadataPath(metadataPath)
|
|
170
|
+
: undefined;
|
|
171
|
+
const metadata = metadataJsonString
|
|
172
|
+
? JSON.parse(metadataJsonString)
|
|
173
|
+
: undefined;
|
|
174
|
+
const assets = reqOptions.createAssets && metadata
|
|
175
|
+
? reqOptions.createAssets({ frontMatter, metadata })
|
|
176
|
+
: undefined;
|
|
177
|
+
const exportsCode = `
|
|
178
|
+
export const frontMatter = ${(0, stringify_object_1.default)(frontMatter)};
|
|
179
|
+
export const contentTitle = ${(0, stringify_object_1.default)(contentTitle)};
|
|
180
|
+
${metadataJsonString ? `export const metadata = ${metadataJsonString};` : ''}
|
|
181
|
+
${assets ? `export const assets = ${createAssetsExportCode(assets)};` : ''}
|
|
182
|
+
`;
|
|
183
|
+
const code = `
|
|
184
|
+
${pragma}
|
|
185
|
+
import React from 'react';
|
|
186
|
+
import { mdx } from '@mdx-js/react';
|
|
187
|
+
|
|
188
|
+
${exportsCode}
|
|
189
|
+
${result}
|
|
190
|
+
`;
|
|
191
|
+
return callback(null, code);
|
|
192
|
+
}
|
|
193
|
+
exports.mdxLoader = mdxLoader;
|
|
194
|
+
//# sourceMappingURL=loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":";A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AAI,CAAC,KAAK,CAAC,kBAAkB,CAAC;QAChC,CAAC,CAAC,SAAS,CAAC;IAEd,MAAM,MAAM,GACV,UAAU,CAAC,YAAY,IAAI,QAAQ;QACjC,CAAC,CAAC,UAAU,CAAC,YAAY,CAAC,EAAC,WAAW,EAAE,QAAQ,EAAC,CAAC;QAClD,CAAC,CAAC,SAAS,CAAC;IAEhB,MAAM,WAAW,GAAG;6BACO,IAAA,0BAAe,EAAC,WAAW,CAAC;8BAC3B,IAAA,0BAAe,EAAC,YAAY,CAAC;EACzD,kBAAkB,CAAC,CAAC,CAAC,2BAA2B,kBAAkB,GAAG,CAAC,CAAC,CAAC,EAAE;EAC1E,MAAM,CAAC,CAAC,CAAC,yBAAyB,sBAAsB,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE;CACzE,CAAC;IAEA,MAAM,IAAI,GAAG;EACb,MAAM;;;;EAIN,WAAW;EACX,MAAM;CACP,CAAC;IAEA,OAAO,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AAC9B,CAAC;AA5HD,8BA4HC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import type { Transformer } from 'unified';
|
|
8
|
+
export default function plugin(): Transformer;
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/remark/headings/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,SAAS,CAAC;AAGzC,MAAM,CAAC,OAAO,UAAU,MAAM,IAAI,WAAW,CAsD5C"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
const tslib_1 = require("tslib");
|
|
10
|
+
/* 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) */
|
|
11
|
+
const utils_1 = require("@docusaurus/utils");
|
|
12
|
+
const unist_util_visit_1 = tslib_1.__importDefault(require("unist-util-visit"));
|
|
13
|
+
const mdast_util_to_string_1 = tslib_1.__importDefault(require("mdast-util-to-string"));
|
|
14
|
+
function plugin() {
|
|
15
|
+
return (root) => {
|
|
16
|
+
const slugs = (0, utils_1.createSlugger)();
|
|
17
|
+
(0, unist_util_visit_1.default)(root, 'heading', (headingNode) => {
|
|
18
|
+
const data = headingNode.data || (headingNode.data = {});
|
|
19
|
+
const properties = (data.hProperties || (data.hProperties = {}));
|
|
20
|
+
let { id } = properties;
|
|
21
|
+
if (id) {
|
|
22
|
+
id = slugs.slug(id, { maintainCase: true });
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
const headingTextNodes = headingNode.children.filter(({ type }) => !['html', 'jsx'].includes(type));
|
|
26
|
+
const heading = (0, mdast_util_to_string_1.default)(headingTextNodes.length > 0 ? headingTextNodes : headingNode);
|
|
27
|
+
// Support explicit heading IDs
|
|
28
|
+
const parsedHeading = (0, utils_1.parseMarkdownHeadingId)(heading);
|
|
29
|
+
id = parsedHeading.id || slugs.slug(heading);
|
|
30
|
+
if (parsedHeading.id) {
|
|
31
|
+
// When there's an id, it is always in the last child node
|
|
32
|
+
// Sometimes heading is in multiple "parts" (** syntax creates a child
|
|
33
|
+
// node):
|
|
34
|
+
// ## part1 *part2* part3 {#id}
|
|
35
|
+
const lastNode = headingNode.children[headingNode.children.length - 1];
|
|
36
|
+
if (headingNode.children.length > 1) {
|
|
37
|
+
const lastNodeText = (0, utils_1.parseMarkdownHeadingId)(lastNode.value).text;
|
|
38
|
+
// When last part contains test+id, remove the id
|
|
39
|
+
if (lastNodeText) {
|
|
40
|
+
lastNode.value = lastNodeText;
|
|
41
|
+
}
|
|
42
|
+
// When last part contains only the id: completely remove that node
|
|
43
|
+
else {
|
|
44
|
+
headingNode.children.pop();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
lastNode.value = parsedHeading.text;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
data.id = id;
|
|
53
|
+
properties.id = id;
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
exports.default = plugin;
|
|
58
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/remark/headings/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,gMAAgM;AAEhM,6CAAwE;AACxE,gFAAqC;AACrC,wFAAiD;AAIjD,SAAwB,MAAM;IAC5B,OAAO,CAAC,IAAI,EAAE,EAAE;QACd,MAAM,KAAK,GAAG,IAAA,qBAAa,GAAE,CAAC;QAC9B,IAAA,0BAAK,EAAC,IAAI,EAAE,SAAS,EAAE,CAAC,WAAoB,EAAE,EAAE;YAC9C,MAAM,IAAI,GAAG,WAAW,CAAC,IAAI,IAAI,CAAC,WAAW,CAAC,IAAI,GAAG,EAAE,CAAC,CAAC;YACzD,MAAM,UAAU,GAAG,CAAC,IAAI,CAAC,WAAW,IAAI,CAAC,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC,CAE9D,CAAC;YACF,IAAI,EAAC,EAAE,EAAC,GAAG,UAAU,CAAC;YAEtB,IAAI,EAAE,EAAE;gBACN,EAAE,GAAG,KAA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EAAE,CAAC;YACb,UAAU,CAAC,EAAE,GAAG,EAAE,CAAC;QACrB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAtDD,yBAsDC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import type { Transformer } from 'unified';
|
|
8
|
+
declare type PluginOptions = {
|
|
9
|
+
name?: string;
|
|
10
|
+
};
|
|
11
|
+
export default function plugin(options?: PluginOptions): Transformer;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/remark/toc/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAaH,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,SAAS,CAAC;AAWzC,aAAK,aAAa,GAAG;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAyCF,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,OAAO,GAAE,aAAkB,GAAG,WAAW,CA6BvE"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
const tslib_1 = require("tslib");
|
|
10
|
+
const parser_1 = require("@babel/parser");
|
|
11
|
+
const traverse_1 = tslib_1.__importDefault(require("@babel/traverse"));
|
|
12
|
+
const stringify_object_1 = tslib_1.__importDefault(require("stringify-object"));
|
|
13
|
+
const mdast_util_to_string_1 = tslib_1.__importDefault(require("mdast-util-to-string"));
|
|
14
|
+
const unist_util_visit_1 = tslib_1.__importDefault(require("unist-util-visit"));
|
|
15
|
+
const utils_1 = require("../utils");
|
|
16
|
+
const parseOptions = {
|
|
17
|
+
plugins: ['jsx'],
|
|
18
|
+
sourceType: 'module',
|
|
19
|
+
};
|
|
20
|
+
const isImport = (child) => child.type === 'import';
|
|
21
|
+
const hasImports = (index) => index > -1;
|
|
22
|
+
const isExport = (child) => child.type === 'export';
|
|
23
|
+
const isTarget = (child, name) => {
|
|
24
|
+
let found = false;
|
|
25
|
+
const ast = (0, parser_1.parse)(child.value, parseOptions);
|
|
26
|
+
(0, traverse_1.default)(ast, {
|
|
27
|
+
VariableDeclarator: (path) => {
|
|
28
|
+
if (path.node.id.name === name) {
|
|
29
|
+
found = true;
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
return found;
|
|
34
|
+
};
|
|
35
|
+
const getOrCreateExistingTargetIndex = (children, name) => {
|
|
36
|
+
let importsIndex = -1;
|
|
37
|
+
let targetIndex = -1;
|
|
38
|
+
children.forEach((child, index) => {
|
|
39
|
+
if (isImport(child)) {
|
|
40
|
+
importsIndex = index;
|
|
41
|
+
}
|
|
42
|
+
else if (isExport(child) && isTarget(child, name)) {
|
|
43
|
+
targetIndex = index;
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
if (targetIndex === -1) {
|
|
47
|
+
const target = {
|
|
48
|
+
default: false,
|
|
49
|
+
type: 'export',
|
|
50
|
+
value: `export const ${name} = [];`,
|
|
51
|
+
};
|
|
52
|
+
targetIndex = hasImports(importsIndex) ? importsIndex + 1 : 0;
|
|
53
|
+
children.splice(targetIndex, 0, target);
|
|
54
|
+
}
|
|
55
|
+
return targetIndex;
|
|
56
|
+
};
|
|
57
|
+
function plugin(options = {}) {
|
|
58
|
+
const name = options.name || 'toc';
|
|
59
|
+
return (root) => {
|
|
60
|
+
const headings = [];
|
|
61
|
+
(0, unist_util_visit_1.default)(root, 'heading', (child, index, parent) => {
|
|
62
|
+
const value = (0, mdast_util_to_string_1.default)(child);
|
|
63
|
+
// depth: 1 headings are titles and not included in the TOC
|
|
64
|
+
if (parent !== root || !value || child.depth < 2) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
headings.push({
|
|
68
|
+
value: (0, utils_1.toValue)(child),
|
|
69
|
+
id: child.data.id,
|
|
70
|
+
level: child.depth,
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
const { children } = root;
|
|
74
|
+
const targetIndex = getOrCreateExistingTargetIndex(children, name);
|
|
75
|
+
if (headings.length) {
|
|
76
|
+
children[targetIndex].value = `export const ${name} = ${(0, stringify_object_1.default)(headings)};`;
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
exports.default = plugin;
|
|
81
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/remark/toc/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,0CAAwD;AAExD,uEAAuC;AACvC,gFAA+C;AAC/C,wFAA4C;AAC5C,gFAAqC;AACrC,oCAAiC;AAOjC,MAAM,YAAY,GAAkB;IAClC,OAAO,EAAE,CAAC,KAAK,CAAC;IAChB,UAAU,EAAE,QAAQ;CACrB,CAAC;AAEF,MAAM,QAAQ,GAAG,CAAC,KAAW,EAAoB,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,QAAQ,CAAC;AAC5E,MAAM,UAAU,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;AACjD,MAAM,QAAQ,GAAG,CAAC,KAAW,EAAoB,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,QAAQ,CAAC;AAM5E,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAE,IAAY,EAAE,EAAE;IACh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,CAAC,UAAyB,EAAE;IACxD,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,KAAK,CAAC;IAEnC,OAAO,CAAC,IAAI,EAAE,EAAE;QACd,MAAM,QAAQ,GAAc,EAAE,CAAC;QAE/B,IAAA,0BAAK,EAAC,IAAI,EAAE,SAAS,EAAE,CAAC,KAAc,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;YACvD,MAAM,KAAK,GAAG,IAAA,8BAAQ,EAAC,KAAK,CAAC,CAAC;YAE9B,2DAA2D;YAC3D,IAAI,MAAM,KAAK,IAAI,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,KAAK,GAAG,CAAC,EAAE;gBAChD,OAAO;aACR;YAED,QAAQ,CAAC,IAAI,CAAC;gBACZ,KAAK,EAAE,IAAA,eAAO,EAAC,KAAK,CAAC;gBACrB,EAAE,EAAE,KAAK,CAAC,IAAK,CAAC,EAAY;gBAC5B,KAAK,EAAE,KAAK,CAAC,KAAK;aACnB,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QACH,MAAM,EAAC,QAAQ,EAAC,GAAG,IAAuB,CAAC;QAC3C,MAAM,WAAW,GAAG,8BAA8B,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QAEnE,IAAI,QAAQ,CAAC,MAAM,EAAE;YACnB,QAAQ,CAAC,WAAW,CAAE,CAAC,KAAK,GAAG,gBAAgB,IAAI,MAAM,IAAA,0BAAe,EACtE,QAAQ,CACT,GAAG,CAAC;SACN;IACH,CAAC,CAAC;AACJ,CAAC;AA7BD,yBA6BC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import type { Transformer } from 'unified';
|
|
8
|
+
declare type PluginOptions = {
|
|
9
|
+
staticDirs: string[];
|
|
10
|
+
siteDir: string;
|
|
11
|
+
};
|
|
12
|
+
export default function plugin(options: PluginOptions): Transformer;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/remark/transformImage/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAgBH,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,SAAS,CAAC;AAQzC,aAAK,aAAa,GAAG;IACnB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AA4HF,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,OAAO,EAAE,aAAa,GAAG,WAAW,CAUlE"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
const tslib_1 = require("tslib");
|
|
10
|
+
const utils_1 = require("@docusaurus/utils");
|
|
11
|
+
const unist_util_visit_1 = tslib_1.__importDefault(require("unist-util-visit"));
|
|
12
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
13
|
+
const url_1 = tslib_1.__importDefault(require("url"));
|
|
14
|
+
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
15
|
+
const escape_html_1 = tslib_1.__importDefault(require("escape-html"));
|
|
16
|
+
const image_size_1 = tslib_1.__importDefault(require("image-size"));
|
|
17
|
+
const util_1 = require("util");
|
|
18
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
19
|
+
const { loaders: { inlineMarkdownImageFileLoader }, } = (0, utils_1.getFileLoaderUtils)();
|
|
20
|
+
async function toImageRequireNode(node, imagePath, filePath) {
|
|
21
|
+
const jsxNode = node;
|
|
22
|
+
let relativeImagePath = (0, utils_1.posixPath)(path_1.default.relative(path_1.default.dirname(filePath), imagePath));
|
|
23
|
+
relativeImagePath = `./${relativeImagePath}`;
|
|
24
|
+
const parsedUrl = url_1.default.parse(node.url);
|
|
25
|
+
const hash = parsedUrl.hash ?? '';
|
|
26
|
+
const search = parsedUrl.search ?? '';
|
|
27
|
+
const alt = node.alt ? `alt={"${(0, escape_html_1.default)(node.alt)}"} ` : '';
|
|
28
|
+
const src = `require("${inlineMarkdownImageFileLoader}${(0, utils_1.escapePath)(relativeImagePath) + search}").default${hash ? ` + '${hash}'` : ''}`;
|
|
29
|
+
const title = node.title ? ` title="${(0, escape_html_1.default)(node.title)}"` : '';
|
|
30
|
+
let width = '';
|
|
31
|
+
let height = '';
|
|
32
|
+
try {
|
|
33
|
+
const size = (await (0, util_1.promisify)(image_size_1.default)(imagePath));
|
|
34
|
+
if (size.width) {
|
|
35
|
+
width = ` width="${size.width}"`;
|
|
36
|
+
}
|
|
37
|
+
if (size.height) {
|
|
38
|
+
height = ` height="${size.height}"`;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
// Workaround for https://github.com/yarnpkg/berry/pull/3889#issuecomment-1034469784
|
|
43
|
+
// TODO remove this check once fixed in Yarn PnP
|
|
44
|
+
if (!process.versions.pnp) {
|
|
45
|
+
logger_1.default.warn `The image at path=${imagePath} can't be read correctly. Please ensure it's a valid image.
|
|
46
|
+
${err.message}`;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
Object.keys(jsxNode).forEach((key) => delete jsxNode[key]);
|
|
50
|
+
jsxNode.type = 'jsx';
|
|
51
|
+
jsxNode.value = `<img ${alt}src={${src}}${title}${width}${height} />`;
|
|
52
|
+
}
|
|
53
|
+
async function ensureImageFileExist(imagePath, sourceFilePath) {
|
|
54
|
+
const imageExists = await fs_extra_1.default.pathExists(imagePath);
|
|
55
|
+
if (!imageExists) {
|
|
56
|
+
throw new Error(`Image ${(0, utils_1.toMessageRelativeFilePath)(imagePath)} used in ${(0, utils_1.toMessageRelativeFilePath)(sourceFilePath)} not found.`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
async function getImageAbsolutePath(imagePath, { siteDir, filePath, staticDirs }) {
|
|
60
|
+
if (imagePath.startsWith('@site/')) {
|
|
61
|
+
const imageFilePath = path_1.default.join(siteDir, imagePath.replace('@site/', ''));
|
|
62
|
+
await ensureImageFileExist(imageFilePath, filePath);
|
|
63
|
+
return imageFilePath;
|
|
64
|
+
}
|
|
65
|
+
else if (path_1.default.isAbsolute(imagePath)) {
|
|
66
|
+
// Absolute paths are expected to exist in the static folder.
|
|
67
|
+
const possiblePaths = staticDirs.map((dir) => path_1.default.join(dir, imagePath));
|
|
68
|
+
const imageFilePath = await (0, utils_1.findAsyncSequential)(possiblePaths, fs_extra_1.default.pathExists);
|
|
69
|
+
if (!imageFilePath) {
|
|
70
|
+
throw new Error(`Image ${possiblePaths
|
|
71
|
+
.map((p) => (0, utils_1.toMessageRelativeFilePath)(p))
|
|
72
|
+
.join(' or ')} used in ${(0, utils_1.toMessageRelativeFilePath)(filePath)} not found.`);
|
|
73
|
+
}
|
|
74
|
+
return imageFilePath;
|
|
75
|
+
}
|
|
76
|
+
// Relative paths are resolved against the source file's folder.
|
|
77
|
+
const imageFilePath = path_1.default.join(path_1.default.dirname(filePath), decodeURIComponent(imagePath));
|
|
78
|
+
await ensureImageFileExist(imageFilePath, filePath);
|
|
79
|
+
return imageFilePath;
|
|
80
|
+
}
|
|
81
|
+
async function processImageNode(node, context) {
|
|
82
|
+
if (!node.url) {
|
|
83
|
+
throw new Error(`Markdown image URL is mandatory in "${(0, utils_1.toMessageRelativeFilePath)(context.filePath)}" file`);
|
|
84
|
+
}
|
|
85
|
+
const parsedUrl = url_1.default.parse(node.url);
|
|
86
|
+
if (parsedUrl.protocol || !parsedUrl.pathname) {
|
|
87
|
+
// pathname:// is an escape hatch, in case user does not want her images to
|
|
88
|
+
// be converted to require calls going through webpack loader
|
|
89
|
+
if (parsedUrl.protocol === 'pathname:') {
|
|
90
|
+
node.url = node.url.replace('pathname://', '');
|
|
91
|
+
}
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
// We try to convert image urls without protocol to images with require calls
|
|
95
|
+
// going through webpack ensures that image assets exist at build time
|
|
96
|
+
const imagePath = await getImageAbsolutePath(parsedUrl.pathname, context);
|
|
97
|
+
await toImageRequireNode(node, imagePath, context.filePath);
|
|
98
|
+
}
|
|
99
|
+
function plugin(options) {
|
|
100
|
+
return async (root, vfile) => {
|
|
101
|
+
const promises = [];
|
|
102
|
+
(0, unist_util_visit_1.default)(root, 'image', (node) => {
|
|
103
|
+
promises.push(processImageNode(node, { ...options, filePath: vfile.path }));
|
|
104
|
+
});
|
|
105
|
+
await Promise.all(promises);
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
exports.default = plugin;
|
|
109
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/remark/transformImage/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,6CAM2B;AAC3B,gFAAqC;AACrC,wDAAwB;AACxB,sDAAsB;AACtB,gEAA0B;AAC1B,sEAAqC;AACrC,oEAAgC;AAChC,+BAA+B;AAG/B,wEAAwC;AAExC,MAAM,EACJ,OAAO,EAAE,EAAC,6BAA6B,EAAC,GACzC,GAAG,IAAA,0BAAkB,GAAE,CAAC;AAWzB,KAAK,UAAU,kBAAkB,CAC/B,IAAW,EACX,SAAiB,EACjB,QAAgB;IAEhB,MAAM,OAAO,GAAG,IAAgC,CAAC;IACjD,IAAI,iBAAiB,GAAG,IAAA,iBAAS,EAC/B,cAAI,CAAC,QAAQ,CAAC,cAAI,CAAC,OAAO,CAAC,QAAQ,CAAC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C,SAAS,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC1E,MAAM,kBAAkB,CAAC,IAAI,EAAE,SAAS,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;AAC9D,CAAC;AAED,SAAwB,MAAM,CAAC,OAAsB;IACnD,OAAO,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE;QAC3B,MAAM,QAAQ,GAAoB,EAAE,CAAC;QACrC,IAAA,0BAAK,EAAC,IAAI,EAAE,OAAO,EAAE,CAAC,IAAW,EAAE,EAAE;YACnC,QAAQ,CAAC,IAAI,CACX,gBAAgB,CAAC,IAAI,EAAE,EAAC,GAAG,OAAO,EAAE,QAAQ,EAAE,KAAK,CAAC,IAAK,EAAC,CAAC,CAC5D,CAAC;QACJ,CAAC,CAAC,CAAC;QACH,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC9B,CAAC,CAAC;AACJ,CAAC;AAVD,yBAUC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import type { Transformer } from 'unified';
|
|
8
|
+
declare type PluginOptions = {
|
|
9
|
+
staticDirs: string[];
|
|
10
|
+
siteDir: string;
|
|
11
|
+
};
|
|
12
|
+
export default function plugin(options: PluginOptions): Transformer;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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;AAOzC,aAAK,aAAa,GAAG;IACnB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAiHF,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,OAAO,EAAE,aAAa,GAAG,WAAW,CAQlE"}
|