@vxrn/mdx 1.1.321 → 1.1.323

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vxrn/mdx",
3
- "version": "1.1.321",
3
+ "version": "1.1.323",
4
4
  "types": "./types/index.d.ts",
5
5
  "main": "dist/index.js",
6
6
  "type": "commonjs",
@@ -7,5 +7,5 @@ export const getHeadings = (source: string) =>
7
7
  .map((x) => ({
8
8
  title: getTitle(x),
9
9
  priority: x.trim().split(' ')[0].length,
10
- id: `#${getTitle(x).replace(/\s+/, '-').toLowerCase()}`,
10
+ id: `#${getTitle(x).replace(/\s+/g, '-').toLowerCase()}`,
11
11
  }))
@@ -10,9 +10,12 @@ import rehypeAutolinkHeadings from 'rehype-autolink-headings'
10
10
  import rehypeSlug from 'rehype-slug'
11
11
  import { getHeadings } from './getHeadings'
12
12
 
13
+ export type UnifiedPlugin = import('unified').Plugin[]
14
+
13
15
  export const getMDXBySlug = async (
14
16
  basePath: string,
15
- slug: string
17
+ slug: string,
18
+ extraPlugins?: UnifiedPlugin
16
19
  ): Promise<{ frontmatter: Frontmatter; code: string }> => {
17
20
  let mdxPath = slug
18
21
 
@@ -24,7 +27,7 @@ export const getMDXBySlug = async (
24
27
 
25
28
  const filePath = path.join(basePath, `${mdxPath}.mdx`)
26
29
  const source = fs.readFileSync(filePath, 'utf8')
27
- const { frontmatter, code } = await getMDX(source)
30
+ const { frontmatter, code } = await getMDX(source, extraPlugins)
28
31
  return {
29
32
  frontmatter: {
30
33
  ...frontmatter,
@@ -35,11 +38,12 @@ export const getMDXBySlug = async (
35
38
  }
36
39
  }
37
40
 
38
- export async function getMDX(source: string) {
41
+ export async function getMDX(source: string, extraPlugins?: UnifiedPlugin) {
39
42
  return await bundleMDX({
40
43
  source,
41
44
  mdxOptions(options) {
42
45
  const plugins = [
46
+ ...(extraPlugins || []),
43
47
  ...(options.rehypePlugins ?? []),
44
48
  rehypeMetaAttribute,
45
49
  rehypeHighlightCode,
package/src/index.ts CHANGED
@@ -1,5 +1,4 @@
1
- // export { rehypeHighlightCode } from './rehypeHighlightCode'
2
1
  export { getAllFrontmatter } from './getAllFrontmatter'
3
- export { getMDXBySlug, getAllVersionsFromPath } from './getMDXBySlug'
4
- export type { Frontmatter } from './types'
2
+ export { getAllVersionsFromPath, getMDXBySlug } from './getMDXBySlug'
5
3
  export { createCodeHighlighter } from './highlightCode'
4
+ export type { Frontmatter } from './types'
@@ -1,9 +1,10 @@
1
1
  import type { Frontmatter } from './types';
2
- export declare const getMDXBySlug: (basePath: string, slug: string) => Promise<{
2
+ export type UnifiedPlugin = import('unified').Plugin[];
3
+ export declare const getMDXBySlug: (basePath: string, slug: string, extraPlugins?: UnifiedPlugin) => Promise<{
3
4
  frontmatter: Frontmatter;
4
5
  code: string;
5
6
  }>;
6
- export declare function getMDX(source: string): Promise<{
7
+ export declare function getMDX(source: string, extraPlugins?: UnifiedPlugin): Promise<{
7
8
  code: string;
8
9
  frontmatter: {
9
10
  [key: string]: any;
@@ -1 +1 @@
1
- {"version":3,"file":"getMDXBySlug.d.ts","sourceRoot":"","sources":["../src/getMDXBySlug.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAO1C,eAAO,MAAM,YAAY,aACb,MAAM,QACV,MAAM,KACX,OAAO,CAAC;IAAE,WAAW,EAAE,WAAW,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAoBpD,CAAA;AAED,wBAAsB,MAAM,CAAC,MAAM,EAAE,MAAM;;;;;;;;;;;GAe1C;AAED,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAOjE"}
1
+ {"version":3,"file":"getMDXBySlug.d.ts","sourceRoot":"","sources":["../src/getMDXBySlug.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAO1C,MAAM,MAAM,aAAa,GAAG,OAAO,SAAS,EAAE,MAAM,EAAE,CAAA;AAEtD,eAAO,MAAM,YAAY,aACb,MAAM,QACV,MAAM,iBACG,aAAa,KAC3B,OAAO,CAAC;IAAE,WAAW,EAAE,WAAW,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAoBpD,CAAA;AAED,wBAAsB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,aAAa;;;;;;;;;;;GAgBxE;AAED,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAOjE"}
package/types/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { getAllFrontmatter } from './getAllFrontmatter';
2
- export { getMDXBySlug, getAllVersionsFromPath } from './getMDXBySlug';
3
- export type { Frontmatter } from './types';
2
+ export { getAllVersionsFromPath, getMDXBySlug } from './getMDXBySlug';
4
3
  export { createCodeHighlighter } from './highlightCode';
4
+ export type { Frontmatter } from './types';
5
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AACvD,OAAO,EAAE,YAAY,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAA;AACrE,YAAY,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAC1C,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AACvD,OAAO,EAAE,sBAAsB,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AACrE,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;AACvD,YAAY,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA"}