@amamo/mdx 0.4.0 → 0.5.0

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/dist/compiler.js CHANGED
@@ -408,13 +408,20 @@ function generateCollectionModule(config, records) {
408
408
  return lines.join('\n');
409
409
  }
410
410
  function generateCollectionTypes() {
411
- return `export interface IGeneratedDocument {
411
+ return `import type { IStructuredData, ITocItem } from '@amamo/mdx'
412
+
413
+ export interface IGeneratedDocument {
412
414
  readonly derived: Readonly<Record<string, unknown>>
413
415
  readonly frontmatter: Readonly<Record<string, unknown>>
414
416
  readonly key: string
415
417
  readonly locale?: string
416
418
  readonly slug?: string
417
- readonly load: () => Promise<{ default: unknown }>
419
+ readonly load: () => Promise<{
420
+ readonly default: unknown
421
+ readonly frontmatter: Readonly<Record<string, unknown>>
422
+ readonly structuredData: IStructuredData
423
+ readonly toc: readonly ITocItem[]
424
+ }>
418
425
  }
419
426
 
420
427
  export declare const collections: Readonly<Record<string, readonly IGeneratedDocument[]>>
@@ -0,0 +1,18 @@
1
+ import type { ReactNode } from 'react';
2
+ export interface ITocItem {
3
+ depth: number;
4
+ title: ReactNode;
5
+ url: string;
6
+ }
7
+ export interface IStructuredDataHeading {
8
+ content: string;
9
+ id: string;
10
+ }
11
+ export interface IStructuredDataContent {
12
+ content: string;
13
+ heading?: string;
14
+ }
15
+ export interface IStructuredData {
16
+ contents: IStructuredDataContent[];
17
+ headings: IStructuredDataHeading[];
18
+ }
@@ -0,0 +1 @@
1
+ export {};
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export type { IAmamoMDXConfig, IAmamoMdxConfig, ICacheConfig, ICollectionConfig, IDerivedConfig, IFrontmatterSchema, IHighlightConfig, ILocaleConfig, IManifestConfig, IMathConfig, IMdxConfig, IMdxExtensionsConfig, IMediaConfig, JsonValue, ManifestField, } from './config.js';
2
2
  export { defineConfig, normalizeConfig, z } from './config.js';
3
+ export type { IStructuredData, IStructuredDataContent, IStructuredDataHeading, ITocItem, } from './content.js';
3
4
  export type { IBuildResult, ICompiler, ITransformResult } from './compiler.js';
4
5
  export { createCompiler } from './compiler.js';
5
6
  export type { IDiagnostic } from './native.js';
package/dist/native.js CHANGED
@@ -14,7 +14,7 @@ const shikiVersion = require('shiki/package.json').version;
14
14
  function nativeConfigJson(config) {
15
15
  return JSON.stringify({
16
16
  ...config,
17
- _runtime: { packageVersion, shikiVersion },
17
+ _runtime: { packageVersion, shikiTransformers: true, shikiVersion },
18
18
  });
19
19
  }
20
20
  export function configurationFingerprint(config) {
package/dist/shiki.js CHANGED
@@ -1,8 +1,18 @@
1
+ import { transformerMetaHighlight, transformerMetaWordHighlight, transformerNotationDiff, transformerNotationErrorLevel, transformerNotationFocus, transformerNotationHighlight, transformerNotationWordHighlight, transformerRemoveLineBreak, transformerRemoveNotationEscape, } from '@shikijs/transformers';
1
2
  import { createHighlighterCore } from 'shiki/core';
2
3
  import { createJavaScriptRegexEngine } from 'shiki/engine/javascript';
3
4
  import { createOnigurumaEngine } from 'shiki/engine/oniguruma';
4
5
  import { bundledLanguages, bundledLanguagesAlias } from 'shiki/langs';
5
6
  import { bundledThemes } from 'shiki/themes';
7
+ function languageClassTransformer(language) {
8
+ return {
9
+ pre(node) {
10
+ const classes = String(node.properties.class ?? '').split(' ');
11
+ classes.push(`language-${language}`);
12
+ node.properties.class = classes.filter(Boolean).join(' ');
13
+ },
14
+ };
15
+ }
6
16
  function themeLoader(name) {
7
17
  if (!Object.hasOwn(bundledThemes, name)) {
8
18
  throw new Error(`AMAMO_SHIKI_UNKNOWN_THEME: Unknown bundled Shiki theme \`${name}\``);
@@ -79,17 +89,32 @@ export async function createShikiRenderer(config) {
79
89
  light: config.themes.light,
80
90
  dark: config.themes.dark,
81
91
  },
82
- transformers: language && !['text', 'plain', 'plaintext'].includes(language)
83
- ? [
84
- {
85
- pre(node) {
86
- const classes = String(node.properties.class ?? '').split(' ');
87
- classes.push(`language-${language}`);
88
- node.properties.class = classes.filter(Boolean).join(' ');
89
- },
92
+ transformers: [
93
+ ...(language && !['text', 'plain', 'plaintext'].includes(language)
94
+ ? [languageClassTransformer(language)]
95
+ : []),
96
+ transformerMetaHighlight({ className: 'line-highlighted' }),
97
+ transformerMetaWordHighlight({ className: 'word-highlighted' }),
98
+ transformerNotationHighlight({ classActiveLine: 'line-highlighted' }),
99
+ transformerNotationDiff({
100
+ classLineAdd: 'line-diff-add',
101
+ classLineRemove: 'line-diff-remove',
102
+ }),
103
+ transformerNotationFocus({ classActiveLine: 'line-focused' }),
104
+ transformerNotationErrorLevel({
105
+ classMap: {
106
+ error: ['line-highlighted', 'line-error'],
107
+ warning: ['line-highlighted', 'line-warning'],
108
+ info: ['line-highlighted', 'line-info'],
90
109
  },
91
- ]
92
- : undefined,
110
+ }),
111
+ transformerNotationWordHighlight({
112
+ classActiveWord: 'word-highlighted',
113
+ classActivePre: 'has-word-highlighted',
114
+ }),
115
+ transformerRemoveLineBreak(),
116
+ transformerRemoveNotationEscape(),
117
+ ],
93
118
  });
94
119
  highlighted.set(key, JSON.parse(JSON.stringify(hast)));
95
120
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amamo/mdx",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "A native MDX content compiler with Vite and Next adapters",
5
5
  "homepage": "https://jikkai.github.io/mdx/",
6
6
  "license": "MIT",
@@ -55,11 +55,12 @@
55
55
  "release": "verso"
56
56
  },
57
57
  "dependencies": {
58
+ "@shikijs/transformers": "4.4.3",
58
59
  "shiki": "4.4.3",
59
60
  "zod": "4.5.4"
60
61
  },
61
62
  "devDependencies": {
62
- "@amamo/oxlint-config": "1.1.0",
63
+ "@amamo/oxlint-config": "1.1.1",
63
64
  "@amamo/verso": "1.2.0",
64
65
  "@napi-rs/cli": "3.8.6",
65
66
  "@types/node": "26.4.0",
@@ -119,12 +120,12 @@
119
120
  },
120
121
  "packageManager": "pnpm@12.1.0",
121
122
  "optionalDependencies": {
122
- "@amamo/mdx-darwin-arm64": "0.4.0",
123
- "@amamo/mdx-darwin-x64": "0.4.0",
124
- "@amamo/mdx-linux-arm64-gnu": "0.4.0",
125
- "@amamo/mdx-linux-x64-gnu": "0.4.0",
126
- "@amamo/mdx-linux-arm64-musl": "0.4.0",
127
- "@amamo/mdx-linux-x64-musl": "0.4.0",
128
- "@amamo/mdx-win32-x64-msvc": "0.4.0"
123
+ "@amamo/mdx-darwin-arm64": "0.5.0",
124
+ "@amamo/mdx-darwin-x64": "0.5.0",
125
+ "@amamo/mdx-linux-arm64-gnu": "0.5.0",
126
+ "@amamo/mdx-linux-x64-gnu": "0.5.0",
127
+ "@amamo/mdx-linux-arm64-musl": "0.5.0",
128
+ "@amamo/mdx-linux-x64-musl": "0.5.0",
129
+ "@amamo/mdx-win32-x64-msvc": "0.5.0"
129
130
  }
130
131
  }