@docusaurus/utils 0.0.0-4485 → 0.0.0-4489
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 +10 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +27 -2
- package/lib/index.js.map +1 -1
- package/package.json +5 -4
- package/src/index.ts +33 -1
- package/lib/mdxUtils.d.ts +0 -17
- package/lib/mdxUtils.d.ts.map +0 -1
- package/lib/mdxUtils.js +0 -31
- package/lib/mdxUtils.js.map +0 -1
- package/src/mdxUtils.ts +0 -32
package/lib/index.d.ts
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
+
/// <reference types="node" />
|
|
7
8
|
import type { ReportingSeverity, TranslationFileContent, TranslationFile } from '@docusaurus/types';
|
|
8
9
|
export * from './constants';
|
|
9
|
-
export * from './mdxUtils';
|
|
10
10
|
export * from './urlUtils';
|
|
11
11
|
export * from './tags';
|
|
12
12
|
export * from './markdownParser';
|
|
@@ -47,6 +47,15 @@ export declare function getPluginI18nPath({ siteDir, locale, pluginName, pluginI
|
|
|
47
47
|
pluginId?: string | undefined;
|
|
48
48
|
subPaths?: string[];
|
|
49
49
|
}): string;
|
|
50
|
+
/**
|
|
51
|
+
* @param permalink The URL that the HTML file corresponds to, without base URL
|
|
52
|
+
* @param outDir Full path to the output directory
|
|
53
|
+
* @param trailingSlash The site config option. If provided, only one path will be read.
|
|
54
|
+
* @returns This returns a buffer, which you have to decode string yourself if
|
|
55
|
+
* needed. (Not always necessary since the output isn't for human consumption
|
|
56
|
+
* anyways, and most HTML manipulation libs accept buffers)
|
|
57
|
+
*/
|
|
58
|
+
export declare function readOutputHTMLFile(permalink: string, outDir: string, trailingSlash: boolean | undefined): Promise<Buffer>;
|
|
50
59
|
export declare function mapAsyncSequential<T, R>(array: T[], action: (t: T) => Promise<R>): Promise<R[]>;
|
|
51
60
|
export declare function findAsyncSequential<T>(array: T[], predicate: (t: T) => Promise<boolean>): Promise<T | undefined>;
|
|
52
61
|
export declare function reportMessage(message: string, reportingSeverity: ReportingSeverity): void;
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;;AAQH,OAAO,KAAK,EACV,iBAAiB,EACjB,sBAAsB,EACtB,eAAe,EAChB,MAAM,mBAAmB,CAAC;AAO3B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AACvB,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAGhC,wBAAsB,QAAQ,CAC5B,iBAAiB,EAAE,MAAM,EACzB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,SAAS,GAAE,OAA+C,GACzD,OAAO,CAAC,IAAI,CAAC,CA2Bf;AAKD;;;GAGG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAK/C;AAED,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAKnD;AAGD;;GAEG;AACH,wBAAgB,YAAY,CAC1B,UAAU,EAAE,MAAM,EAClB,MAAM,CAAC,EAAE,MAAM,EACf,aAAa,CAAC,EAAE,MAAM,EACtB,OAAO,GAAE,OAA+C,GACvD,MAAM,CAiBR;AAED,wBAAgB,eAAe,CAAC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BAAkB,CAAC,CAAC,EAAE,CAAC,EAC3C,KAAK,EAAE,CAAC,EAAE,EACV,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,GAC3B,OAAO,CAAC,CAAC,EAAE,CAAC,CAQd;AAED,wBAAsB,mBAAmB,CAAC,CAAC,EACzC,KAAK,EAAE,CAAC,EAAE,EACV,SAAS,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,OAAO,CAAC,OAAO,CAAC,GACpC,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAQxB;AAED,wBAAgB,aAAa,CAC3B,OAAO,EAAE,MAAM,EACf,iBAAiB,EAAE,iBAAiB,GACnC,IAAI,CAoBN;AAED,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,sBAAsB,EAAE,GACjC,sBAAsB,CAExB;AAID,wBAAgB,6BAA6B,CAC3C,eAAe,EAAE,eAAe,EAChC,aAAa,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,GACzC,eAAe,CAQjB"}
|
package/lib/index.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.updateTranslationFileMessages = exports.mergeTranslations = exports.reportMessage = exports.findAsyncSequential = exports.mapAsyncSequential = exports.getPluginI18nPath = exports.getElementsAround = exports.removePrefix = exports.removeSuffix = exports.removeTrailingSlash = exports.addTrailingSlash = exports.addTrailingPathSeparator = exports.addLeadingSlash = exports.resolvePathname = exports.isValidPathname = exports.genChunkName = exports.encodePath = exports.fileToPath = exports.generate = void 0;
|
|
9
|
+
exports.updateTranslationFileMessages = exports.mergeTranslations = exports.reportMessage = exports.findAsyncSequential = exports.mapAsyncSequential = exports.readOutputHTMLFile = exports.getPluginI18nPath = exports.getElementsAround = exports.removePrefix = exports.removeSuffix = exports.removeTrailingSlash = exports.addTrailingSlash = exports.addTrailingPathSeparator = exports.addLeadingSlash = exports.resolvePathname = exports.isValidPathname = exports.genChunkName = exports.encodePath = exports.fileToPath = exports.generate = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
|
|
12
12
|
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
@@ -18,7 +18,6 @@ const resolve_pathname_1 = (0, tslib_1.__importDefault)(require("resolve-pathnam
|
|
|
18
18
|
const hashUtils_1 = require("./hashUtils");
|
|
19
19
|
const constants_1 = require("./constants");
|
|
20
20
|
(0, tslib_1.__exportStar)(require("./constants"), exports);
|
|
21
|
-
(0, tslib_1.__exportStar)(require("./mdxUtils"), exports);
|
|
22
21
|
(0, tslib_1.__exportStar)(require("./urlUtils"), exports);
|
|
23
22
|
(0, tslib_1.__exportStar)(require("./tags"), exports);
|
|
24
23
|
(0, tslib_1.__exportStar)(require("./markdownParser"), exports);
|
|
@@ -168,6 +167,32 @@ function getPluginI18nPath({ siteDir, locale, pluginName, pluginId = constants_1
|
|
|
168
167
|
`${pluginName}${pluginId === constants_1.DEFAULT_PLUGIN_ID ? '' : `-${pluginId}`}`, ...subPaths);
|
|
169
168
|
}
|
|
170
169
|
exports.getPluginI18nPath = getPluginI18nPath;
|
|
170
|
+
/**
|
|
171
|
+
* @param permalink The URL that the HTML file corresponds to, without base URL
|
|
172
|
+
* @param outDir Full path to the output directory
|
|
173
|
+
* @param trailingSlash The site config option. If provided, only one path will be read.
|
|
174
|
+
* @returns This returns a buffer, which you have to decode string yourself if
|
|
175
|
+
* needed. (Not always necessary since the output isn't for human consumption
|
|
176
|
+
* anyways, and most HTML manipulation libs accept buffers)
|
|
177
|
+
*/
|
|
178
|
+
async function readOutputHTMLFile(permalink, outDir, trailingSlash) {
|
|
179
|
+
const withTrailingSlashPath = path_1.default.join(outDir, permalink, 'index.html');
|
|
180
|
+
const withoutTrailingSlashPath = path_1.default.join(outDir, `${permalink}.html`);
|
|
181
|
+
if (trailingSlash) {
|
|
182
|
+
return fs_extra_1.default.readFile(withTrailingSlashPath);
|
|
183
|
+
}
|
|
184
|
+
else if (trailingSlash === false) {
|
|
185
|
+
return fs_extra_1.default.readFile(withoutTrailingSlashPath);
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
const HTMLPath = await findAsyncSequential([withTrailingSlashPath, withoutTrailingSlashPath], fs_extra_1.default.pathExists);
|
|
189
|
+
if (!HTMLPath) {
|
|
190
|
+
throw new Error(`Expected output HTML file to be found at ${withTrailingSlashPath}`);
|
|
191
|
+
}
|
|
192
|
+
return fs_extra_1.default.readFile(HTMLPath);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
exports.readOutputHTMLFile = readOutputHTMLFile;
|
|
171
196
|
async function mapAsyncSequential(array, action) {
|
|
172
197
|
const results = [];
|
|
173
198
|
// eslint-disable-next-line no-restricted-syntax
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,6EAAwC;AACxC,6DAAwB;AACxB,mCAAkC;AAClC,mCAAiC;AACjC,qEAA0B;AAC1B,6BAAwB;AAOxB,qFAAqD;AAErD,2CAAiD;AACjD,2CAA8C;AAE9C,2DAA4B;AAC5B,0DAA2B;AAC3B,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,6EAAwC;AACxC,6DAAwB;AACxB,mCAAkC;AAClC,mCAAiC;AACjC,qEAA0B;AAC1B,6BAAwB;AAOxB,qFAAqD;AAErD,2CAAiD;AACjD,2CAA8C;AAE9C,2DAA4B;AAC5B,0DAA2B;AAC3B,sDAAuB;AACvB,gEAAiC;AACjC,+DAAgC;AAChC,yDAA0B;AAC1B,2DAA4B;AAC5B,2DAA4B;AAC5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,MAAM;QACR,KAAK,OAAO;YACV,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;QAC3B;YACE,MAAM,IAAI,KAAK,CACb,yCAAyC,iBAAiB,GAAG,CAC9D,CAAC;KACL;AACH,CAAC;AAvBD,sCAuBC;AAED,SAAgB,iBAAiB,CAC/B,QAAkC;IAElC,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC,EAAC,GAAG,GAAG,EAAE,GAAG,OAAO,EAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AACvE,CAAC;AAJD,8CAIC;AAED,0DAA0D;AAC1D,yCAAyC;AACzC,SAAgB,6BAA6B,CAC3C,eAAgC,EAChC,aAA0C;IAE1C,OAAO;QACL,GAAG,eAAe;QAClB,OAAO,EAAE,IAAA,kBAAS,EAAC,eAAe,CAAC,OAAO,EAAE,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;YAC5D,GAAG,WAAW;YACd,OAAO,EAAE,aAAa,CAAC,WAAW,CAAC,OAAO,CAAC;SAC5C,CAAC,CAAC;KACJ,CAAC;AACJ,CAAC;AAXD,sEAWC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/utils",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-4489",
|
|
4
4
|
"description": "Node utility functions for Docusaurus packages.",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
},
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@docusaurus/logger": "0.0.0-
|
|
21
|
+
"@docusaurus/logger": "0.0.0-4489",
|
|
22
22
|
"@mdx-js/runtime": "^1.6.22",
|
|
23
23
|
"@svgr/webpack": "^6.0.0",
|
|
24
24
|
"file-loader": "^6.2.0",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"node": ">=14"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@docusaurus/types": "0.0.0-
|
|
42
|
+
"@docusaurus/types": "0.0.0-4489",
|
|
43
43
|
"@types/dedent": "^0.7.0",
|
|
44
44
|
"@types/github-slugger": "^1.3.0",
|
|
45
45
|
"@types/micromatch": "^4.0.2",
|
|
@@ -48,9 +48,10 @@
|
|
|
48
48
|
"tslib": "^2.3.1"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
+
"@babel/core": "^7.0.0",
|
|
51
52
|
"react": "*",
|
|
52
53
|
"react-dom": "*",
|
|
53
54
|
"webpack": "5.x"
|
|
54
55
|
},
|
|
55
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "f4020aaf26717ce5e5085a949cf3b7e088bc386f"
|
|
56
57
|
}
|
package/src/index.ts
CHANGED
|
@@ -23,7 +23,6 @@ import {simpleHash, docuHash} from './hashUtils';
|
|
|
23
23
|
import {DEFAULT_PLUGIN_ID} from './constants';
|
|
24
24
|
|
|
25
25
|
export * from './constants';
|
|
26
|
-
export * from './mdxUtils';
|
|
27
26
|
export * from './urlUtils';
|
|
28
27
|
export * from './tags';
|
|
29
28
|
export * from './markdownParser';
|
|
@@ -210,6 +209,39 @@ export function getPluginI18nPath({
|
|
|
210
209
|
);
|
|
211
210
|
}
|
|
212
211
|
|
|
212
|
+
/**
|
|
213
|
+
* @param permalink The URL that the HTML file corresponds to, without base URL
|
|
214
|
+
* @param outDir Full path to the output directory
|
|
215
|
+
* @param trailingSlash The site config option. If provided, only one path will be read.
|
|
216
|
+
* @returns This returns a buffer, which you have to decode string yourself if
|
|
217
|
+
* needed. (Not always necessary since the output isn't for human consumption
|
|
218
|
+
* anyways, and most HTML manipulation libs accept buffers)
|
|
219
|
+
*/
|
|
220
|
+
export async function readOutputHTMLFile(
|
|
221
|
+
permalink: string,
|
|
222
|
+
outDir: string,
|
|
223
|
+
trailingSlash: boolean | undefined,
|
|
224
|
+
): Promise<Buffer> {
|
|
225
|
+
const withTrailingSlashPath = path.join(outDir, permalink, 'index.html');
|
|
226
|
+
const withoutTrailingSlashPath = path.join(outDir, `${permalink}.html`);
|
|
227
|
+
if (trailingSlash) {
|
|
228
|
+
return fs.readFile(withTrailingSlashPath);
|
|
229
|
+
} else if (trailingSlash === false) {
|
|
230
|
+
return fs.readFile(withoutTrailingSlashPath);
|
|
231
|
+
} else {
|
|
232
|
+
const HTMLPath = await findAsyncSequential(
|
|
233
|
+
[withTrailingSlashPath, withoutTrailingSlashPath],
|
|
234
|
+
fs.pathExists,
|
|
235
|
+
);
|
|
236
|
+
if (!HTMLPath) {
|
|
237
|
+
throw new Error(
|
|
238
|
+
`Expected output HTML file to be found at ${withTrailingSlashPath}`,
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
return fs.readFile(HTMLPath);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
213
245
|
export async function mapAsyncSequential<T, R>(
|
|
214
246
|
array: T[],
|
|
215
247
|
action: (t: T) => Promise<R>,
|
package/lib/mdxUtils.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
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
|
-
/**
|
|
8
|
-
* Transform mdx text to plain html text
|
|
9
|
-
* Initially created to convert MDX blog posts to HTML for the RSS feed
|
|
10
|
-
* without import/export nodes
|
|
11
|
-
*
|
|
12
|
-
* TODO not ideal implementation, won't work well with MDX elements!
|
|
13
|
-
* TODO theme+global site config should be able to declare MDX comps in scope for rendering the RSS feeds
|
|
14
|
-
* see also https://github.com/facebook/docusaurus/issues/4625
|
|
15
|
-
*/
|
|
16
|
-
export declare function mdxToHtml(mdxStr: string): string;
|
|
17
|
-
//# sourceMappingURL=mdxUtils.d.ts.map
|
package/lib/mdxUtils.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mdxUtils.d.ts","sourceRoot":"","sources":["../src/mdxUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAQH;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CACvB,MAAM,EAAE,MAAM,GAEb,MAAM,CAMR"}
|
package/lib/mdxUtils.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
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.mdxToHtml = void 0;
|
|
10
|
-
const tslib_1 = require("tslib");
|
|
11
|
-
const react_1 = (0, tslib_1.__importDefault)(require("react"));
|
|
12
|
-
const server_1 = (0, tslib_1.__importDefault)(require("react-dom/server"));
|
|
13
|
-
const runtime_1 = (0, tslib_1.__importDefault)(require("@mdx-js/runtime"));
|
|
14
|
-
const remark_mdx_remove_imports_1 = (0, tslib_1.__importDefault)(require("remark-mdx-remove-imports"));
|
|
15
|
-
const remark_mdx_remove_exports_1 = (0, tslib_1.__importDefault)(require("remark-mdx-remove-exports"));
|
|
16
|
-
/**
|
|
17
|
-
* Transform mdx text to plain html text
|
|
18
|
-
* Initially created to convert MDX blog posts to HTML for the RSS feed
|
|
19
|
-
* without import/export nodes
|
|
20
|
-
*
|
|
21
|
-
* TODO not ideal implementation, won't work well with MDX elements!
|
|
22
|
-
* TODO theme+global site config should be able to declare MDX comps in scope for rendering the RSS feeds
|
|
23
|
-
* see also https://github.com/facebook/docusaurus/issues/4625
|
|
24
|
-
*/
|
|
25
|
-
function mdxToHtml(mdxStr) {
|
|
26
|
-
return server_1.default.renderToString(react_1.default.createElement(runtime_1.default, { remarkPlugins: [remark_mdx_remove_imports_1.default, remark_mdx_remove_exports_1.default] }, [
|
|
27
|
-
mdxStr,
|
|
28
|
-
]));
|
|
29
|
-
}
|
|
30
|
-
exports.mdxToHtml = mdxToHtml;
|
|
31
|
-
//# sourceMappingURL=mdxUtils.js.map
|
package/lib/mdxUtils.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mdxUtils.js","sourceRoot":"","sources":["../src/mdxUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,+DAA0B;AAC1B,2EAA8C;AAC9C,2EAAkC;AAClC,uGAAsD;AACtD,uGAAsD;AAEtD;;;;;;;;GAQG;AACH,SAAgB,SAAS,CACvB,MAAc;IAGd,OAAO,gBAAc,CAAC,cAAc,CAClC,eAAK,CAAC,aAAa,CAAC,iBAAG,EAAE,EAAC,aAAa,EAAE,CAAC,mCAAa,EAAE,mCAAa,CAAC,EAAC,EAAE;QACxE,MAAM;KACP,CAAC,CACH,CAAC;AACJ,CAAC;AATD,8BASC"}
|
package/src/mdxUtils.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
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
|
-
|
|
8
|
-
import React from 'react';
|
|
9
|
-
import ReactDOMServer from 'react-dom/server';
|
|
10
|
-
import MDX from '@mdx-js/runtime';
|
|
11
|
-
import removeImports from 'remark-mdx-remove-imports';
|
|
12
|
-
import removeExports from 'remark-mdx-remove-exports';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Transform mdx text to plain html text
|
|
16
|
-
* Initially created to convert MDX blog posts to HTML for the RSS feed
|
|
17
|
-
* without import/export nodes
|
|
18
|
-
*
|
|
19
|
-
* TODO not ideal implementation, won't work well with MDX elements!
|
|
20
|
-
* TODO theme+global site config should be able to declare MDX comps in scope for rendering the RSS feeds
|
|
21
|
-
* see also https://github.com/facebook/docusaurus/issues/4625
|
|
22
|
-
*/
|
|
23
|
-
export function mdxToHtml(
|
|
24
|
-
mdxStr: string,
|
|
25
|
-
// TODO allow providing components/scope here, see https://github.com/mdx-js/mdx/tree/v1.6.13/packages/runtime
|
|
26
|
-
): string {
|
|
27
|
-
return ReactDOMServer.renderToString(
|
|
28
|
-
React.createElement(MDX, {remarkPlugins: [removeImports, removeExports]}, [
|
|
29
|
-
mdxStr,
|
|
30
|
-
]),
|
|
31
|
-
);
|
|
32
|
-
}
|