@docusaurus/utils 2.0.0-beta.16 → 2.0.0-beta.19
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/constants.d.ts +51 -1
- package/lib/constants.d.ts.map +1 -1
- package/lib/constants.js +57 -10
- package/lib/constants.js.map +1 -1
- package/lib/dataFileUtils.d.ts +38 -2
- package/lib/dataFileUtils.d.ts.map +1 -1
- package/lib/dataFileUtils.js +39 -13
- package/lib/dataFileUtils.js.map +1 -1
- package/lib/emitUtils.d.ts +32 -0
- package/lib/emitUtils.d.ts.map +1 -0
- package/lib/emitUtils.js +80 -0
- package/lib/emitUtils.js.map +1 -0
- package/lib/gitUtils.d.ts +54 -5
- package/lib/gitUtils.d.ts.map +1 -1
- package/lib/gitUtils.js +17 -14
- package/lib/gitUtils.js.map +1 -1
- package/lib/globUtils.d.ts +28 -0
- package/lib/globUtils.d.ts.map +1 -1
- package/lib/globUtils.js +36 -13
- package/lib/globUtils.js.map +1 -1
- package/lib/hashUtils.d.ts +5 -4
- package/lib/hashUtils.d.ts.map +1 -1
- package/lib/hashUtils.js +7 -6
- package/lib/hashUtils.js.map +1 -1
- package/lib/i18nUtils.d.ts +51 -0
- package/lib/i18nUtils.d.ts.map +1 -0
- package/lib/i18nUtils.js +69 -0
- package/lib/i18nUtils.js.map +1 -0
- package/lib/index.d.ts +10 -54
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +56 -256
- package/lib/index.js.map +1 -1
- package/lib/jsUtils.d.ts +45 -0
- package/lib/jsUtils.d.ts.map +1 -0
- package/lib/jsUtils.js +94 -0
- package/lib/jsUtils.js.map +1 -0
- package/lib/markdownLinks.d.ts +48 -5
- package/lib/markdownLinks.d.ts.map +1 -1
- package/lib/markdownLinks.js +29 -13
- package/lib/markdownLinks.js.map +1 -1
- package/lib/markdownUtils.d.ts +112 -0
- package/lib/markdownUtils.d.ts.map +1 -0
- package/lib/markdownUtils.js +271 -0
- package/lib/markdownUtils.js.map +1 -0
- package/lib/pathUtils.d.ts +2 -1
- package/lib/pathUtils.d.ts.map +1 -1
- package/lib/pathUtils.js +16 -7
- package/lib/pathUtils.js.map +1 -1
- package/lib/slugger.d.ts +10 -0
- package/lib/slugger.d.ts.map +1 -1
- package/lib/slugger.js +6 -2
- package/lib/slugger.js.map +1 -1
- package/lib/tags.d.ts +42 -10
- package/lib/tags.d.ts.map +1 -1
- package/lib/tags.js +40 -26
- package/lib/tags.js.map +1 -1
- package/lib/urlUtils.d.ts +57 -0
- package/lib/urlUtils.d.ts.map +1 -1
- package/lib/urlUtils.js +132 -6
- package/lib/urlUtils.js.map +1 -1
- package/lib/webpackUtils.d.ts +5 -0
- package/lib/webpackUtils.d.ts.map +1 -1
- package/lib/webpackUtils.js +8 -5
- package/lib/webpackUtils.js.map +1 -1
- package/package.json +11 -11
- package/src/constants.ts +65 -9
- package/src/dataFileUtils.ts +44 -12
- package/src/emitUtils.ts +99 -0
- package/src/gitUtils.ts +77 -17
- package/src/globUtils.ts +34 -13
- package/src/hashUtils.ts +6 -5
- package/src/i18nUtils.ts +115 -0
- package/src/index.ts +43 -307
- package/src/jsUtils.ts +102 -0
- package/src/markdownLinks.ts +71 -28
- package/src/markdownUtils.ts +354 -0
- package/src/pathUtils.ts +15 -7
- package/src/slugger.ts +13 -1
- package/src/tags.ts +53 -28
- package/src/urlUtils.ts +145 -7
- package/src/webpackUtils.ts +11 -4
- package/lib/markdownParser.d.ts +0 -32
- package/lib/markdownParser.d.ts.map +0 -1
- package/lib/markdownParser.js +0 -161
- package/lib/markdownParser.js.map +0 -1
- package/src/markdownParser.ts +0 -201
package/lib/markdownLinks.js
CHANGED
|
@@ -8,23 +8,35 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.replaceMarkdownLinks = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
|
-
const path_1 =
|
|
11
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
12
|
+
const dataFileUtils_1 = require("./dataFileUtils");
|
|
12
13
|
const pathUtils_1 = require("./pathUtils");
|
|
14
|
+
/**
|
|
15
|
+
* Takes a Markdown file and replaces relative file references with their URL
|
|
16
|
+
* counterparts, e.g. `[link](./intro.md)` => `[link](/docs/intro)`, preserving
|
|
17
|
+
* everything else.
|
|
18
|
+
*
|
|
19
|
+
* This method uses best effort to find a matching file. The file reference can
|
|
20
|
+
* be relative to the directory of the current file (most likely) or any of the
|
|
21
|
+
* content paths (so `/tutorials/intro.md` can be resolved as
|
|
22
|
+
* `<siteDir>/docs/tutorials/intro.md`). Links that contain the `http(s):` or
|
|
23
|
+
* `@site/` prefix will always be ignored.
|
|
24
|
+
*/
|
|
13
25
|
function replaceMarkdownLinks({ siteDir, fileString, filePath, contentPaths, sourceToPermalink, }) {
|
|
14
|
-
const { contentPath, contentPathLocalized } = contentPaths;
|
|
15
26
|
const brokenMarkdownLinks = [];
|
|
16
27
|
// Replace internal markdown linking (except in fenced blocks).
|
|
17
28
|
let fencedBlock = false;
|
|
18
29
|
let lastCodeFence = '';
|
|
19
30
|
const lines = fileString.split('\n').map((line) => {
|
|
20
31
|
if (line.trim().startsWith('```')) {
|
|
32
|
+
const codeFence = line.trim().match(/^`+/)[0];
|
|
21
33
|
if (!fencedBlock) {
|
|
22
34
|
fencedBlock = true;
|
|
23
|
-
|
|
35
|
+
lastCodeFence = codeFence;
|
|
24
36
|
// If we are in a ````-fenced block, all ``` would be plain text instead
|
|
25
37
|
// of fences
|
|
26
38
|
}
|
|
27
|
-
else if (
|
|
39
|
+
else if (codeFence.length >= lastCodeFence.length) {
|
|
28
40
|
fencedBlock = false;
|
|
29
41
|
}
|
|
30
42
|
}
|
|
@@ -33,20 +45,24 @@ function replaceMarkdownLinks({ siteDir, fileString, filePath, contentPaths, sou
|
|
|
33
45
|
}
|
|
34
46
|
let modifiedLine = line;
|
|
35
47
|
// Replace inline-style links or reference-style links e.g:
|
|
36
|
-
// This is [Document 1](doc1.md)
|
|
37
|
-
//
|
|
38
|
-
|
|
39
|
-
const mdRegex = /(?:(?:\]\()|(?:\]:\s*))(?!https?:\/\/|@site\/)(?<filename>[^'")\]\s>]+\.mdx?)/g;
|
|
48
|
+
// This is [Document 1](doc1.md)
|
|
49
|
+
// [doc1]: doc1.md
|
|
50
|
+
const mdRegex = /(?:\]\(|\]:\s*)(?!https?:\/\/|@site\/)(?<filename>[^'")\]\s>]+\.mdx?)/g;
|
|
40
51
|
let mdMatch = mdRegex.exec(modifiedLine);
|
|
41
52
|
while (mdMatch !== null) {
|
|
42
53
|
// Replace it to correct html link.
|
|
43
54
|
const mdLink = mdMatch.groups.filename;
|
|
44
|
-
const sourcesToTry = [
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
55
|
+
const sourcesToTry = [];
|
|
56
|
+
// ./file.md and ../file.md are always relative to the current file
|
|
57
|
+
if (!mdLink.startsWith('./') && !mdLink.startsWith('../')) {
|
|
58
|
+
sourcesToTry.push(...(0, dataFileUtils_1.getContentPathList)(contentPaths), siteDir);
|
|
59
|
+
}
|
|
60
|
+
// /file.md is always relative to the content path
|
|
61
|
+
if (!mdLink.startsWith('/')) {
|
|
62
|
+
sourcesToTry.push(path_1.default.dirname(filePath));
|
|
63
|
+
}
|
|
49
64
|
const aliasedSourceMatch = sourcesToTry
|
|
65
|
+
.map((p) => path_1.default.join(p, decodeURIComponent(mdLink)))
|
|
50
66
|
.map((source) => (0, pathUtils_1.aliasedSitePath)(source, siteDir))
|
|
51
67
|
.find((source) => sourceToPermalink[source]);
|
|
52
68
|
const permalink = aliasedSourceMatch
|
package/lib/markdownLinks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdownLinks.js","sourceRoot":"","sources":["../src/markdownLinks.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,
|
|
1
|
+
{"version":3,"file":"markdownLinks.js","sourceRoot":"","sources":["../src/markdownLinks.ts"],"names":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AI,EAAE,MAAM;iBACb,CAAC;gBAEF,mBAAmB,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;aAC9C;YACD,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;SACtC;QACD,OAAO,YAAY,CAAC;IACtB,CAAC,CAAC,CAAC;IAEH,MAAM,UAAU,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAEpC,OAAO,EAAC,UAAU,EAAE,mBAAmB,EAAC,CAAC;AAC3C,CAAC;AAxGD,oDAwGC"}
|
|
@@ -0,0 +1,112 @@
|
|
|
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 SluggerOptions } from './slugger';
|
|
8
|
+
/**
|
|
9
|
+
* Parses custom ID from a heading. The ID must be composed of letters,
|
|
10
|
+
* underscores, and dashes only.
|
|
11
|
+
*
|
|
12
|
+
* @param heading e.g. `## Some heading {#some-heading}` where the last
|
|
13
|
+
* character must be `}` for the ID to be recognized
|
|
14
|
+
*/
|
|
15
|
+
export declare function parseMarkdownHeadingId(heading: string): {
|
|
16
|
+
/**
|
|
17
|
+
* The heading content sans the ID part, right-trimmed. e.g. `## Some heading`
|
|
18
|
+
*/
|
|
19
|
+
text: string;
|
|
20
|
+
/** The heading ID. e.g. `some-heading` */
|
|
21
|
+
id?: string;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Creates an excerpt of a Markdown file. This function will:
|
|
25
|
+
*
|
|
26
|
+
* - Ignore h1 headings (setext or atx)
|
|
27
|
+
* - Ignore import/export
|
|
28
|
+
* - Ignore code blocks
|
|
29
|
+
*
|
|
30
|
+
* And for the first contentful line, it will strip away most Markdown
|
|
31
|
+
* syntax, including HTML tags, emphasis, links (keeping the text), etc.
|
|
32
|
+
*/
|
|
33
|
+
export declare function createExcerpt(fileString: string): string | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Takes a raw Markdown file content, and parses the front matter using
|
|
36
|
+
* gray-matter. Worth noting that gray-matter accepts TOML and other markup
|
|
37
|
+
* languages as well.
|
|
38
|
+
*
|
|
39
|
+
* @throws Throws when gray-matter throws. e.g.:
|
|
40
|
+
* ```md
|
|
41
|
+
* ---
|
|
42
|
+
* foo: : bar
|
|
43
|
+
* ---
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare function parseFrontMatter(markdownFileContent: string): {
|
|
47
|
+
/** Front matter as parsed by gray-matter. */
|
|
48
|
+
frontMatter: {
|
|
49
|
+
[key: string]: unknown;
|
|
50
|
+
};
|
|
51
|
+
/** The remaining content, trimmed. */
|
|
52
|
+
content: string;
|
|
53
|
+
};
|
|
54
|
+
declare type ParseMarkdownContentTitleOptions = {
|
|
55
|
+
/**
|
|
56
|
+
* If `true`, the matching title will be removed from the returned content.
|
|
57
|
+
* We can promise that at least one empty line will be left between the
|
|
58
|
+
* content before and after, but you shouldn't make too much assumption
|
|
59
|
+
* about what's left.
|
|
60
|
+
*/
|
|
61
|
+
removeContentTitle?: boolean;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Takes the raw Markdown content, without front matter, and tries to find an h1
|
|
65
|
+
* title (setext or atx) to be used as metadata.
|
|
66
|
+
*
|
|
67
|
+
* It only searches until the first contentful paragraph, ignoring import/export
|
|
68
|
+
* declarations.
|
|
69
|
+
*
|
|
70
|
+
* It will try to convert markdown to reasonable text, but won't be best effort,
|
|
71
|
+
* since it's only used as a fallback when `frontMatter.title` is not provided.
|
|
72
|
+
* For now, we just unwrap inline code (``# `config.js` `` => `config.js`).
|
|
73
|
+
*/
|
|
74
|
+
export declare function parseMarkdownContentTitle(contentUntrimmed: string, options?: ParseMarkdownContentTitleOptions): {
|
|
75
|
+
/** The content, optionally without the content title. */
|
|
76
|
+
content: string;
|
|
77
|
+
/** The title, trimmed and without the `#`. */
|
|
78
|
+
contentTitle: string | undefined;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Makes a full-round parse.
|
|
82
|
+
*
|
|
83
|
+
* @throws Throws when `parseFrontMatter` throws, usually because of invalid
|
|
84
|
+
* syntax.
|
|
85
|
+
*/
|
|
86
|
+
export declare function parseMarkdownString(markdownFileContent: string, options?: ParseMarkdownContentTitleOptions): {
|
|
87
|
+
/** @see {@link parseFrontMatter} */
|
|
88
|
+
frontMatter: {
|
|
89
|
+
[key: string]: unknown;
|
|
90
|
+
};
|
|
91
|
+
/** @see {@link parseMarkdownContentTitle} */
|
|
92
|
+
contentTitle: string | undefined;
|
|
93
|
+
/** @see {@link createExcerpt} */
|
|
94
|
+
excerpt: string | undefined;
|
|
95
|
+
/**
|
|
96
|
+
* Content without front matter and (optionally) without title, depending on
|
|
97
|
+
* the `removeContentTitle` option.
|
|
98
|
+
*/
|
|
99
|
+
content: string;
|
|
100
|
+
};
|
|
101
|
+
export declare type WriteHeadingIDOptions = SluggerOptions & {
|
|
102
|
+
/** Overwrite existing heading IDs. */
|
|
103
|
+
overwrite?: boolean;
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Takes Markdown content, returns new content with heading IDs written.
|
|
107
|
+
* Respects existing IDs (unless `overwrite=true`) and never generates colliding
|
|
108
|
+
* IDs (through the slugger).
|
|
109
|
+
*/
|
|
110
|
+
export declare function writeMarkdownHeadingId(content: string, options?: WriteHeadingIDOptions): string;
|
|
111
|
+
export {};
|
|
112
|
+
//# sourceMappingURL=markdownUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdownUtils.d.ts","sourceRoot":"","sources":["../src/markdownUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAA8B,KAAK,cAAc,EAAC,MAAM,WAAW,CAAC;AAM3E;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,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AAEF;;;;GAIG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,qBAA+D,GACvE,MAAM,CAoCR"}
|
|
@@ -0,0 +1,271 @@
|
|
|
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.writeMarkdownHeadingId = exports.parseMarkdownString = exports.parseMarkdownContentTitle = exports.parseFrontMatter = exports.createExcerpt = exports.parseMarkdownHeadingId = void 0;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
12
|
+
const gray_matter_1 = tslib_1.__importDefault(require("gray-matter"));
|
|
13
|
+
const slugger_1 = require("./slugger");
|
|
14
|
+
// Some utilities for parsing Markdown content. These things are only used on
|
|
15
|
+
// server-side when we infer metadata like `title` and `description` from the
|
|
16
|
+
// content. Most parsing is still done in MDX through the mdx-loader.
|
|
17
|
+
/**
|
|
18
|
+
* Parses custom ID from a heading. The ID must be composed of letters,
|
|
19
|
+
* underscores, and dashes only.
|
|
20
|
+
*
|
|
21
|
+
* @param heading e.g. `## Some heading {#some-heading}` where the last
|
|
22
|
+
* character must be `}` for the ID to be recognized
|
|
23
|
+
*/
|
|
24
|
+
function parseMarkdownHeadingId(heading) {
|
|
25
|
+
const customHeadingIdRegex = /\s*\{#(?<id>[\w-]+)\}$/;
|
|
26
|
+
const matches = customHeadingIdRegex.exec(heading);
|
|
27
|
+
if (matches) {
|
|
28
|
+
return {
|
|
29
|
+
text: heading.replace(matches[0], ''),
|
|
30
|
+
id: matches.groups.id,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
return { text: heading, id: undefined };
|
|
34
|
+
}
|
|
35
|
+
exports.parseMarkdownHeadingId = parseMarkdownHeadingId;
|
|
36
|
+
// TODO: Find a better way to do so, possibly by compiling the Markdown content,
|
|
37
|
+
// stripping out HTML tags and obtaining the first line.
|
|
38
|
+
/**
|
|
39
|
+
* Creates an excerpt of a Markdown file. This function will:
|
|
40
|
+
*
|
|
41
|
+
* - Ignore h1 headings (setext or atx)
|
|
42
|
+
* - Ignore import/export
|
|
43
|
+
* - Ignore code blocks
|
|
44
|
+
*
|
|
45
|
+
* And for the first contentful line, it will strip away most Markdown
|
|
46
|
+
* syntax, including HTML tags, emphasis, links (keeping the text), etc.
|
|
47
|
+
*/
|
|
48
|
+
function createExcerpt(fileString) {
|
|
49
|
+
const fileLines = fileString
|
|
50
|
+
.trimStart()
|
|
51
|
+
// Remove Markdown alternate title
|
|
52
|
+
.replace(/^[^\n]*\n[=]+/g, '')
|
|
53
|
+
.split('\n');
|
|
54
|
+
let inCode = false;
|
|
55
|
+
let inImport = false;
|
|
56
|
+
let lastCodeFence = '';
|
|
57
|
+
for (const fileLine of fileLines) {
|
|
58
|
+
if (fileLine === '' && inImport) {
|
|
59
|
+
inImport = false;
|
|
60
|
+
}
|
|
61
|
+
// Skip empty line.
|
|
62
|
+
if (!fileLine.trim()) {
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
// Skip import/export declaration.
|
|
66
|
+
if ((/^(?:import|export)\s.*/.test(fileLine) || inImport) && !inCode) {
|
|
67
|
+
inImport = true;
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
// Skip code block line.
|
|
71
|
+
if (fileLine.trim().startsWith('```')) {
|
|
72
|
+
const codeFence = fileLine.trim().match(/^`+/)[0];
|
|
73
|
+
if (!inCode) {
|
|
74
|
+
inCode = true;
|
|
75
|
+
lastCodeFence = codeFence;
|
|
76
|
+
// If we are in a ````-fenced block, all ``` would be plain text instead
|
|
77
|
+
// of fences
|
|
78
|
+
}
|
|
79
|
+
else if (codeFence.length >= lastCodeFence.length) {
|
|
80
|
+
inCode = false;
|
|
81
|
+
}
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
else if (inCode) {
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
const cleanedLine = fileLine
|
|
88
|
+
// Remove HTML tags.
|
|
89
|
+
.replace(/<[^>]*>/g, '')
|
|
90
|
+
// Remove Title headers
|
|
91
|
+
.replace(/^#[^#]+#?/gm, '')
|
|
92
|
+
// Remove Markdown + ATX-style headers
|
|
93
|
+
.replace(/^#{1,6}\s*(?<text>[^#]*)\s*#{0,6}/gm, '$1')
|
|
94
|
+
// Remove emphasis.
|
|
95
|
+
.replace(/(?<opening>[*_]{1,3})(?<text>.*?)\1/g, '$2')
|
|
96
|
+
// Remove strikethroughs.
|
|
97
|
+
.replace(/~~(?<text>\S.*\S)~~/g, '$1')
|
|
98
|
+
// Remove images.
|
|
99
|
+
.replace(/!\[(?<alt>.*?)\][[(].*?[\])]/g, '$1')
|
|
100
|
+
// Remove footnotes.
|
|
101
|
+
.replace(/\[\^.+?\](?:: .*$)?/g, '')
|
|
102
|
+
// Remove inline links.
|
|
103
|
+
.replace(/\[(?<alt>.*?)\][[(].*?[\])]/g, '$1')
|
|
104
|
+
// Remove inline code.
|
|
105
|
+
.replace(/`(?<text>.+?)`/g, '$1')
|
|
106
|
+
// Remove blockquotes.
|
|
107
|
+
.replace(/^\s{0,3}>\s?/g, '')
|
|
108
|
+
// Remove admonition definition.
|
|
109
|
+
.replace(/:::.*/, '')
|
|
110
|
+
// Remove Emoji names within colons include preceding whitespace.
|
|
111
|
+
.replace(/\s?:(?:::|[^:\n])+:/g, '')
|
|
112
|
+
// Remove custom Markdown heading id.
|
|
113
|
+
.replace(/\{#*[\w-]+\}/, '')
|
|
114
|
+
.trim();
|
|
115
|
+
if (cleanedLine) {
|
|
116
|
+
return cleanedLine;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
121
|
+
exports.createExcerpt = createExcerpt;
|
|
122
|
+
/**
|
|
123
|
+
* Takes a raw Markdown file content, and parses the front matter using
|
|
124
|
+
* gray-matter. Worth noting that gray-matter accepts TOML and other markup
|
|
125
|
+
* languages as well.
|
|
126
|
+
*
|
|
127
|
+
* @throws Throws when gray-matter throws. e.g.:
|
|
128
|
+
* ```md
|
|
129
|
+
* ---
|
|
130
|
+
* foo: : bar
|
|
131
|
+
* ---
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
function parseFrontMatter(markdownFileContent) {
|
|
135
|
+
const { data, content } = (0, gray_matter_1.default)(markdownFileContent);
|
|
136
|
+
return {
|
|
137
|
+
frontMatter: data,
|
|
138
|
+
content: content.trim(),
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
exports.parseFrontMatter = parseFrontMatter;
|
|
142
|
+
function toTextContentTitle(contentTitle) {
|
|
143
|
+
if (contentTitle.startsWith('`') && contentTitle.endsWith('`')) {
|
|
144
|
+
return contentTitle.substring(1, contentTitle.length - 1);
|
|
145
|
+
}
|
|
146
|
+
return contentTitle;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Takes the raw Markdown content, without front matter, and tries to find an h1
|
|
150
|
+
* title (setext or atx) to be used as metadata.
|
|
151
|
+
*
|
|
152
|
+
* It only searches until the first contentful paragraph, ignoring import/export
|
|
153
|
+
* declarations.
|
|
154
|
+
*
|
|
155
|
+
* It will try to convert markdown to reasonable text, but won't be best effort,
|
|
156
|
+
* since it's only used as a fallback when `frontMatter.title` is not provided.
|
|
157
|
+
* For now, we just unwrap inline code (``# `config.js` `` => `config.js`).
|
|
158
|
+
*/
|
|
159
|
+
function parseMarkdownContentTitle(contentUntrimmed, options) {
|
|
160
|
+
const removeContentTitleOption = options?.removeContentTitle ?? false;
|
|
161
|
+
const content = contentUntrimmed.trim();
|
|
162
|
+
// We only need to detect import statements that will be parsed by MDX as
|
|
163
|
+
// `import` nodes, as broken syntax can't render anyways. That means any block
|
|
164
|
+
// that has `import` at the very beginning and surrounded by empty lines.
|
|
165
|
+
const contentWithoutImport = content
|
|
166
|
+
.replace(/^(?:import\s(?:.|\r?\n(?!\r?\n))*(?:\r?\n){2,})*/, '')
|
|
167
|
+
.trim();
|
|
168
|
+
const regularTitleMatch = /^#[ \t]+(?<title>[^ \t].*)(?:\r?\n|$)/.exec(contentWithoutImport);
|
|
169
|
+
const alternateTitleMatch = /^(?<title>.*)\r?\n=+(?:\r?\n|$)/.exec(contentWithoutImport);
|
|
170
|
+
const titleMatch = regularTitleMatch ?? alternateTitleMatch;
|
|
171
|
+
if (!titleMatch) {
|
|
172
|
+
return { content, contentTitle: undefined };
|
|
173
|
+
}
|
|
174
|
+
const newContent = removeContentTitleOption
|
|
175
|
+
? content.replace(titleMatch[0], '')
|
|
176
|
+
: content;
|
|
177
|
+
if (regularTitleMatch) {
|
|
178
|
+
return {
|
|
179
|
+
content: newContent.trim(),
|
|
180
|
+
contentTitle: toTextContentTitle(regularTitleMatch
|
|
181
|
+
.groups.title.trim()
|
|
182
|
+
.replace(/\s*(?:\{#*[\w-]+\}|#+)$/, '')).trim(),
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
return {
|
|
186
|
+
content: newContent.trim(),
|
|
187
|
+
contentTitle: toTextContentTitle(alternateTitleMatch.groups.title.trim().replace(/\s*=+$/, '')).trim(),
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
exports.parseMarkdownContentTitle = parseMarkdownContentTitle;
|
|
191
|
+
/**
|
|
192
|
+
* Makes a full-round parse.
|
|
193
|
+
*
|
|
194
|
+
* @throws Throws when `parseFrontMatter` throws, usually because of invalid
|
|
195
|
+
* syntax.
|
|
196
|
+
*/
|
|
197
|
+
function parseMarkdownString(markdownFileContent, options) {
|
|
198
|
+
try {
|
|
199
|
+
const { frontMatter, content: contentWithoutFrontMatter } = parseFrontMatter(markdownFileContent);
|
|
200
|
+
const { content, contentTitle } = parseMarkdownContentTitle(contentWithoutFrontMatter, options);
|
|
201
|
+
const excerpt = createExcerpt(content);
|
|
202
|
+
return {
|
|
203
|
+
frontMatter,
|
|
204
|
+
content,
|
|
205
|
+
contentTitle,
|
|
206
|
+
excerpt,
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
catch (err) {
|
|
210
|
+
logger_1.default.error(`Error while parsing Markdown front matter.
|
|
211
|
+
This can happen if you use special characters in front matter values (try using double quotes around that value).`);
|
|
212
|
+
throw err;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
exports.parseMarkdownString = parseMarkdownString;
|
|
216
|
+
function unwrapMarkdownLinks(line) {
|
|
217
|
+
return line.replace(/\[(?<alt>[^\]]+)\]\([^)]+\)/g, (match, p1) => p1);
|
|
218
|
+
}
|
|
219
|
+
function addHeadingId(line, slugger, maintainCase) {
|
|
220
|
+
let headingLevel = 0;
|
|
221
|
+
while (line.charAt(headingLevel) === '#') {
|
|
222
|
+
headingLevel += 1;
|
|
223
|
+
}
|
|
224
|
+
const headingText = line.slice(headingLevel).trimEnd();
|
|
225
|
+
const headingHashes = line.slice(0, headingLevel);
|
|
226
|
+
const slug = slugger.slug(unwrapMarkdownLinks(headingText).trim(), {
|
|
227
|
+
maintainCase,
|
|
228
|
+
});
|
|
229
|
+
return `${headingHashes}${headingText} {#${slug}}`;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Takes Markdown content, returns new content with heading IDs written.
|
|
233
|
+
* Respects existing IDs (unless `overwrite=true`) and never generates colliding
|
|
234
|
+
* IDs (through the slugger).
|
|
235
|
+
*/
|
|
236
|
+
function writeMarkdownHeadingId(content, options = { maintainCase: false, overwrite: false }) {
|
|
237
|
+
const { maintainCase = false, overwrite = false } = options;
|
|
238
|
+
const lines = content.split('\n');
|
|
239
|
+
const slugger = (0, slugger_1.createSlugger)();
|
|
240
|
+
// If we can't overwrite existing slugs, make sure other headings don't
|
|
241
|
+
// generate colliding slugs by first marking these slugs as occupied
|
|
242
|
+
if (!overwrite) {
|
|
243
|
+
lines.forEach((line) => {
|
|
244
|
+
const parsedHeading = parseMarkdownHeadingId(line);
|
|
245
|
+
if (parsedHeading.id) {
|
|
246
|
+
slugger.slug(parsedHeading.id);
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
let inCode = false;
|
|
251
|
+
return lines
|
|
252
|
+
.map((line) => {
|
|
253
|
+
if (line.startsWith('```')) {
|
|
254
|
+
inCode = !inCode;
|
|
255
|
+
return line;
|
|
256
|
+
}
|
|
257
|
+
// Ignore h1 headings, as we don't create anchor links for those
|
|
258
|
+
if (inCode || !line.startsWith('##')) {
|
|
259
|
+
return line;
|
|
260
|
+
}
|
|
261
|
+
const parsedHeading = parseMarkdownHeadingId(line);
|
|
262
|
+
// Do not process if id is already there
|
|
263
|
+
if (parsedHeading.id && !overwrite) {
|
|
264
|
+
return line;
|
|
265
|
+
}
|
|
266
|
+
return addHeadingId(parsedHeading.text, slugger, maintainCase);
|
|
267
|
+
})
|
|
268
|
+
.join('\n');
|
|
269
|
+
}
|
|
270
|
+
exports.writeMarkdownHeadingId = writeMarkdownHeadingId;
|
|
271
|
+
//# sourceMappingURL=markdownUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdownUtils.js","sourceRoot":"","sources":["../src/markdownUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,wEAAwC;AACxC,sEAAiC;AACjC,uCAA2E;AAE3E,6EAA6E;AAC7E,6EAA6E;AAC7E,qEAAqE;AAErE;;;;;;GAMG;AACH,SAAgB,sBAAsB,CAAC,OAAe;IAQpD,MAAM,oBAAoB,GAAG,wBAAwB,CAAC;IACtD,MAAM,OAAO,GAAG,oBAAoB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACnD,IAAI,OAAO,EAAE;QACX,OAAO;YACL,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAE,EAAE,EAAE,CAAC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AI,MAAM,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;YACpC,OAAO,IAAI,CAAC;SACb;QACD,MAAM,aAAa,GAAG,sBAAsB,CAAC,IAAI,CAAC,CAAC;QAEnD,wCAAwC;QACxC,IAAI,aAAa,CAAC,EAAE,IAAI,CAAC,SAAS,EAAE;YAClC,OAAO,IAAI,CAAC;SACb;QACD,OAAO,YAAY,CAAC,aAAa,CAAC,IAAI,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;IACjE,CAAC,CAAC;SACD,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC;AAvCD,wDAuCC"}
|
package/lib/pathUtils.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
export declare const isNameTooLong: (str: string) => boolean;
|
|
8
|
-
export declare
|
|
8
|
+
export declare function shortName(str: string): string;
|
|
9
9
|
/**
|
|
10
10
|
* Convert Windows backslash paths to posix style paths.
|
|
11
11
|
* E.g: endi\lie -> endi/lie
|
|
@@ -48,4 +48,5 @@ export declare function aliasedSitePath(filePath: string, siteDir: string): stri
|
|
|
48
48
|
* doesn't escape those that fail to be converted.
|
|
49
49
|
*/
|
|
50
50
|
export declare function escapePath(str: string): string;
|
|
51
|
+
export declare function addTrailingPathSeparator(str: string): string;
|
|
51
52
|
//# sourceMappingURL=pathUtils.d.ts.map
|
package/lib/pathUtils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pathUtils.d.ts","sourceRoot":"","sources":["../src/pathUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"pathUtils.d.ts","sourceRoot":"","sources":["../src/pathUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAeH,eAAO,MAAM,aAAa,QAAS,MAAM,KAAG,OAMgC,CAAC;AAE7E,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAiB7C;AAED;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAY7C;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAElE;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAKzE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAK9C;AAED,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAK5D"}
|
package/lib/pathUtils.js
CHANGED
|
@@ -6,11 +6,11 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.escapePath = exports.aliasedSitePath = exports.toMessageRelativeFilePath = exports.posixPath = exports.shortName = exports.isNameTooLong = void 0;
|
|
9
|
+
exports.addTrailingPathSeparator = exports.escapePath = exports.aliasedSitePath = exports.toMessageRelativeFilePath = exports.posixPath = exports.shortName = exports.isNameTooLong = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
11
12
|
// Based on https://github.com/gatsbyjs/gatsby/pull/21518/files
|
|
12
|
-
|
|
13
|
-
// MacOS (APFS) and Windows (NTFS) filename length limit = 255 chars,
|
|
13
|
+
// macOS (APFS) and Windows (NTFS) filename length limit = 255 chars,
|
|
14
14
|
// Others = 255 bytes
|
|
15
15
|
const MAX_PATH_SEGMENT_CHARS = 255;
|
|
16
16
|
const MAX_PATH_SEGMENT_BYTES = 255;
|
|
@@ -21,10 +21,12 @@ const isWindows = () => process.platform === 'win32';
|
|
|
21
21
|
const isNameTooLong = (str) =>
|
|
22
22
|
// Not entirely correct: we can't assume FS from OS. But good enough?
|
|
23
23
|
isMacOs() || isWindows()
|
|
24
|
-
?
|
|
25
|
-
|
|
24
|
+
? // Windows (NTFS) and macOS (APFS) filename length limit (255 chars)
|
|
25
|
+
str.length + SPACE_FOR_APPENDING > MAX_PATH_SEGMENT_CHARS
|
|
26
|
+
: // Other (255 bytes)
|
|
27
|
+
Buffer.from(str).length + SPACE_FOR_APPENDING > MAX_PATH_SEGMENT_BYTES;
|
|
26
28
|
exports.isNameTooLong = isNameTooLong;
|
|
27
|
-
|
|
29
|
+
function shortName(str) {
|
|
28
30
|
if (isMacOs() || isWindows()) {
|
|
29
31
|
const overflowingChars = str.length - MAX_PATH_SEGMENT_CHARS;
|
|
30
32
|
return str.slice(0, str.length - overflowingChars - SPACE_FOR_APPENDING - 1);
|
|
@@ -34,7 +36,7 @@ const shortName = (str) => {
|
|
|
34
36
|
return strBuffer
|
|
35
37
|
.slice(0, Buffer.byteLength(strBuffer) - overflowingBytes - SPACE_FOR_APPENDING - 1)
|
|
36
38
|
.toString();
|
|
37
|
-
}
|
|
39
|
+
}
|
|
38
40
|
exports.shortName = shortName;
|
|
39
41
|
/**
|
|
40
42
|
* Convert Windows backslash paths to posix style paths.
|
|
@@ -103,4 +105,11 @@ function escapePath(str) {
|
|
|
103
105
|
return escaped.substring(1, escaped.length - 1);
|
|
104
106
|
}
|
|
105
107
|
exports.escapePath = escapePath;
|
|
108
|
+
function addTrailingPathSeparator(str) {
|
|
109
|
+
return str.endsWith(path_1.default.sep)
|
|
110
|
+
? str
|
|
111
|
+
: // If this is Windows, we need to change the forward slash to backward
|
|
112
|
+
`${str.replace(/\/$/, '')}${path_1.default.sep}`;
|
|
113
|
+
}
|
|
114
|
+
exports.addTrailingPathSeparator = addTrailingPathSeparator;
|
|
106
115
|
//# sourceMappingURL=pathUtils.js.map
|
package/lib/pathUtils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pathUtils.js","sourceRoot":"","sources":["../src/pathUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,+DAA+D;
|
|
1
|
+
{"version":3,"file":"pathUtils.js","sourceRoot":"","sources":["../src/pathUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,wDAAwB;AAExB,+DAA+D;AAC/D,qEAAqE;AACrE,qBAAqB;AACrB,MAAM,sBAAsB,GAAG,GAAG,CAAC;AACnC,MAAM,sBAAsB,GAAG,GAAG,CAAC;AACnC,0EAA0E;AAC1E,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAE/B,MAAM,OAAO,GAAG,GAAG,EAAE,CAAC,OAAO,CAAC,QAAQ,KAAK,QAAQ,CAAC;AACpD,MAAM,SAAS,GAAG,GAAG,EAAE,CAAC,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC;AAE9C,MAAM,aAAa,GAAG,CAAC,GAAW,EAAW,EAAE;AACpD,qEAAqE;AACrE,OAAO,EAAE,IAAI,SAAS,EAAE;IACtB,CAAC,CAAC,oEAAoE;QACpE,GAAG,CAAC,MAAM,GAAG,mBAAmB,GAAG,sBAAsB;IAC3D,CAAC,CAAC,oBAAoB;QACpB,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,GAAG,mBAAmB,GAAG,sBAAsB,CAAC;AANhE,QAAA,aAAa,iBAMmD;AAE7E,SAAgB,SAAS,CAAC,GAAW;IACnC,IAAI,OAAO,EAAE,IAAI,SAAS,EAAE,EAAE;QAC5B,MAAM,gBAAgB,GAAG,GAAG,CAAC,MAAM,GAAG,sBAAsB,CAAC;QAC7D,OAAO,GAAG,CAAC,KAAK,CACd,CAAC,EACD,GAAG,CAAC,MAAM,GAAG,gBAAgB,GAAG,mBAAmB,GAAG,CAAC,CACxD,CAAC;KACH;IACD,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACnC,MAAM,gBAAgB,GACpB,MAAM,CAAC,U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AE,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AAClD,CAAC;AALD,gCAKC;AAED,SAAgB,wBAAwB,CAAC,GAAW;IAClD,OAAO,GAAG,CAAC,QAAQ,CAAC,cAAI,CAAC,GAAG,CAAC;QAC3B,CAAC,CAAC,GAAG;QACL,CAAC,CAAC,sEAAsE;YACtE,GAAG,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,GAAG,cAAI,CAAC,GAAG,EAAE,CAAC;AAC7C,CAAC;AALD,4DAKC"}
|
package/lib/slugger.d.ts
CHANGED
|
@@ -5,10 +5,20 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
export declare type SluggerOptions = {
|
|
8
|
+
/** Keep the headings' casing, otherwise make all lowercase. */
|
|
8
9
|
maintainCase?: boolean;
|
|
9
10
|
};
|
|
10
11
|
export declare type Slugger = {
|
|
12
|
+
/**
|
|
13
|
+
* Takes a Markdown heading like "Josh Cena" and sluggifies it according to
|
|
14
|
+
* GitHub semantics (in this case `josh-cena`). Stateful, because if you try
|
|
15
|
+
* to sluggify "Josh Cena" again it would return `josh-cena-1`.
|
|
16
|
+
*/
|
|
11
17
|
slug: (value: string, options?: SluggerOptions) => string;
|
|
12
18
|
};
|
|
19
|
+
/**
|
|
20
|
+
* A thin wrapper around github-slugger. This is a factory function that returns
|
|
21
|
+
* a stateful Slugger object.
|
|
22
|
+
*/
|
|
13
23
|
export declare function createSlugger(): Slugger;
|
|
14
24
|
//# sourceMappingURL=slugger.d.ts.map
|
package/lib/slugger.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slugger.d.ts","sourceRoot":"","sources":["../src/slugger.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH,oBAAY,cAAc,GAAG;
|
|
1
|
+
{"version":3,"file":"slugger.d.ts","sourceRoot":"","sources":["../src/slugger.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH,oBAAY,cAAc,GAAG;IAC3B,+DAA+D;IAC/D,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB,CAAC;AAEF,oBAAY,OAAO,GAAG;IACpB;;;;OAIG;IACH,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,KAAK,MAAM,CAAC;CAC3D,CAAC;AAEF;;;GAGG;AACH,wBAAgB,aAAa,IAAI,OAAO,CAKvC"}
|
package/lib/slugger.js
CHANGED
|
@@ -8,11 +8,15 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.createSlugger = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
|
-
const github_slugger_1 =
|
|
11
|
+
const github_slugger_1 = tslib_1.__importDefault(require("github-slugger"));
|
|
12
|
+
/**
|
|
13
|
+
* A thin wrapper around github-slugger. This is a factory function that returns
|
|
14
|
+
* a stateful Slugger object.
|
|
15
|
+
*/
|
|
12
16
|
function createSlugger() {
|
|
13
17
|
const githubSlugger = new github_slugger_1.default();
|
|
14
18
|
return {
|
|
15
|
-
slug: (value, options) => githubSlugger.slug(value, options
|
|
19
|
+
slug: (value, options) => githubSlugger.slug(value, options?.maintainCase),
|
|
16
20
|
};
|
|
17
21
|
}
|
|
18
22
|
exports.createSlugger = createSlugger;
|
package/lib/slugger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slugger.js","sourceRoot":"","sources":["../src/slugger.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,
|
|
1
|
+
{"version":3,"file":"slugger.js","sourceRoot":"","sources":["../src/slugger.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,4EAA2C;AAmB3C;;;GAGG;AACH,SAAgB,aAAa;IAC3B,MAAM,aAAa,GAAG,IAAI,wBAAa,EAAE,CAAC;IAC1C,OAAO;QACL,IAAI,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,YAAY,CAAC;KAC3E,CAAC;AACJ,CAAC;AALD,sCAKC"}
|