@blogmcp/render-embed 0.2.2 → 0.3.1
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/LICENSE +21 -0
- package/dist/parse.d.ts +9 -4
- package/dist/parse.js +30 -34
- package/dist/parse.js.map +1 -1
- package/package.json +3 -3
- package/src/parse.ts +30 -32
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Lukas Zubal
|
|
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.
|
package/dist/parse.d.ts
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* post-frontmatter body) — host-assigned, the shared anchor key across live + fallback rendering.
|
|
9
9
|
*/
|
|
10
10
|
import { Marked } from 'marked';
|
|
11
|
+
import { computeBodyOffset } from '@blogmcp/mdx-schema/composables/parsing';
|
|
11
12
|
import type { ParsedArticle, SourceRange } from './types.js';
|
|
12
13
|
/**
|
|
13
14
|
* A GFM `marked` instance whose `walkTokens` hook runs every link/image URL through `sanitizeUrl`
|
|
@@ -27,11 +28,15 @@ import type { ParsedArticle, SourceRange } from './types.js';
|
|
|
27
28
|
*/
|
|
28
29
|
export declare function createDefaultMarked(): Marked;
|
|
29
30
|
/**
|
|
30
|
-
* Exact start offset of the trimmed body within `content
|
|
31
|
-
*
|
|
32
|
-
*
|
|
31
|
+
* Exact start offset of the trimmed body within `content`. Lets a splice map a body-relative range
|
|
32
|
+
* to a full-content slice without an ambiguous `indexOf`.
|
|
33
|
+
*
|
|
34
|
+
* Re-exported from `@blogmcp/mdx-schema`, which now owns it: this file had a verbatim copy, and so
|
|
35
|
+
* did `mcp-app-article-review`. Three independent definitions of "where does the body start" is one
|
|
36
|
+
* definition too many when they feed splice ranges — the offset base now lives next to the scan that
|
|
37
|
+
* produces the offsets it is added to.
|
|
33
38
|
*/
|
|
34
|
-
export
|
|
39
|
+
export { computeBodyOffset };
|
|
35
40
|
/**
|
|
36
41
|
* Split a markdown span into top-level BLOCK units, each with its source range within `src`. Uses
|
|
37
42
|
* marked's block lexer (whose token `raw` values concatenate back to the input); GUARDS on that
|
package/dist/parse.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { Marked } from 'marked';
|
|
11
11
|
import { sanitizeHtml, sanitizeUrl } from '@blogmcp/sanitize';
|
|
12
|
-
import {
|
|
12
|
+
import { stripFrontmatter, HAS_MDX_RE, scanMdxNodes, computeBodyOffset, } from '@blogmcp/mdx-schema/composables/parsing';
|
|
13
13
|
/**
|
|
14
14
|
* Detects raw HTML in a markdown SOURCE — the fast-path-skip guard in `renderMarkdownSafe`.
|
|
15
15
|
* Matches `<`+letter (tag), `<!` (comment/doctype), `</` (closing); does NOT match bare `<` in
|
|
@@ -57,27 +57,15 @@ function renderMarkdownSafe(src, marked) {
|
|
|
57
57
|
return sanitizeHtml(html);
|
|
58
58
|
}
|
|
59
59
|
/**
|
|
60
|
-
* Exact start offset of the trimmed body within `content
|
|
61
|
-
*
|
|
62
|
-
*
|
|
60
|
+
* Exact start offset of the trimmed body within `content`. Lets a splice map a body-relative range
|
|
61
|
+
* to a full-content slice without an ambiguous `indexOf`.
|
|
62
|
+
*
|
|
63
|
+
* Re-exported from `@blogmcp/mdx-schema`, which now owns it: this file had a verbatim copy, and so
|
|
64
|
+
* did `mcp-app-article-review`. Three independent definitions of "where does the body start" is one
|
|
65
|
+
* definition too many when they feed splice ranges — the offset base now lives next to the scan that
|
|
66
|
+
* produces the offsets it is added to.
|
|
63
67
|
*/
|
|
64
|
-
export
|
|
65
|
-
if (!content)
|
|
66
|
-
return 0;
|
|
67
|
-
let preBodyEnd = 0;
|
|
68
|
-
if (content.startsWith('---')) {
|
|
69
|
-
const endIndex = content.indexOf('---', 3);
|
|
70
|
-
if (endIndex === -1)
|
|
71
|
-
return 0; // unterminated frontmatter → stripFrontmatter returns source as-is
|
|
72
|
-
preBodyEnd = endIndex + 3;
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
return 0; // no frontmatter → stripFrontmatter returns source as-is (no trim)
|
|
76
|
-
}
|
|
77
|
-
const afterDelim = content.slice(preBodyEnd);
|
|
78
|
-
const leadingWs = afterDelim.length - afterDelim.trimStart().length;
|
|
79
|
-
return preBodyEnd + leadingWs;
|
|
80
|
-
}
|
|
68
|
+
export { computeBodyOffset };
|
|
81
69
|
/**
|
|
82
70
|
* Split a markdown span into top-level BLOCK units, each with its source range within `src`. Uses
|
|
83
71
|
* marked's block lexer (whose token `raw` values concatenate back to the input); GUARDS on that
|
|
@@ -153,25 +141,33 @@ export function parseArticle(content, marked = createDefaultMarked()) {
|
|
|
153
141
|
return { mode: 'html', html: renderMarkdownSafe(body, marked), items: [], body, bodyOffset };
|
|
154
142
|
}
|
|
155
143
|
// MDX path: markdown chunks (themselves block-split) interleaved with component nodes.
|
|
156
|
-
|
|
144
|
+
//
|
|
145
|
+
// `scanMdxNodes` replaces a local MDX_COMPONENT_PATTERN walk that carried both scanner bugs
|
|
146
|
+
// independently — a prose `<Gallery>` mention ran to the next '/>' anywhere in the document, and a
|
|
147
|
+
// component shown inside a ``` fence became a live component node with a `sourceRange` an editor
|
|
148
|
+
// could then splice. See the @deprecated block on MDX_COMPONENT_PATTERN for the measurements.
|
|
149
|
+
//
|
|
150
|
+
// ⚠ Only the COMPONENT nodes are consumed. The gaps keep going through this file's own
|
|
151
|
+
// `pushMarkdownBlocks`, deliberately: it block-splits with a different whitespace policy, and
|
|
152
|
+
// consuming the walk's `html` nodes instead would renumber `mdx-N` and shift `sourceRange` for
|
|
153
|
+
// EVERY article, not just the fence-bearing ones — silently invalidating anchors that already
|
|
154
|
+
// exist in stored review comments.
|
|
157
155
|
let lastIndex = 0;
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
156
|
+
for (const node of scanMdxNodes(body)) {
|
|
157
|
+
if (node.type !== 'component')
|
|
158
|
+
continue;
|
|
159
|
+
if (node.start > lastIndex) {
|
|
160
|
+
pushMarkdownBlocks(body.slice(lastIndex, node.start), lastIndex);
|
|
162
161
|
}
|
|
163
|
-
const name = match[1] || match[4] || '';
|
|
164
|
-
const propsStr = match[1] ? match[2] || '' : match[5] || '';
|
|
165
|
-
const children = match[3];
|
|
166
162
|
items.push({
|
|
167
163
|
type: 'component',
|
|
168
|
-
name,
|
|
169
|
-
props:
|
|
170
|
-
children: children
|
|
164
|
+
name: node.name,
|
|
165
|
+
props: node.props,
|
|
166
|
+
children: node.children,
|
|
171
167
|
nodeId: nextId(),
|
|
172
|
-
sourceRange: { start:
|
|
168
|
+
sourceRange: { start: node.start, end: node.end },
|
|
173
169
|
});
|
|
174
|
-
lastIndex =
|
|
170
|
+
lastIndex = node.end;
|
|
175
171
|
}
|
|
176
172
|
if (lastIndex < body.length) {
|
|
177
173
|
pushMarkdownBlocks(body.slice(lastIndex), lastIndex);
|
package/dist/parse.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse.js","sourceRoot":"","sources":["../src/parse.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC7D,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"parse.js","sourceRoot":"","sources":["../src/parse.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC7D,OAAO,EACL,gBAAgB,EAChB,UAAU,EACV,YAAY,EACZ,iBAAiB,GAClB,MAAM,yCAAyC,CAAA;AAGhD;;;;;GAKG;AACH,MAAM,eAAe,GAAG,aAAa,CAAA;AAErC;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,mBAAmB;IACjC,OAAO,IAAI,MAAM,CAAC;QAChB,UAAU,CAAC,KAAK;YACd,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;gBACpD,KAAK,CAAC,IAAI,GAAG,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;YACtC,CAAC;QACH,CAAC;KACF,CAAC,CAAA;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,kBAAkB,CAAC,GAAW,EAAE,MAAc;IACrD,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAW,CAAA;IAC1D,IAAI,CAAC,eAAe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YACjB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,MAAM,EAAE,MAAM,EAAE;YAChB,WAAW,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE;SAClD,CAAC,CAAA;QACF,SAAS,GAAG,IAAI,CAAC,GAAG,CAAA;IACtB,CAAC;IAED,IAAI,SAAS,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;QAC5B,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,SAAS,CAAC,CAAA;IACtD,CAAC;IAED,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,IAAI,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC;QACtC,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,kBAAkB,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,CAAA;IAC9F,CAAC;IAED,MAAM,YAAY,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,KAAK,WAAW,CAAC,CAAA;IAChE,OAAO,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,CAAA;AACnF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blogmcp/render-embed",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Framework-agnostic render-embed protocol + parse for the headless-renderer review overlay (host + renderer postMessage bridges).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -55,8 +55,8 @@
|
|
|
55
55
|
"typecheck": "tsc --noEmit"
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@blogmcp/mdx-schema": "^0.
|
|
59
|
-
"@blogmcp/sanitize": "^0.
|
|
58
|
+
"@blogmcp/mdx-schema": "^0.5.0",
|
|
59
|
+
"@blogmcp/sanitize": "^0.3.0",
|
|
60
60
|
"marked": "^15.0.7",
|
|
61
61
|
"zod": "^3.23.8"
|
|
62
62
|
},
|
package/src/parse.ts
CHANGED
|
@@ -11,10 +11,10 @@
|
|
|
11
11
|
import { Marked } from 'marked'
|
|
12
12
|
import { sanitizeHtml, sanitizeUrl } from '@blogmcp/sanitize'
|
|
13
13
|
import {
|
|
14
|
-
parseJsxProps,
|
|
15
14
|
stripFrontmatter,
|
|
16
15
|
HAS_MDX_RE,
|
|
17
|
-
|
|
16
|
+
scanMdxNodes,
|
|
17
|
+
computeBodyOffset,
|
|
18
18
|
} from '@blogmcp/mdx-schema/composables/parsing'
|
|
19
19
|
import type { ParsedArticle, RenderUnit, SourceRange } from './types.js'
|
|
20
20
|
|
|
@@ -67,24 +67,15 @@ function renderMarkdownSafe(src: string, marked: Marked): string {
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
/**
|
|
70
|
-
* Exact start offset of the trimmed body within `content
|
|
71
|
-
*
|
|
72
|
-
*
|
|
70
|
+
* Exact start offset of the trimmed body within `content`. Lets a splice map a body-relative range
|
|
71
|
+
* to a full-content slice without an ambiguous `indexOf`.
|
|
72
|
+
*
|
|
73
|
+
* Re-exported from `@blogmcp/mdx-schema`, which now owns it: this file had a verbatim copy, and so
|
|
74
|
+
* did `mcp-app-article-review`. Three independent definitions of "where does the body start" is one
|
|
75
|
+
* definition too many when they feed splice ranges — the offset base now lives next to the scan that
|
|
76
|
+
* produces the offsets it is added to.
|
|
73
77
|
*/
|
|
74
|
-
export
|
|
75
|
-
if (!content) return 0
|
|
76
|
-
let preBodyEnd = 0
|
|
77
|
-
if (content.startsWith('---')) {
|
|
78
|
-
const endIndex = content.indexOf('---', 3)
|
|
79
|
-
if (endIndex === -1) return 0 // unterminated frontmatter → stripFrontmatter returns source as-is
|
|
80
|
-
preBodyEnd = endIndex + 3
|
|
81
|
-
} else {
|
|
82
|
-
return 0 // no frontmatter → stripFrontmatter returns source as-is (no trim)
|
|
83
|
-
}
|
|
84
|
-
const afterDelim = content.slice(preBodyEnd)
|
|
85
|
-
const leadingWs = afterDelim.length - afterDelim.trimStart().length
|
|
86
|
-
return preBodyEnd + leadingWs
|
|
87
|
-
}
|
|
78
|
+
export { computeBodyOffset }
|
|
88
79
|
|
|
89
80
|
/**
|
|
90
81
|
* Split a markdown span into top-level BLOCK units, each with its source range within `src`. Uses
|
|
@@ -163,26 +154,33 @@ export function parseArticle(content: string, marked: Marked = createDefaultMark
|
|
|
163
154
|
}
|
|
164
155
|
|
|
165
156
|
// MDX path: markdown chunks (themselves block-split) interleaved with component nodes.
|
|
166
|
-
|
|
157
|
+
//
|
|
158
|
+
// `scanMdxNodes` replaces a local MDX_COMPONENT_PATTERN walk that carried both scanner bugs
|
|
159
|
+
// independently — a prose `<Gallery>` mention ran to the next '/>' anywhere in the document, and a
|
|
160
|
+
// component shown inside a ``` fence became a live component node with a `sourceRange` an editor
|
|
161
|
+
// could then splice. See the @deprecated block on MDX_COMPONENT_PATTERN for the measurements.
|
|
162
|
+
//
|
|
163
|
+
// ⚠ Only the COMPONENT nodes are consumed. The gaps keep going through this file's own
|
|
164
|
+
// `pushMarkdownBlocks`, deliberately: it block-splits with a different whitespace policy, and
|
|
165
|
+
// consuming the walk's `html` nodes instead would renumber `mdx-N` and shift `sourceRange` for
|
|
166
|
+
// EVERY article, not just the fence-bearing ones — silently invalidating anchors that already
|
|
167
|
+
// exist in stored review comments.
|
|
167
168
|
let lastIndex = 0
|
|
168
|
-
let match: RegExpExecArray | null
|
|
169
169
|
|
|
170
|
-
|
|
171
|
-
if (
|
|
172
|
-
|
|
170
|
+
for (const node of scanMdxNodes(body)) {
|
|
171
|
+
if (node.type !== 'component') continue
|
|
172
|
+
if (node.start > lastIndex) {
|
|
173
|
+
pushMarkdownBlocks(body.slice(lastIndex, node.start), lastIndex)
|
|
173
174
|
}
|
|
174
|
-
const name = match[1] || match[4] || ''
|
|
175
|
-
const propsStr = match[1] ? match[2] || '' : match[5] || ''
|
|
176
|
-
const children = match[3]
|
|
177
175
|
items.push({
|
|
178
176
|
type: 'component',
|
|
179
|
-
name,
|
|
180
|
-
props:
|
|
181
|
-
children: children
|
|
177
|
+
name: node.name,
|
|
178
|
+
props: node.props,
|
|
179
|
+
children: node.children,
|
|
182
180
|
nodeId: nextId(),
|
|
183
|
-
sourceRange: { start:
|
|
181
|
+
sourceRange: { start: node.start, end: node.end },
|
|
184
182
|
})
|
|
185
|
-
lastIndex =
|
|
183
|
+
lastIndex = node.end
|
|
186
184
|
}
|
|
187
185
|
|
|
188
186
|
if (lastIndex < body.length) {
|