@docusaurus/mdx-loader 0.0.0-5091 → 0.0.0-5094

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/loader.d.ts CHANGED
@@ -6,11 +6,13 @@
6
6
  */
7
7
  import type { LoaderContext } from 'webpack';
8
8
  import type { Plugin } from 'unified';
9
+ import type { AdmonitionOptions } from './remark/admonitions';
9
10
  export declare type MDXPlugin = [
10
11
  Plugin<any[]>,
11
12
  any
12
13
  ] | Plugin<any[]>;
13
14
  export declare type MDXOptions = {
15
+ admonitions: boolean | AdmonitionOptions;
14
16
  remarkPlugins: MDXPlugin[];
15
17
  rehypePlugins: MDXPlugin[];
16
18
  beforeDefaultRemarkPlugins: MDXPlugin[];
@@ -1 +1 @@
1
- {"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAoBH,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,SAAS,CAAC;AAC3C,OAAO,KAAK,EAAY,MAAM,EAAC,MAAM,SAAS,CAAC;AAqB/C,oBAAY,SAAS,GAEnB;IAAC,MAAM,CAAC,GAAG,EAAE,CAAC;IAAE,GAAG;CAAC,GAAG,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC;AACvC,oBAAY,UAAU,GAAG;IACvB,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;AAEF,oBAAY,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,GAAG;IAC1C,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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CAAC,GAAG;IAC1C,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;IAC/B,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AA8EF,wBAAsB,SAAS,CAC7B,IAAI,EAAE,aAAa,CAAC,OAAO,CAAC,EAC5B,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,IAAI,CAAC,CA8Hf"}
package/lib/loader.js CHANGED
@@ -19,6 +19,7 @@ const toc_1 = tslib_1.__importDefault(require("./remark/toc"));
19
19
  const unwrapMdxCodeBlocks_1 = tslib_1.__importDefault(require("./remark/unwrapMdxCodeBlocks"));
20
20
  const transformImage_1 = tslib_1.__importDefault(require("./remark/transformImage"));
21
21
  const transformLinks_1 = tslib_1.__importDefault(require("./remark/transformLinks"));
22
+ const admonitions_1 = tslib_1.__importDefault(require("./remark/admonitions"));
22
23
  const { loaders: { inlineMarkdownImageFileLoader }, } = (0, utils_1.getFileLoaderUtils)();
23
24
  const pragma = `
24
25
  /* @jsxRuntime classic */
@@ -26,6 +27,7 @@ const pragma = `
26
27
  /* @jsxFrag React.Fragment */
27
28
  `;
28
29
  const DEFAULT_OPTIONS = {
30
+ admonitions: true,
29
31
  rehypePlugins: [],
30
32
  remarkPlugins: [unwrapMdxCodeBlocks_1.default, remark_emoji_1.default, headings_1.default, toc_1.default],
31
33
  beforeDefaultRemarkPlugins: [],
@@ -86,6 +88,15 @@ function createAssetsExportCode(assets) {
86
88
  .filter(Boolean);
87
89
  return `{\n${codeLines.join('\n')}\n}`;
88
90
  }
91
+ function getAdmonitionsPlugins(admonitionsOption) {
92
+ if (admonitionsOption) {
93
+ const plugin = admonitionsOption === true
94
+ ? admonitions_1.default
95
+ : [admonitions_1.default, admonitionsOption];
96
+ return [plugin];
97
+ }
98
+ return [];
99
+ }
89
100
  async function mdxLoader(fileString) {
90
101
  const callback = this.async();
91
102
  const filePath = this.resourcePath;
@@ -96,32 +107,35 @@ async function mdxLoader(fileString) {
96
107
  });
97
108
  const hasFrontMatter = Object.keys(frontMatter).length > 0;
98
109
  if (!compilerCache.has(this.query)) {
99
- const options = {
100
- ...reqOptions,
101
- remarkPlugins: [
102
- ...(reqOptions.beforeDefaultRemarkPlugins ?? []),
103
- ...DEFAULT_OPTIONS.remarkPlugins,
104
- [
105
- transformImage_1.default,
106
- {
107
- staticDirs: reqOptions.staticDirs,
108
- siteDir: reqOptions.siteDir,
109
- },
110
- ],
111
- [
112
- transformLinks_1.default,
113
- {
114
- staticDirs: reqOptions.staticDirs,
115
- siteDir: reqOptions.siteDir,
116
- },
117
- ],
118
- ...(reqOptions.remarkPlugins ?? []),
110
+ const remarkPlugins = [
111
+ ...(reqOptions.beforeDefaultRemarkPlugins ?? []),
112
+ ...getAdmonitionsPlugins(reqOptions.admonitions ?? false),
113
+ ...DEFAULT_OPTIONS.remarkPlugins,
114
+ [
115
+ transformImage_1.default,
116
+ {
117
+ staticDirs: reqOptions.staticDirs,
118
+ siteDir: reqOptions.siteDir,
119
+ },
119
120
  ],
120
- rehypePlugins: [
121
- ...(reqOptions.beforeDefaultRehypePlugins ?? []),
122
- ...DEFAULT_OPTIONS.rehypePlugins,
123
- ...(reqOptions.rehypePlugins ?? []),
121
+ [
122
+ transformLinks_1.default,
123
+ {
124
+ staticDirs: reqOptions.staticDirs,
125
+ siteDir: reqOptions.siteDir,
126
+ },
124
127
  ],
128
+ ...(reqOptions.remarkPlugins ?? []),
129
+ ];
130
+ const rehypePlugins = [
131
+ ...(reqOptions.beforeDefaultRehypePlugins ?? []),
132
+ ...DEFAULT_OPTIONS.rehypePlugins,
133
+ ...(reqOptions.rehypePlugins ?? []),
134
+ ];
135
+ const options = {
136
+ ...reqOptions,
137
+ remarkPlugins,
138
+ rehypePlugins,
125
139
  };
126
140
  compilerCache.set(this.query, [(0, mdx_1.createCompiler)(options), options]);
127
141
  }
package/lib/loader.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,gEAA0B;AAC1B,wEAAwC;AACxC,6CAK2B;AAC3B,qCAA2C;AAC3C,wEAAiC;AACjC,gFAA+C;AAE/C,yEAAyC;AACzC,+DAA+B;AAC/B,+FAA+D;AAC/D,qFAAqD;AACrD,qFAAqD;AAKrD,MAAM,EACJ,OAAO,EAAE,EAAC,6BAA6B,EAAC,GACzC,GAAG,IAAA,0BAAkB,GAAE,CAAC;AAEzB,MAAM,MAAM,GAAG;;;;CAId,CAAC;AAEF,MAAM,eAAe,GAAe;IAClC,aAAa,EAAE,EAAE;IACjB,aAAa,EAAE,CAAC,6BAAmB,EAAE,sBAAK,EAAE,kBAAQ,EAAE,aAAG,CAAC;IAC1D,0BAA0B,EAAE,EAAE;IAC9B,0BAA0B,EAAE,EAAE;CAC/B,CAAC;AAEF,MAAM,aAAa,GAAG,IAAI,GAAG,EAA0C,CAAC;AA0BxE;;;;;GAKG;AACH,KAAK,UAAU,gBAAgB,CAAC,YAAoB;IAClD,IAAI;QACF,OAAO,MAAM,kBAAE,CAAC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;KACh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+ * 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 { Plugin } from 'unified';
8
+ export declare type AdmonitionOptions = {
9
+ tag: string;
10
+ keywords: string[];
11
+ };
12
+ export declare const DefaultAdmonitionOptions: AdmonitionOptions;
13
+ declare const plugin: Plugin;
14
+ export default plugin;
15
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/remark/admonitions/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAyB,MAAM,EAAC,MAAM,SAAS,CAAC;AAK5D,oBAAY,iBAAiB,GAAG;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB,CAAC;AAEF,eAAO,MAAM,wBAAwB,EAAE,iBAatC,CAAC;AAgBF,QAAA,MAAM,MAAM,EAAE,MAoIb,CAAC;AAEF,eAAe,MAAM,CAAC"}
@@ -0,0 +1,132 @@
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.DefaultAdmonitionOptions = void 0;
10
+ const tslib_1 = require("tslib");
11
+ const unist_util_visit_1 = tslib_1.__importDefault(require("unist-util-visit"));
12
+ const NEWLINE = '\n';
13
+ exports.DefaultAdmonitionOptions = {
14
+ tag: ':::',
15
+ keywords: [
16
+ 'secondary',
17
+ 'info',
18
+ 'success',
19
+ 'danger',
20
+ 'note',
21
+ 'tip',
22
+ 'warning',
23
+ 'important',
24
+ 'caution',
25
+ ],
26
+ };
27
+ function escapeRegExp(s) {
28
+ return s.replace(/[-[\]{}()*+?.\\^$|/]/g, '\\$&');
29
+ }
30
+ function normalizeOptions(options) {
31
+ return { ...exports.DefaultAdmonitionOptions, ...options };
32
+ }
33
+ // This string value does not matter much
34
+ // It is ignored because nodes are using hName/hProperties coming from HAST
35
+ const admonitionNodeType = 'admonitionHTML';
36
+ const plugin = function plugin(optionsInput = {}) {
37
+ const options = normalizeOptions(optionsInput);
38
+ const keywords = Object.values(options.keywords).map(escapeRegExp).join('|');
39
+ const tag = escapeRegExp(options.tag);
40
+ const regex = new RegExp(`${tag}(${keywords})(?: *(.*))?\n`);
41
+ const escapeTag = new RegExp(escapeRegExp(`\\${options.tag}`), 'g');
42
+ // The tokenizer is called on blocks to determine if there is an admonition
43
+ // present and create tags for it
44
+ function blockTokenizer(eat, value, silent) {
45
+ // Stop if no match or match does not start at beginning of line
46
+ const match = regex.exec(value);
47
+ if (!match || match.index !== 0) {
48
+ return false;
49
+ }
50
+ // If silent return the match
51
+ if (silent) {
52
+ return true;
53
+ }
54
+ const now = eat.now();
55
+ const [opening, keyword, title] = match;
56
+ const food = [];
57
+ const content = [];
58
+ let newValue = value;
59
+ // consume lines until a closing tag
60
+ let idx = newValue.indexOf(NEWLINE);
61
+ while (idx !== -1) {
62
+ // grab this line and eat it
63
+ const next = newValue.indexOf(NEWLINE, idx + 1);
64
+ const line = next !== -1 ? newValue.slice(idx + 1, next) : newValue.slice(idx + 1);
65
+ food.push(line);
66
+ newValue = newValue.slice(idx + 1);
67
+ // the closing tag is NOT part of the content
68
+ if (line.startsWith(options.tag)) {
69
+ break;
70
+ }
71
+ content.push(line);
72
+ idx = newValue.indexOf(NEWLINE);
73
+ }
74
+ // consume the processed tag and replace escape sequences
75
+ const contentString = content.join(NEWLINE).replace(escapeTag, options.tag);
76
+ const add = eat(opening + food.join(NEWLINE));
77
+ // parse the content in block mode
78
+ const exit = this.enterBlock();
79
+ const contentNodes = this.tokenizeBlock(contentString, now);
80
+ exit();
81
+ const titleNodes = this.tokenizeInline(title, now);
82
+ const isSimpleTextTitle = titleNodes.length === 1 && titleNodes[0].type === 'text';
83
+ const element = {
84
+ type: admonitionNodeType,
85
+ data: {
86
+ // hName/hProperties come from HAST
87
+ // See https://github.com/syntax-tree/mdast-util-to-hast#fields-on-nodes
88
+ hName: 'admonition',
89
+ hProperties: {
90
+ ...(title && isSimpleTextTitle && { title }),
91
+ type: keyword,
92
+ },
93
+ },
94
+ children: [
95
+ // For titles containing MDX syntax: create a custom element. The theme
96
+ // component will extract it and render it nicely.
97
+ //
98
+ // Temporary workaround, because it's complex in MDX v1 to emit
99
+ // interpolated JSX prop syntax (title={<>my <code>title</code></>}).
100
+ // For this reason, we use children instead of the title prop.
101
+ title &&
102
+ !isSimpleTextTitle && {
103
+ type: admonitionNodeType,
104
+ data: {
105
+ hName: 'mdxAdmonitionTitle',
106
+ hProperties: {},
107
+ },
108
+ children: titleNodes,
109
+ },
110
+ ...contentNodes,
111
+ ].filter(Boolean),
112
+ };
113
+ return add(element);
114
+ }
115
+ // add tokenizer to parser after fenced code blocks
116
+ const Parser = this.Parser.prototype;
117
+ Parser.blockTokenizers.admonition = blockTokenizer;
118
+ Parser.blockMethods.splice(Parser.blockMethods.indexOf('fencedCode') + 1, 0, 'admonition');
119
+ Parser.interruptParagraph.splice(Parser.interruptParagraph.indexOf('fencedCode') + 1, 0, ['admonition']);
120
+ Parser.interruptList.splice(Parser.interruptList.indexOf('fencedCode') + 1, 0, ['admonition']);
121
+ Parser.interruptBlockquote.splice(Parser.interruptBlockquote.indexOf('fencedCode') + 1, 0, ['admonition']);
122
+ return (root) => {
123
+ // escape everything except admonitionHTML nodes
124
+ (0, unist_util_visit_1.default)(root, (node) => node?.type !== admonitionNodeType, (node) => {
125
+ if (node.value) {
126
+ node.value = node.value.replace(escapeTag, options.tag);
127
+ }
128
+ });
129
+ };
130
+ };
131
+ exports.default = plugin;
132
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/remark/admonitions/index.ts"],"names":[],"mappings":";AAAA;;;;;G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AAI,CAAC,MAAM,CAAC,SAAS,CAAC;IACrC,MAAM,CAAC,eAAe,CAAC,UAAU,GAAG,cAAc,CAAC;IACnD,MAAM,CAAC,YAAY,CAAC,MAAM,CACxB,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,YAAY,CAAC,GAAG,CAAC,EAC7C,CAAC,EACD,YAAY,CACb,CAAC;IACF,MAAM,CAAC,kBAAkB,CAAC,MAAM,CAC9B,MAAM,CAAC,kBAAkB,CAAC,OAAO,CAAC,YAAY,CAAC,GAAG,CAAC,EACnD,CAAC,EACD,CAAC,YAAY,CAAC,CACf,CAAC;IACF,MAAM,CAAC,aAAa,CAAC,MAAM,CACzB,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,YAAY,CAAC,GAAG,CAAC,EAC9C,CAAC,EACD,CAAC,YAAY,CAAC,CACf,CAAC;IACF,MAAM,CAAC,mBAAmB,CAAC,MAAM,CAC/B,MAAM,CAAC,mBAAmB,CAAC,OAAO,CAAC,YAAY,CAAC,GAAG,CAAC,EACpD,CAAC,EACD,CAAC,YAAY,CAAC,CACf,CAAC;IAEF,OAAO,CAAC,IAAI,EAAE,EAAE;QACd,gDAAgD;QAChD,IAAA,0BAAK,EACH,IAAI,EACJ,CAAC,IAAa,EAAmB,EAAE,CAChC,IAAgB,EAAE,IAAI,KAAK,kBAAkB,EAChD,CAAC,IAAa,EAAE,EAAE;YAChB,IAAI,IAAI,CAAC,KAAK,EAAE;gBACd,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;aACzD;QACH,CAAC,CACF,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,MAAM,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/mdx-loader",
3
- "version": "0.0.0-5091",
3
+ "version": "0.0.0-5094",
4
4
  "description": "Docusaurus Loader for MDX",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -20,8 +20,8 @@
20
20
  "dependencies": {
21
21
  "@babel/parser": "^7.18.3",
22
22
  "@babel/traverse": "^7.18.2",
23
- "@docusaurus/logger": "0.0.0-5091",
24
- "@docusaurus/utils": "0.0.0-5091",
23
+ "@docusaurus/logger": "0.0.0-5094",
24
+ "@docusaurus/utils": "0.0.0-5094",
25
25
  "@mdx-js/mdx": "^1.6.22",
26
26
  "escape-html": "^1.0.3",
27
27
  "file-loader": "^6.2.0",
@@ -37,13 +37,15 @@
37
37
  "webpack": "^5.72.1"
38
38
  },
39
39
  "devDependencies": {
40
- "@docusaurus/types": "0.0.0-5091",
40
+ "@docusaurus/types": "0.0.0-5094",
41
41
  "@types/escape-html": "^1.0.2",
42
42
  "@types/mdast": "^3.0.10",
43
43
  "@types/stringify-object": "^3.3.1",
44
44
  "@types/unist": "^2.0.6",
45
+ "rehype-stringify": "^8.0.0",
45
46
  "remark": "^12.0.1",
46
47
  "remark-mdx": "^1.6.21",
48
+ "remark-rehype": "^8.1.0",
47
49
  "to-vfile": "^6.1.0",
48
50
  "unist-builder": "^2.0.3",
49
51
  "unist-util-remove-position": "^3.0.0"
@@ -55,5 +57,5 @@
55
57
  "engines": {
56
58
  "node": ">=16.14"
57
59
  },
58
- "gitHead": "9f79f0eb7547d40c08306a72a3617806f2e6f2bd"
60
+ "gitHead": "5ed0ed8f0a5918441c8b83093fd1975bfe7e0cfd"
59
61
  }
package/src/loader.ts CHANGED
@@ -23,8 +23,10 @@ import unwrapMdxCodeBlocks from './remark/unwrapMdxCodeBlocks';
23
23
  import transformImage from './remark/transformImage';
24
24
  import transformLinks from './remark/transformLinks';
25
25
 
26
+ import transformAdmonitions from './remark/admonitions';
26
27
  import type {LoaderContext} from 'webpack';
27
28
  import type {Processor, Plugin} from 'unified';
29
+ import type {AdmonitionOptions} from './remark/admonitions';
28
30
 
29
31
  const {
30
32
  loaders: {inlineMarkdownImageFileLoader},
@@ -37,6 +39,7 @@ const pragma = `
37
39
  `;
38
40
 
39
41
  const DEFAULT_OPTIONS: MDXOptions = {
42
+ admonitions: true,
40
43
  rehypePlugins: [],
41
44
  remarkPlugins: [unwrapMdxCodeBlocks, emoji, headings, toc],
42
45
  beforeDefaultRemarkPlugins: [],
@@ -48,7 +51,9 @@ const compilerCache = new Map<string | Options, [Processor, Options]>();
48
51
  export type MDXPlugin =
49
52
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
50
53
  [Plugin<any[]>, any] | Plugin<any[]>;
54
+
51
55
  export type MDXOptions = {
56
+ admonitions: boolean | AdmonitionOptions;
52
57
  remarkPlugins: MDXPlugin[];
53
58
  rehypePlugins: MDXPlugin[];
54
59
  beforeDefaultRemarkPlugins: MDXPlugin[];
@@ -132,6 +137,19 @@ function createAssetsExportCode(assets: unknown) {
132
137
  return `{\n${codeLines.join('\n')}\n}`;
133
138
  }
134
139
 
140
+ function getAdmonitionsPlugins(
141
+ admonitionsOption: MDXOptions['admonitions'],
142
+ ): MDXPlugin[] {
143
+ if (admonitionsOption) {
144
+ const plugin: MDXPlugin =
145
+ admonitionsOption === true
146
+ ? transformAdmonitions
147
+ : [transformAdmonitions, admonitionsOption];
148
+ return [plugin];
149
+ }
150
+ return [];
151
+ }
152
+
135
153
  export async function mdxLoader(
136
154
  this: LoaderContext<Options>,
137
155
  fileString: string,
@@ -149,32 +167,37 @@ export async function mdxLoader(
149
167
  const hasFrontMatter = Object.keys(frontMatter).length > 0;
150
168
 
151
169
  if (!compilerCache.has(this.query)) {
152
- const options: Options = {
153
- ...reqOptions,
154
- remarkPlugins: [
155
- ...(reqOptions.beforeDefaultRemarkPlugins ?? []),
156
- ...DEFAULT_OPTIONS.remarkPlugins,
157
- [
158
- transformImage,
159
- {
160
- staticDirs: reqOptions.staticDirs,
161
- siteDir: reqOptions.siteDir,
162
- },
163
- ],
164
- [
165
- transformLinks,
166
- {
167
- staticDirs: reqOptions.staticDirs,
168
- siteDir: reqOptions.siteDir,
169
- },
170
- ],
171
- ...(reqOptions.remarkPlugins ?? []),
170
+ const remarkPlugins: MDXPlugin[] = [
171
+ ...(reqOptions.beforeDefaultRemarkPlugins ?? []),
172
+ ...getAdmonitionsPlugins(reqOptions.admonitions ?? false),
173
+ ...DEFAULT_OPTIONS.remarkPlugins,
174
+ [
175
+ transformImage,
176
+ {
177
+ staticDirs: reqOptions.staticDirs,
178
+ siteDir: reqOptions.siteDir,
179
+ },
172
180
  ],
173
- rehypePlugins: [
174
- ...(reqOptions.beforeDefaultRehypePlugins ?? []),
175
- ...DEFAULT_OPTIONS.rehypePlugins,
176
- ...(reqOptions.rehypePlugins ?? []),
181
+ [
182
+ transformLinks,
183
+ {
184
+ staticDirs: reqOptions.staticDirs,
185
+ siteDir: reqOptions.siteDir,
186
+ },
177
187
  ],
188
+ ...(reqOptions.remarkPlugins ?? []),
189
+ ];
190
+
191
+ const rehypePlugins: MDXPlugin[] = [
192
+ ...(reqOptions.beforeDefaultRehypePlugins ?? []),
193
+ ...DEFAULT_OPTIONS.rehypePlugins,
194
+ ...(reqOptions.rehypePlugins ?? []),
195
+ ];
196
+
197
+ const options: Options = {
198
+ ...reqOptions,
199
+ remarkPlugins,
200
+ rehypePlugins,
178
201
  };
179
202
  compilerCache.set(this.query, [createCompiler(options), options]);
180
203
  }
@@ -0,0 +1,45 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Elvis Wolcott
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+ ---
24
+
25
+ MIT License
26
+
27
+ Copyright (c) Facebook, Inc. and its affiliates.
28
+
29
+ Permission is hereby granted, free of charge, to any person obtaining a copy
30
+ of this software and associated documentation files (the "Software"), to deal
31
+ in the Software without restriction, including without limitation the rights
32
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
33
+ copies of the Software, and to permit persons to whom the Software is
34
+ furnished to do so, subject to the following conditions:
35
+
36
+ The above copyright notice and this permission notice shall be included in all
37
+ copies or substantial portions of the Software.
38
+
39
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
40
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
41
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
42
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
43
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
44
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
45
+ SOFTWARE.
@@ -0,0 +1,3 @@
1
+ # Docusaurus admonitions
2
+
3
+ Code from [remark-admonitions](https://github.com/remarkjs/remark-directive) (MIT license) has been copied to this folder, and highly customized for Docusaurus needs.
@@ -0,0 +1,182 @@
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 visit from 'unist-util-visit';
9
+ import type {Transformer, Processor, Plugin} from 'unified';
10
+ import type {Literal} from 'mdast';
11
+
12
+ const NEWLINE = '\n';
13
+
14
+ export type AdmonitionOptions = {
15
+ tag: string;
16
+ keywords: string[];
17
+ };
18
+
19
+ export const DefaultAdmonitionOptions: AdmonitionOptions = {
20
+ tag: ':::',
21
+ keywords: [
22
+ 'secondary',
23
+ 'info',
24
+ 'success',
25
+ 'danger',
26
+ 'note',
27
+ 'tip',
28
+ 'warning',
29
+ 'important',
30
+ 'caution',
31
+ ],
32
+ };
33
+
34
+ function escapeRegExp(s: string): string {
35
+ return s.replace(/[-[\]{}()*+?.\\^$|/]/g, '\\$&');
36
+ }
37
+
38
+ function normalizeOptions(
39
+ options: Partial<AdmonitionOptions>,
40
+ ): AdmonitionOptions {
41
+ return {...DefaultAdmonitionOptions, ...options};
42
+ }
43
+
44
+ // This string value does not matter much
45
+ // It is ignored because nodes are using hName/hProperties coming from HAST
46
+ const admonitionNodeType = 'admonitionHTML';
47
+
48
+ const plugin: Plugin = function plugin(
49
+ this: Processor,
50
+ optionsInput: Partial<AdmonitionOptions> = {},
51
+ ): Transformer {
52
+ const options = normalizeOptions(optionsInput);
53
+
54
+ const keywords = Object.values(options.keywords).map(escapeRegExp).join('|');
55
+ const tag = escapeRegExp(options.tag);
56
+ const regex = new RegExp(`${tag}(${keywords})(?: *(.*))?\n`);
57
+ const escapeTag = new RegExp(escapeRegExp(`\\${options.tag}`), 'g');
58
+
59
+ // The tokenizer is called on blocks to determine if there is an admonition
60
+ // present and create tags for it
61
+ function blockTokenizer(this: any, eat: any, value: string, silent: boolean) {
62
+ // Stop if no match or match does not start at beginning of line
63
+ const match = regex.exec(value);
64
+ if (!match || match.index !== 0) {
65
+ return false;
66
+ }
67
+ // If silent return the match
68
+ if (silent) {
69
+ return true;
70
+ }
71
+
72
+ const now = eat.now();
73
+ const [opening, keyword, title] = match;
74
+ const food = [];
75
+ const content = [];
76
+
77
+ let newValue = value;
78
+ // consume lines until a closing tag
79
+ let idx = newValue.indexOf(NEWLINE);
80
+ while (idx !== -1) {
81
+ // grab this line and eat it
82
+ const next = newValue.indexOf(NEWLINE, idx + 1);
83
+ const line =
84
+ next !== -1 ? newValue.slice(idx + 1, next) : newValue.slice(idx + 1);
85
+ food.push(line);
86
+ newValue = newValue.slice(idx + 1);
87
+ // the closing tag is NOT part of the content
88
+ if (line.startsWith(options.tag)) {
89
+ break;
90
+ }
91
+ content.push(line);
92
+ idx = newValue.indexOf(NEWLINE);
93
+ }
94
+
95
+ // consume the processed tag and replace escape sequences
96
+ const contentString = content.join(NEWLINE).replace(escapeTag, options.tag);
97
+ const add = eat(opening + food.join(NEWLINE));
98
+
99
+ // parse the content in block mode
100
+ const exit = this.enterBlock();
101
+ const contentNodes = this.tokenizeBlock(contentString, now);
102
+ exit();
103
+
104
+ const titleNodes = this.tokenizeInline(title, now);
105
+
106
+ const isSimpleTextTitle =
107
+ titleNodes.length === 1 && titleNodes[0].type === 'text';
108
+
109
+ const element = {
110
+ type: admonitionNodeType,
111
+ data: {
112
+ // hName/hProperties come from HAST
113
+ // See https://github.com/syntax-tree/mdast-util-to-hast#fields-on-nodes
114
+ hName: 'admonition',
115
+ hProperties: {
116
+ ...(title && isSimpleTextTitle && {title}),
117
+ type: keyword,
118
+ },
119
+ },
120
+ children: [
121
+ // For titles containing MDX syntax: create a custom element. The theme
122
+ // component will extract it and render it nicely.
123
+ //
124
+ // Temporary workaround, because it's complex in MDX v1 to emit
125
+ // interpolated JSX prop syntax (title={<>my <code>title</code></>}).
126
+ // For this reason, we use children instead of the title prop.
127
+ title &&
128
+ !isSimpleTextTitle && {
129
+ type: admonitionNodeType,
130
+ data: {
131
+ hName: 'mdxAdmonitionTitle',
132
+ hProperties: {},
133
+ },
134
+ children: titleNodes,
135
+ },
136
+ ...contentNodes,
137
+ ].filter(Boolean),
138
+ };
139
+
140
+ return add(element);
141
+ }
142
+
143
+ // add tokenizer to parser after fenced code blocks
144
+ const Parser = this.Parser.prototype;
145
+ Parser.blockTokenizers.admonition = blockTokenizer;
146
+ Parser.blockMethods.splice(
147
+ Parser.blockMethods.indexOf('fencedCode') + 1,
148
+ 0,
149
+ 'admonition',
150
+ );
151
+ Parser.interruptParagraph.splice(
152
+ Parser.interruptParagraph.indexOf('fencedCode') + 1,
153
+ 0,
154
+ ['admonition'],
155
+ );
156
+ Parser.interruptList.splice(
157
+ Parser.interruptList.indexOf('fencedCode') + 1,
158
+ 0,
159
+ ['admonition'],
160
+ );
161
+ Parser.interruptBlockquote.splice(
162
+ Parser.interruptBlockquote.indexOf('fencedCode') + 1,
163
+ 0,
164
+ ['admonition'],
165
+ );
166
+
167
+ return (root) => {
168
+ // escape everything except admonitionHTML nodes
169
+ visit(
170
+ root,
171
+ (node: unknown): node is Literal =>
172
+ (node as Literal)?.type !== admonitionNodeType,
173
+ (node: Literal) => {
174
+ if (node.value) {
175
+ node.value = node.value.replace(escapeTag, options.tag);
176
+ }
177
+ },
178
+ );
179
+ };
180
+ };
181
+
182
+ export default plugin;