Skip to content

Fix: Only embed YouTube videos when URL is on its own line #14356

Closed
Shresthap21 wants to merge 5 commits intolaurent22:devfrom
Shresthap21:fix/youtube-inline-embed-14352
Closed

Fix: Only embed YouTube videos when URL is on its own line #14356
Shresthap21 wants to merge 5 commits intolaurent22:devfrom
Shresthap21:fix/youtube-inline-embed-14352

Conversation

@Shresthap21
Copy link

@Shresthap21 Shresthap21 commented Feb 14, 2026

Fixes #14352

Problem

When markdown.plugin.externalEmbed is enabled, YouTube videos were being embedded even when the URL appeared inline with other text, not just when standalone on its own line.

Solution

Modified the externalEmbed plugin to check for surrounding text content before/after YouTube links:

  • Checks for any text tokens before the link in the same paragraph
  • Checks for any text tokens after the link in the same paragraph
  • Only embeds the video if no surrounding text is found (URL is standalone)
  • Inline URLs are now rendered as regular links

Test Cases

Added comprehensive test cases:

  • external_embed_inline.md/html - Tests inline and standalone scenarios
  • external_embed_edges.md/html - Edge cases (URL at start/end of paragraph, multiple URLs)

Examples

Before: Inline URL would embed → Text https://youtube.com/watch?v=xyz more text
After: Inline URL shows as link → Text https://youtube.com/watch?v=xyz more text
Standalone still embeds: Empty line with just URL → Embeds video ✓

Summary by CodeRabbit

  • Tests

    • Added Markdown and HTML test cases covering various external embed edge cases (URLs at start/end of paragraphs, standalone URLs, multiple inline URLs, YouTube embed behaviour).
  • Improvements

    • YouTube/video embedding now triggers only for truly standalone links; links surrounded by other text render as regular anchors.

…#14352)

When markdown.plugin.externalEmbed is enabled, YouTube videos should only be embedded when the URL appears on its own line (standalone), not when inline with other text.

Modified externalEmbed plugin to check for surrounding text content before/after the YouTube link. If any text exists in the same paragraph, the URL is rendered as a regular link instead of an embedded video.

Added test cases for inline and standalone YouTube URLs.
Copilot AI review requested due to automatic review settings February 14, 2026 20:45
@github-actions
Copy link
Contributor

github-actions bot commented Feb 14, 2026

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@coderabbitai
Copy link

coderabbitai bot commented Feb 14, 2026

Walkthrough

Updates add new markdown/HTML test fixtures for external-URL embedding edge cases and tighten the renderer's external-embed rule so YouTube links are embedded only when the link appears on its own line (standalone), not when inline with other text.

Changes

Cohort / File(s) Summary
External Embed Test Cases
packages/app-cli/tests/md_to_html/external_embed_edges.md, packages/app-cli/tests/md_to_html/external_embed_edges.html, packages/app-cli/tests/md_to_html/external_embed_inline.md, packages/app-cli/tests/md_to_html/external_embed_inline.html
Adds new test fixtures covering edge cases for external embedding: URLs at paragraph start/end, standalone URL blocks, and inline multiple URLs. Expected HTML shows standalone YouTube URLs rendered as iframes while inline URLs remain plain links.
Embedding Logic
packages/renderer/MdToHtml/rules/externalEmbed.ts
Changes standalone-link detection: embedding now triggers only when a link has no surrounding content (ignoring whitespace/line breaks). Retains activeEmbedVideo state and existing embed HTML generation, but guards activation with the stricter standalone condition.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 6
✅ Passed checks (6 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: implementing a fix to embed YouTube videos only when the URL appears on its own line, which is the primary objective of the PR.
Linked Issues check ✅ Passed The PR modifications to externalEmbed.ts implement the required detection of standalone URLs, and test files comprehensively cover inline, standalone, and edge-case scenarios as specified in issue #14352.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the linked issue #14352: modifying the embed detection logic and adding comprehensive test fixtures for inline vs. standalone YouTube URL scenarios.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into dev

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

No actionable comments were generated in the recent review. 🎉

🧹 Recent nitpick comments
packages/renderer/MdToHtml/rules/externalEmbed.ts (1)

24-24: Consider resetting state at the start of rendering to improve robustness.

The activeEmbedVideo variable is closure-scoped and persists across renders when the same markdownIt instance is reused. If rendering fails after link_open sets the state but before link_close clears it, stale state could affect subsequent renders.

A defensive approach would be to ensure the state is reset at appropriate boundaries, though this may require architectural changes beyond this PR's scope.


Comment @coderabbitai help to get the list of available commands and usage tips.

@Shresthap21
Copy link
Author

I have read the CLA Document and I hereby sign the CLA

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the Markdown renderer’s externalEmbed rule to only embed YouTube videos when the URL appears standalone (no surrounding content in the same paragraph), and adds regression fixtures to cover inline vs standalone and edge scenarios.

Changes:

  • Add surrounding-content checks before embedding YouTube links in externalEmbed renderer rule.
  • Add new md/html fixture pairs to validate inline URLs remain links while standalone URLs embed.
  • Add additional edge-case fixtures (URL at start/end of paragraph, multiple URLs).

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
packages/renderer/MdToHtml/rules/externalEmbed.ts Adds logic to detect surrounding content and only emit embed markup when the YouTube URL is standalone.
packages/app-cli/tests/md_to_html/external_embed_inline.md New fixture covering inline vs standalone YouTube URLs.
packages/app-cli/tests/md_to_html/external_embed_inline.html Expected HTML output for external_embed_inline.md.
packages/app-cli/tests/md_to_html/external_embed_edges.md New fixture covering edge cases and multiple-URL scenarios.
packages/app-cli/tests/md_to_html/external_embed_edges.html Expected HTML output for external_embed_edges.md.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


But this URL on its own line should be embedded:

https://www.youtube.com/watch?v=standalone456
Copy link

Copilot AI Feb 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

standalone456 is not a valid 11-character YouTube video ID per extractVideoId, so the renderer won’t embed it and this fixture will fail. Replace with an 11-char ID and update the expected HTML snapshot accordingly.

Suggested change
https://www.youtube.com/watch?v=standalone456
https://www.youtube.com/watch?v=abcdefghijk

Copilot uses AI. Check for mistakes.
github-actions bot added a commit that referenced this pull request Feb 14, 2026
Shresthap21 and others added 4 commits February 15, 2026 02:22
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@laurent22
Copy link
Owner

Thanks for the submission.

While this PR targets an existing issue, the proposed solution is not suitable for the project in its current form. Bringing it up to an acceptable standard would require significant redesign and guidance.

For future contributions, please ensure changes are well-aligned with the existing architecture and sufficiently tested.

Please do not open another PR for this issue.

@laurent22 laurent22 closed this Feb 15, 2026
Repository owner locked as spam and limited conversation to collaborators Feb 15, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

YouTube video are displayed inline too

2 participants