@blogmcp/mdx-schema 0.1.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/checkPin.d.ts +48 -0
- package/dist/checkPin.js +139 -0
- package/dist/checkPin.js.map +1 -0
- package/dist/composables/useMdxParsing.d.ts +71 -0
- package/dist/composables/useMdxParsing.js +239 -0
- package/dist/composables/useMdxParsing.js.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/metadata/customComponents.d.ts +128 -0
- package/dist/metadata/customComponents.js +301 -0
- package/dist/metadata/customComponents.js.map +1 -0
- package/dist/metadata/index.d.ts +24 -0
- package/dist/metadata/index.js +427 -0
- package/dist/metadata/index.js.map +1 -0
- package/dist/metadata/validate.d.ts +46 -0
- package/dist/metadata/validate.js +95 -0
- package/dist/metadata/validate.js.map +1 -0
- package/dist/prepareProps.d.ts +42 -0
- package/dist/prepareProps.js +177 -0
- package/dist/prepareProps.js.map +1 -0
- package/dist/styles/index.d.ts +203 -0
- package/dist/styles/index.js +162 -0
- package/dist/styles/index.js.map +1 -0
- package/dist/types/index.d.ts +421 -0
- package/dist/types/index.js +25 -0
- package/dist/types/index.js.map +1 -0
- package/dist/version.d.ts +23 -0
- package/dist/version.js +23 -0
- package/dist/version.js.map +1 -0
- package/package.json +80 -0
- package/src/checkPin.ts +163 -0
- package/src/composables/useMdxParsing.ts +248 -0
- package/src/index.ts +22 -0
- package/src/metadata/customComponents.ts +360 -0
- package/src/metadata/index.ts +437 -0
- package/src/metadata/validate.ts +153 -0
- package/src/prepareProps.ts +219 -0
- package/src/styles/index.ts +196 -0
- package/src/types/index.ts +469 -0
- package/src/version.ts +24 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Write-time pin enforcement.
|
|
3
|
+
*
|
|
4
|
+
* Walks parsed MDX components (including nested MDX-in-MDX children),
|
|
5
|
+
* returns a `PinViolation` for each component whose `addedIn > pinVersion`
|
|
6
|
+
* and for each prop whose effective `addedIn` (prop-level if set,
|
|
7
|
+
* otherwise the parent component's) is `> pinVersion`.
|
|
8
|
+
*
|
|
9
|
+
* Called by `article.service.ts` before save. When `pinVersion` is
|
|
10
|
+
* `null` (no tenant pin set), returns `[]` immediately — the common
|
|
11
|
+
* case.
|
|
12
|
+
*
|
|
13
|
+
* Uses the canonical framework-neutral parser at
|
|
14
|
+
* `src/composables/useMdxParsing.ts` — no new AST dependency. The
|
|
15
|
+
* parser only walks top-level component tags, so this module recurses
|
|
16
|
+
* into `children` strings to cover the `<Tooltip><Button/></Tooltip>`
|
|
17
|
+
* attack vector flagged in review.
|
|
18
|
+
*
|
|
19
|
+
* Comparison uses node-semver named imports (`gt` / `valid` / `lt`).
|
|
20
|
+
* Pre-release identifiers follow standard semver precedence:
|
|
21
|
+
* `0.2.0-beta.1 < 0.2.0`.
|
|
22
|
+
*
|
|
23
|
+
* **addedIn validity:** every `addedIn` we encounter in metadata MUST be
|
|
24
|
+
* a valid semver — these are programmer-error conditions and we throw.
|
|
25
|
+
*
|
|
26
|
+
* **pinVersion validity:** the pin lives in the tenants table, written
|
|
27
|
+
* by humans / migrations / a future UI. We DO NOT throw on a malformed
|
|
28
|
+
* pin at save time (would block every save until ops fixes the DB).
|
|
29
|
+
* Instead we log once and treat the pin as `null` (no enforcement). The
|
|
30
|
+
* write path that SETS `mdx_schema_version_pin` is the right place to
|
|
31
|
+
* validate; we degrade safely here.
|
|
32
|
+
*/
|
|
33
|
+
import { gt, lt, valid } from 'semver';
|
|
34
|
+
export interface PinViolation {
|
|
35
|
+
kind: 'componentNewerThanPin' | 'propNewerThanPin';
|
|
36
|
+
/** Component name as it appears in MDX (e.g. "Callout"). */
|
|
37
|
+
component: string;
|
|
38
|
+
/** Prop name — set ONLY when `kind === 'propNewerThanPin'`. */
|
|
39
|
+
prop?: string;
|
|
40
|
+
/** The `addedIn` SCHEMA_VERSION of the offending element. */
|
|
41
|
+
addedIn: string;
|
|
42
|
+
/** The pin set on the tenant. */
|
|
43
|
+
pinVersion: string;
|
|
44
|
+
}
|
|
45
|
+
export declare function checkPin(content: string, pinVersion: string | null): PinViolation[];
|
|
46
|
+
/** Test-only — clear the malformed-pin dedupe so specs don't poison each other. */
|
|
47
|
+
export declare function _resetMalformedPinDedupeForTests(): void;
|
|
48
|
+
export { gt as semverGt, lt as semverLt, valid as semverValid };
|
package/dist/checkPin.js
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Write-time pin enforcement.
|
|
3
|
+
*
|
|
4
|
+
* Walks parsed MDX components (including nested MDX-in-MDX children),
|
|
5
|
+
* returns a `PinViolation` for each component whose `addedIn > pinVersion`
|
|
6
|
+
* and for each prop whose effective `addedIn` (prop-level if set,
|
|
7
|
+
* otherwise the parent component's) is `> pinVersion`.
|
|
8
|
+
*
|
|
9
|
+
* Called by `article.service.ts` before save. When `pinVersion` is
|
|
10
|
+
* `null` (no tenant pin set), returns `[]` immediately — the common
|
|
11
|
+
* case.
|
|
12
|
+
*
|
|
13
|
+
* Uses the canonical framework-neutral parser at
|
|
14
|
+
* `src/composables/useMdxParsing.ts` — no new AST dependency. The
|
|
15
|
+
* parser only walks top-level component tags, so this module recurses
|
|
16
|
+
* into `children` strings to cover the `<Tooltip><Button/></Tooltip>`
|
|
17
|
+
* attack vector flagged in review.
|
|
18
|
+
*
|
|
19
|
+
* Comparison uses node-semver named imports (`gt` / `valid` / `lt`).
|
|
20
|
+
* Pre-release identifiers follow standard semver precedence:
|
|
21
|
+
* `0.2.0-beta.1 < 0.2.0`.
|
|
22
|
+
*
|
|
23
|
+
* **addedIn validity:** every `addedIn` we encounter in metadata MUST be
|
|
24
|
+
* a valid semver — these are programmer-error conditions and we throw.
|
|
25
|
+
*
|
|
26
|
+
* **pinVersion validity:** the pin lives in the tenants table, written
|
|
27
|
+
* by humans / migrations / a future UI. We DO NOT throw on a malformed
|
|
28
|
+
* pin at save time (would block every save until ops fixes the DB).
|
|
29
|
+
* Instead we log once and treat the pin as `null` (no enforcement). The
|
|
30
|
+
* write path that SETS `mdx_schema_version_pin` is the right place to
|
|
31
|
+
* validate; we degrade safely here.
|
|
32
|
+
*/
|
|
33
|
+
import { gt, lt, valid } from 'semver';
|
|
34
|
+
import { extractMdxComponents, stripFrontmatter, HAS_MDX_RE } from './composables/useMdxParsing.js';
|
|
35
|
+
import { getComponentMetadata } from './metadata/index.js';
|
|
36
|
+
/** Module-level dedupe so we don't spam the log on a malformed pin. */
|
|
37
|
+
const malformedPinSeen = new Set();
|
|
38
|
+
function assertValidAddedIn(label, version) {
|
|
39
|
+
if (!valid(version)) {
|
|
40
|
+
throw new Error(`[mdx-schema/checkPin] ${label} is not a valid semver string: "${version}"`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Recursive walker. Returns violations for the given parsed item AND
|
|
45
|
+
* its children (when children contain further MDX components).
|
|
46
|
+
*/
|
|
47
|
+
function walkItem(item, pinVersion, out) {
|
|
48
|
+
if (item.type !== 'component')
|
|
49
|
+
return;
|
|
50
|
+
const meta = getComponentMetadata(item.name);
|
|
51
|
+
if (!meta) {
|
|
52
|
+
// Unknown component — validateComponent surfaces this as a hard
|
|
53
|
+
// error already; checkPin's contract is pin-only.
|
|
54
|
+
// We still recurse into children in case they exist.
|
|
55
|
+
if ('children' in item && typeof item.children === 'string' && HAS_MDX_RE.test(item.children)) {
|
|
56
|
+
const childItems = extractMdxComponents(item.children);
|
|
57
|
+
for (const child of childItems)
|
|
58
|
+
walkItem(child, pinVersion, out);
|
|
59
|
+
}
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
assertValidAddedIn(`${meta.name}.addedIn`, meta.addedIn);
|
|
63
|
+
// Component-level violation: if the component itself is newer
|
|
64
|
+
// than the pin, every prop violation would be redundant — emit
|
|
65
|
+
// ONLY the component violation and skip per-prop checks. Still
|
|
66
|
+
// recurse into children so a nested violation is reported.
|
|
67
|
+
if (gt(meta.addedIn, pinVersion)) {
|
|
68
|
+
out.push({
|
|
69
|
+
kind: 'componentNewerThanPin',
|
|
70
|
+
component: meta.name,
|
|
71
|
+
addedIn: meta.addedIn,
|
|
72
|
+
pinVersion,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
// Prop-level violations: each prop's effective `addedIn` (defaults
|
|
77
|
+
// to component's `addedIn` when prop-level is unset).
|
|
78
|
+
for (const propName of Object.keys(item.props)) {
|
|
79
|
+
const propMeta = meta.props.find(p => p.name === propName);
|
|
80
|
+
if (!propMeta) {
|
|
81
|
+
// Unknown prop — validateComponent already surfaces this; pin
|
|
82
|
+
// check has nothing to say.
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
const effectiveAddedIn = propMeta.addedIn ?? meta.addedIn;
|
|
86
|
+
assertValidAddedIn(`${meta.name}.${propName}.addedIn`, effectiveAddedIn);
|
|
87
|
+
if (gt(effectiveAddedIn, pinVersion)) {
|
|
88
|
+
out.push({
|
|
89
|
+
kind: 'propNewerThanPin',
|
|
90
|
+
component: meta.name,
|
|
91
|
+
prop: propName,
|
|
92
|
+
addedIn: effectiveAddedIn,
|
|
93
|
+
pinVersion,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
// Recurse: children string may itself contain MDX components.
|
|
99
|
+
if (typeof item.children === 'string' && HAS_MDX_RE.test(item.children)) {
|
|
100
|
+
const childItems = extractMdxComponents(item.children);
|
|
101
|
+
for (const child of childItems)
|
|
102
|
+
walkItem(child, pinVersion, out);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
export function checkPin(content, pinVersion) {
|
|
106
|
+
if (pinVersion === null)
|
|
107
|
+
return [];
|
|
108
|
+
if (!valid(pinVersion)) {
|
|
109
|
+
// Operational-safety: malformed pin in the tenants table must not
|
|
110
|
+
// block every save. Log once per process per offending string and
|
|
111
|
+
// degrade to "no pin" so saves proceed. Validate at WRITE-of-pin
|
|
112
|
+
// time, not READ-of-pin time.
|
|
113
|
+
if (!malformedPinSeen.has(pinVersion)) {
|
|
114
|
+
malformedPinSeen.add(pinVersion);
|
|
115
|
+
const isProd = typeof process !== 'undefined'
|
|
116
|
+
&& typeof process.env !== 'undefined'
|
|
117
|
+
&& process.env.NODE_ENV === 'production';
|
|
118
|
+
if (!isProd) {
|
|
119
|
+
// eslint-disable-next-line no-console
|
|
120
|
+
console.warn(`[mdx-schema/checkPin] pinVersion "${pinVersion}" is not valid semver; treating as no pin. Fix the tenants.mdx_schema_version_pin column.`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return [];
|
|
124
|
+
}
|
|
125
|
+
const stripped = stripFrontmatter(content);
|
|
126
|
+
const parsed = extractMdxComponents(stripped);
|
|
127
|
+
const violations = [];
|
|
128
|
+
for (const item of parsed)
|
|
129
|
+
walkItem(item, pinVersion, violations);
|
|
130
|
+
return violations;
|
|
131
|
+
}
|
|
132
|
+
/** Test-only — clear the malformed-pin dedupe so specs don't poison each other. */
|
|
133
|
+
export function _resetMalformedPinDedupeForTests() {
|
|
134
|
+
malformedPinSeen.clear();
|
|
135
|
+
}
|
|
136
|
+
// Re-export semver helpers we use, so consumers of this module don't
|
|
137
|
+
// need an extra dependency just to round-trip versions:
|
|
138
|
+
export { gt as semverGt, lt as semverLt, valid as semverValid };
|
|
139
|
+
//# sourceMappingURL=checkPin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkPin.js","sourceRoot":"","sources":["../src/checkPin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,EAAE,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAA;AACtC,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAA;AACnG,OAAO,EAAE,oBAAoB,EA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parsing for JSX-style component syntax used in MDX content.
|
|
5
|
+
* Used by md-editor (compilation), blog (rendering), and Tiptap (roundtripping).
|
|
6
|
+
*
|
|
7
|
+
* Pure TS — no framework dependencies.
|
|
8
|
+
*/
|
|
9
|
+
import type { ParsedContent } from '../types/index.js';
|
|
10
|
+
/** Regex to detect whether content contains MDX components (uppercase JSX tags). */
|
|
11
|
+
export declare const HAS_MDX_RE: RegExp;
|
|
12
|
+
/**
|
|
13
|
+
* Regex pattern for matching JSX-style components in MDX content.
|
|
14
|
+
* Matches both opening+closing tags and self-closing tags.
|
|
15
|
+
*
|
|
16
|
+
* Group layout:
|
|
17
|
+
* - Opening+closing: match[1]=name, match[2]=props, match[3]=children
|
|
18
|
+
* - Self-closing: match[4]=name, match[5]=props
|
|
19
|
+
*
|
|
20
|
+
* NOTE: Create a new RegExp instance per call (g-flag + exec requires fresh lastIndex).
|
|
21
|
+
*/
|
|
22
|
+
export declare const MDX_COMPONENT_PATTERN: RegExp;
|
|
23
|
+
/**
|
|
24
|
+
* Extract a brace-delimited expression from a string, handling nested braces and quoted strings.
|
|
25
|
+
* Returns the content between the outer braces and the index after the closing brace.
|
|
26
|
+
*/
|
|
27
|
+
export declare function extractBraceExpression(str: string, startIndex: number): {
|
|
28
|
+
content: string;
|
|
29
|
+
endIndex: number;
|
|
30
|
+
} | null;
|
|
31
|
+
/**
|
|
32
|
+
* Parse a JSX props string into a key-value record.
|
|
33
|
+
* Supports: prop="value", prop={expression}, prop (boolean), and nested braces.
|
|
34
|
+
*/
|
|
35
|
+
export declare function parseJsxProps(propsString: string): Record<string, unknown>;
|
|
36
|
+
/**
|
|
37
|
+
* Serialize a props object back to JSX-style props string.
|
|
38
|
+
* Reverses parseJsxProps().
|
|
39
|
+
*
|
|
40
|
+
* Rules:
|
|
41
|
+
* - string → prop="value"
|
|
42
|
+
* - boolean true → prop (shorthand)
|
|
43
|
+
* - number → prop={value}
|
|
44
|
+
* - array/object → prop={JSON}
|
|
45
|
+
*/
|
|
46
|
+
export declare function serializeProps(props: Record<string, unknown>): string;
|
|
47
|
+
/**
|
|
48
|
+
* Serialize a component back to JSX-style MDX syntax.
|
|
49
|
+
*
|
|
50
|
+
* @param name - Component name (e.g., "Callout")
|
|
51
|
+
* @param props - Component props object
|
|
52
|
+
* @param children - Inner content (if any). If empty/undefined, produces self-closing tag.
|
|
53
|
+
*/
|
|
54
|
+
export declare function serializeComponent(name: string, props: Record<string, unknown>, children?: string): string;
|
|
55
|
+
/**
|
|
56
|
+
* Strip YAML frontmatter from MDX content.
|
|
57
|
+
*/
|
|
58
|
+
export declare function stripFrontmatter(source: string): string;
|
|
59
|
+
/**
|
|
60
|
+
* Extract frontmatter string from MDX content.
|
|
61
|
+
* Returns the frontmatter block (without delimiters) or null if none.
|
|
62
|
+
*/
|
|
63
|
+
export declare function extractFrontmatter(source: string): string | null;
|
|
64
|
+
/**
|
|
65
|
+
* Extract MDX components from content, splitting into html chunks and component definitions.
|
|
66
|
+
* Does NOT process markdown → HTML (caller handles that).
|
|
67
|
+
*
|
|
68
|
+
* @param content - MDX content (frontmatter should already be stripped)
|
|
69
|
+
* @returns Array of parsed content items
|
|
70
|
+
*/
|
|
71
|
+
export declare function extractMdxComponents(content: string): ParsedContent[];
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MDX Parsing & Serialization Utilities
|
|
3
|
+
*
|
|
4
|
+
* Shared parsing for JSX-style component syntax used in MDX content.
|
|
5
|
+
* Used by md-editor (compilation), blog (rendering), and Tiptap (roundtripping).
|
|
6
|
+
*
|
|
7
|
+
* Pure TS — no framework dependencies.
|
|
8
|
+
*/
|
|
9
|
+
/** Regex to detect whether content contains MDX components (uppercase JSX tags). */
|
|
10
|
+
export const HAS_MDX_RE = /<[A-Z][a-zA-Z]*[\s/>]/;
|
|
11
|
+
/**
|
|
12
|
+
* Regex pattern for matching JSX-style components in MDX content.
|
|
13
|
+
* Matches both opening+closing tags and self-closing tags.
|
|
14
|
+
*
|
|
15
|
+
* Group layout:
|
|
16
|
+
* - Opening+closing: match[1]=name, match[2]=props, match[3]=children
|
|
17
|
+
* - Self-closing: match[4]=name, match[5]=props
|
|
18
|
+
*
|
|
19
|
+
* NOTE: Create a new RegExp instance per call (g-flag + exec requires fresh lastIndex).
|
|
20
|
+
*/
|
|
21
|
+
export const MDX_COMPONENT_PATTERN = /<([A-Z][a-zA-Z]*)\s*([^>]*)>([\s\S]*?)<\/\1>|<([A-Z][a-zA-Z]*)\s*((?:[^/]|\/(?!>))*)\/>/g;
|
|
22
|
+
/**
|
|
23
|
+
* Extract a brace-delimited expression from a string, handling nested braces and quoted strings.
|
|
24
|
+
* Returns the content between the outer braces and the index after the closing brace.
|
|
25
|
+
*/
|
|
26
|
+
export function extractBraceExpression(str, startIndex) {
|
|
27
|
+
if (str[startIndex] !== '{')
|
|
28
|
+
return null;
|
|
29
|
+
let depth = 0;
|
|
30
|
+
let inString = null;
|
|
31
|
+
for (let i = startIndex; i < str.length; i++) {
|
|
32
|
+
const ch = str[i];
|
|
33
|
+
if (inString) {
|
|
34
|
+
if (ch === '\\') {
|
|
35
|
+
i++;
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
if (ch === inString)
|
|
39
|
+
inString = null;
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
if (ch === '"' || ch === "'") {
|
|
43
|
+
inString = ch;
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
if (ch === '{') {
|
|
47
|
+
depth++;
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
if (ch === '}') {
|
|
51
|
+
depth--;
|
|
52
|
+
if (depth === 0) {
|
|
53
|
+
return { content: str.slice(startIndex + 1, i), endIndex: i + 1 };
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Parse a JSX props string into a key-value record.
|
|
61
|
+
* Supports: prop="value", prop={expression}, prop (boolean), and nested braces.
|
|
62
|
+
*/
|
|
63
|
+
export function parseJsxProps(propsString) {
|
|
64
|
+
const result = {};
|
|
65
|
+
if (!propsString.trim())
|
|
66
|
+
return result;
|
|
67
|
+
let i = 0;
|
|
68
|
+
const s = propsString;
|
|
69
|
+
while (i < s.length) {
|
|
70
|
+
while (i < s.length && /\s/.test(s[i]))
|
|
71
|
+
i++;
|
|
72
|
+
if (i >= s.length)
|
|
73
|
+
break;
|
|
74
|
+
const nameMatch = s.slice(i).match(/^(\w+)/);
|
|
75
|
+
if (!nameMatch) {
|
|
76
|
+
i++;
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
const name = nameMatch[1];
|
|
80
|
+
i += name.length;
|
|
81
|
+
while (i < s.length && /\s/.test(s[i]))
|
|
82
|
+
i++;
|
|
83
|
+
if (s[i] !== '=') {
|
|
84
|
+
result[name] = true;
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
i++; // skip '='
|
|
88
|
+
while (i < s.length && /\s/.test(s[i]))
|
|
89
|
+
i++;
|
|
90
|
+
if (s[i] === '"') {
|
|
91
|
+
const endQuote = s.indexOf('"', i + 1);
|
|
92
|
+
if (endQuote === -1) {
|
|
93
|
+
result[name] = '';
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
result[name] = s.slice(i + 1, endQuote);
|
|
97
|
+
i = endQuote + 1;
|
|
98
|
+
}
|
|
99
|
+
else if (s[i] === '{') {
|
|
100
|
+
const expr = extractBraceExpression(s, i);
|
|
101
|
+
if (expr) {
|
|
102
|
+
try {
|
|
103
|
+
result[name] = JSON.parse(expr.content.replace(/'/g, '"'));
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
result[name] = expr.content;
|
|
107
|
+
}
|
|
108
|
+
i = expr.endIndex;
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
i++;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
i++;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return result;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Serialize a props object back to JSX-style props string.
|
|
122
|
+
* Reverses parseJsxProps().
|
|
123
|
+
*
|
|
124
|
+
* Rules:
|
|
125
|
+
* - string → prop="value"
|
|
126
|
+
* - boolean true → prop (shorthand)
|
|
127
|
+
* - number → prop={value}
|
|
128
|
+
* - array/object → prop={JSON}
|
|
129
|
+
*/
|
|
130
|
+
export function serializeProps(props) {
|
|
131
|
+
const parts = [];
|
|
132
|
+
for (const [key, value] of Object.entries(props)) {
|
|
133
|
+
if (value === undefined || value === null)
|
|
134
|
+
continue;
|
|
135
|
+
if (value === true) {
|
|
136
|
+
parts.push(key);
|
|
137
|
+
}
|
|
138
|
+
else if (typeof value === 'string') {
|
|
139
|
+
parts.push(`${key}="${value}"`);
|
|
140
|
+
}
|
|
141
|
+
else if (typeof value === 'number') {
|
|
142
|
+
parts.push(`${key}={${value}}`);
|
|
143
|
+
}
|
|
144
|
+
else if (typeof value === 'boolean') {
|
|
145
|
+
parts.push(`${key}={${value}}`);
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
// Arrays and objects → JSON
|
|
149
|
+
parts.push(`${key}={${JSON.stringify(value)}}`);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return parts.join(' ');
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Serialize a component back to JSX-style MDX syntax.
|
|
156
|
+
*
|
|
157
|
+
* @param name - Component name (e.g., "Callout")
|
|
158
|
+
* @param props - Component props object
|
|
159
|
+
* @param children - Inner content (if any). If empty/undefined, produces self-closing tag.
|
|
160
|
+
*/
|
|
161
|
+
export function serializeComponent(name, props, children) {
|
|
162
|
+
const propsStr = serializeProps(props);
|
|
163
|
+
const propsWithSpace = propsStr ? ` ${propsStr}` : '';
|
|
164
|
+
if (!children) {
|
|
165
|
+
return `<${name}${propsWithSpace} />`;
|
|
166
|
+
}
|
|
167
|
+
return `<${name}${propsWithSpace}>\n${children}\n</${name}>`;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Strip YAML frontmatter from MDX content.
|
|
171
|
+
*/
|
|
172
|
+
export function stripFrontmatter(source) {
|
|
173
|
+
if (source.startsWith('---')) {
|
|
174
|
+
const endIndex = source.indexOf('---', 3);
|
|
175
|
+
if (endIndex !== -1) {
|
|
176
|
+
return source.substring(endIndex + 3).trim();
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return source;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Extract frontmatter string from MDX content.
|
|
183
|
+
* Returns the frontmatter block (without delimiters) or null if none.
|
|
184
|
+
*/
|
|
185
|
+
export function extractFrontmatter(source) {
|
|
186
|
+
if (source.startsWith('---')) {
|
|
187
|
+
const endIndex = source.indexOf('---', 3);
|
|
188
|
+
if (endIndex !== -1) {
|
|
189
|
+
return source.substring(3, endIndex).trim();
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Extract MDX components from content, splitting into html chunks and component definitions.
|
|
196
|
+
* Does NOT process markdown → HTML (caller handles that).
|
|
197
|
+
*
|
|
198
|
+
* @param content - MDX content (frontmatter should already be stripped)
|
|
199
|
+
* @returns Array of parsed content items
|
|
200
|
+
*/
|
|
201
|
+
export function extractMdxComponents(content) {
|
|
202
|
+
if (!HAS_MDX_RE.test(content)) {
|
|
203
|
+
return [{ type: 'html', content }];
|
|
204
|
+
}
|
|
205
|
+
const componentRe = new RegExp(MDX_COMPONENT_PATTERN.source, 'g');
|
|
206
|
+
const items = [];
|
|
207
|
+
let lastIndex = 0;
|
|
208
|
+
let match;
|
|
209
|
+
while ((match = componentRe.exec(content)) !== null) {
|
|
210
|
+
if (match.index > lastIndex) {
|
|
211
|
+
const raw = content.slice(lastIndex, match.index);
|
|
212
|
+
if (raw.trim()) {
|
|
213
|
+
items.push({ type: 'html', content: raw });
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
const name = match[1] || match[4] || '';
|
|
217
|
+
const propsStr = match[1] ? (match[2] || '') : (match[5] || '');
|
|
218
|
+
const children = match[3];
|
|
219
|
+
items.push({
|
|
220
|
+
type: 'component',
|
|
221
|
+
name,
|
|
222
|
+
props: parseJsxProps(propsStr),
|
|
223
|
+
children: children?.trim(),
|
|
224
|
+
});
|
|
225
|
+
lastIndex = match.index + match[0].length;
|
|
226
|
+
}
|
|
227
|
+
if (lastIndex < content.length) {
|
|
228
|
+
const remaining = content.slice(lastIndex);
|
|
229
|
+
if (remaining.trim()) {
|
|
230
|
+
items.push({ type: 'html', content: remaining });
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
// Fallback: regex found no components despite HAS_MDX_RE match
|
|
234
|
+
if (items.length === 0 && content.trim()) {
|
|
235
|
+
return [{ type: 'html', content }];
|
|
236
|
+
}
|
|
237
|
+
return items;
|
|
238
|
+
}
|
|
239
|
+
//# sourceMappingURL=useMdxParsing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMdxParsing.js","sourceRoot":"","sources":["../../src/composables/useMdxParsing.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,oFAAoF;AACpF,MAAM,CAAC,MAAM,UAAU,GAAG,uBAAuB,CAAA;AAEjD;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAChC,0FAA0F,CAAA;AAE5F;;;GAGG;AACH,MAAM,UAAU,sBAAsB,CAAC,GAAW,EAAE,UAAkB;IACpE,IAAI,GAAG,CAAC,UAAU,CAAC,KAAK,GAAG;QAAE,OAAO,IAAI,CAAA;IAExC,IAAI,KAAK,GAAG,CAAC,CAAA;IACb,IAAI,QAAQ,GAAkB,IAAI,CAAA;IAElC,KAAK,IAAI,CAAC,GAAG,UAAU,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAA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AC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAA;QAC/D,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,CAAC,CAAA;QAEzB,KAAK,CAAC,IAAI,CAAC;YACT,IAAI,EAAE,WAAW;YACjB,IAAI;YACJ,KAAK,EAAE,aAAa,CAAC,QAAQ,CAAC;YAC9B,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE;SAC3B,CAAC,CAAA;QAEF,SAAS,GAAG,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAA;IAC3C,CAAC;IAED,IAAI,SAAS,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;QAC/B,MAAM,SAAS,GAAG,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,CAAA;QAC1C,IAAI,SAAS,CAAC,IAAI,EAAE,EAAE,CAAC;YACrB,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,CAAA;QAClD,CAAC;IACH,CAAC;IAED,+DAA+D;IAC/D,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,IAAI,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC;QACzC,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAA;IACpC,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @blogmcp/mdx-schema
|
|
3
|
+
*
|
|
4
|
+
* Framework-agnostic contract for MDX components. Pure TypeScript — no Vue, no React.
|
|
5
|
+
*
|
|
6
|
+
* Three concerns:
|
|
7
|
+
* - Types: prop shapes + blog config
|
|
8
|
+
* - Metadata: hand-curated component descriptions (drives MCP + agent UX)
|
|
9
|
+
* - Parsing: JSX-style component extraction/serialization
|
|
10
|
+
*
|
|
11
|
+
* Framework renderer packages (@blogmcp/mdx-render-vue, future mdx-render-react)
|
|
12
|
+
* import schemas from here and attach their own component implementations.
|
|
13
|
+
*/
|
|
14
|
+
export * from './types/index.js';
|
|
15
|
+
export * from './metadata/index.js';
|
|
16
|
+
export * from './composables/useMdxParsing.js';
|
|
17
|
+
export * from './metadata/validate.js';
|
|
18
|
+
export * from './styles/index.js';
|
|
19
|
+
export * from './version.js';
|
|
20
|
+
export * from './prepareProps.js';
|
|
21
|
+
export * from './checkPin.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @blogmcp/mdx-schema
|
|
3
|
+
*
|
|
4
|
+
* Framework-agnostic contract for MDX components. Pure TypeScript — no Vue, no React.
|
|
5
|
+
*
|
|
6
|
+
* Three concerns:
|
|
7
|
+
* - Types: prop shapes + blog config
|
|
8
|
+
* - Metadata: hand-curated component descriptions (drives MCP + agent UX)
|
|
9
|
+
* - Parsing: JSX-style component extraction/serialization
|
|
10
|
+
*
|
|
11
|
+
* Framework renderer packages (@blogmcp/mdx-render-vue, future mdx-render-react)
|
|
12
|
+
* import schemas from here and attach their own component implementations.
|
|
13
|
+
*/
|
|
14
|
+
export * from './types/index.js';
|
|
15
|
+
export * from './metadata/index.js';
|
|
16
|
+
export * from './composables/useMdxParsing.js';
|
|
17
|
+
export * from './metadata/validate.js';
|
|
18
|
+
export * from './styles/index.js';
|
|
19
|
+
export * from './version.js';
|
|
20
|
+
export * from './prepareProps.js';
|
|
21
|
+
export * from './checkPin.js';
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,cAAc,kBAAkB,CAAA;AAChC,cAAc,qBAAqB,CAAA;AACnC,cAAc,gCAAgC,CAAA;AAC9C,cAAc,wBAAwB,CAAA;AACtC,cAAc,mBAAmB,CAAA;AACjC,cAAc,cAAc,CAAA;AAC5B,cAAc,mBAAmB,CAAA;AACjC,cAAc,eAAe,CAAA"}
|