|
23 | 23 | * - <SetupSteps>/<SetupStep> → prose children + code from the `code={}` prop |
24 | 24 | * - <ZoomPanPinch> → transparent wrapper, pass inner content |
25 | 25 | * - <ViewSourceCodeNotice href> → plain markdown link line |
| 26 | + * - YouTube/HTML embeds → stripped (keep a markdown Watch link in prose for LLMs) |
26 | 27 | * - imported .md components → transcluded inline (e.g. <AWSRegions />) |
27 | 28 | * - import / export stmts → stripped |
28 | 29 | * - {/* MDX comments */} → stripped |
@@ -447,6 +448,36 @@ const State = { |
447 | 448 | SETUP_STEP: "SETUP_STEP", |
448 | 449 | }; |
449 | 450 |
|
| 451 | +/** |
| 452 | + * If `lines[i]` starts an HTML/JSX video embed (`<iframe>` or styled `<div>` |
| 453 | + * wrapping one), return the inclusive end index of the block. Otherwise null. |
| 454 | + * Authors should keep a markdown Watch link in surrounding prose for LLMs. |
| 455 | + */ |
| 456 | +export function findHtmlEmbedEnd(lines, i) { |
| 457 | + const trimmed = (lines[i] || "").trim(); |
| 458 | + if (/^<iframe\b/i.test(trimmed)) { |
| 459 | + let j = i; |
| 460 | + while (j < lines.length) { |
| 461 | + if (/<\/iframe>/i.test(lines[j]) || /\/>\s*$/.test(lines[j].trim())) { |
| 462 | + return j; |
| 463 | + } |
| 464 | + j++; |
| 465 | + } |
| 466 | + return i; |
| 467 | + } |
| 468 | + if (/^<div\b/i.test(trimmed) && /style=\{/.test(trimmed)) { |
| 469 | + let depth = 0; |
| 470 | + for (let j = i; j < lines.length; j++) { |
| 471 | + if (/<div\b/i.test(lines[j])) depth++; |
| 472 | + if (/<\/div>/i.test(lines[j])) { |
| 473 | + depth--; |
| 474 | + if (depth === 0) return j; |
| 475 | + } |
| 476 | + } |
| 477 | + } |
| 478 | + return null; |
| 479 | +} |
| 480 | + |
450 | 481 | /** |
451 | 482 | * Main transform function. |
452 | 483 | * @param {string} mdxContent - raw MDX file content |
@@ -876,6 +907,12 @@ export function transformMdx(mdxContent, options = {}) { |
876 | 907 | admonitionLines = []; |
877 | 908 | admonitionType = null; |
878 | 909 | } else { |
| 910 | + // Drop YouTube/HTML embeds inside tips; keep the markdown Watch link. |
| 911 | + const embedEnd = findHtmlEmbedEnd(lines, i); |
| 912 | + if (embedEnd !== null) { |
| 913 | + i = embedEnd; |
| 914 | + continue; |
| 915 | + } |
879 | 916 | admonitionLines.push(line); |
880 | 917 | } |
881 | 918 | continue; |
@@ -1098,6 +1135,15 @@ export function transformMdx(mdxContent, options = {}) { |
1098 | 1135 | continue; |
1099 | 1136 | } |
1100 | 1137 |
|
| 1138 | + // --- HTML/JSX video embeds (YouTube iframes) — strip; keep prose links --- |
| 1139 | + if (state === State.NORMAL) { |
| 1140 | + const embedEnd = findHtmlEmbedEnd(lines, i); |
| 1141 | + if (embedEnd !== null) { |
| 1142 | + i = embedEnd; |
| 1143 | + continue; |
| 1144 | + } |
| 1145 | + } |
| 1146 | + |
1101 | 1147 | // --- Image components (self-closing, may span lines) --- |
1102 | 1148 | // <CaptionedImage|EnlargeImage|Components.CaptionedImage |
1103 | 1149 | // src="..." alt|caption|title="..." /> →  |
|
0 commit comments