Skip to content

feat(remark-lite-youtube): new remark plugin for lite-youtube embeds#294

Open
stephansama wants to merge 1 commit into
mainfrom
stephansama/ste-145-create-lite-youtube-remark-plugin
Open

feat(remark-lite-youtube): new remark plugin for lite-youtube embeds#294
stephansama wants to merge 1 commit into
mainfrom
stephansama/ste-145-create-lite-youtube-remark-plugin

Conversation

@stephansama

Copy link
Copy Markdown
Owner

Closes STE-145

New @stephansama/remark-lite-youtube package at core/remark-lite-youtube/. Remark plugin that transforms YouTube URL links into <lite-youtube videoid='...' playlabel='...'> markup for use with @justinribeiro/lite-youtube (already in the workspace catalog).

Supported URL formats

  • https://www.youtube.com/watch?v={id}
  • https://youtu.be/{id}
  • https://www.youtube.com/embed/{id}

Non-YouTube links are left untouched.

Options

  • defaultPlayLabel — fallback for the playlabel attribute when the markdown link has no text (default: Play).

Tests

8 cases in src/lite-youtube.test.ts covering URL parsing (all three formats + invalid input) and end-to-end remark processing.

Pattern mirrors core/remark-asciinema (same package shape, same plugin shape via unist-util-visit).

@vercel

vercel Bot commented May 18, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
packages Ready Ready Preview, Comment May 18, 2026 3:00am

@changeset-bot

changeset-bot Bot commented May 18, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: e822f9f

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai

coderabbitai Bot commented May 18, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@stephansama has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 25 minutes and 25 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: f7174758-bc7d-4aa2-82d0-e293058a8a75

📥 Commits

Reviewing files that changed from the base of the PR and between 9a84b42 and e822f9f.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (9)
  • README.md
  • core/remark-lite-youtube/README.md
  • core/remark-lite-youtube/package.json
  • core/remark-lite-youtube/src/index.ts
  • core/remark-lite-youtube/src/lite-youtube.test.ts
  • core/remark-lite-youtube/src/lite-youtube.ts
  • core/remark-lite-youtube/src/utilities.ts
  • core/remark-lite-youtube/tsconfig.json
  • core/remark-lite-youtube/tsdown.config.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch stephansama/ste-145-create-lite-youtube-remark-plugin

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@pkg-pr-new

pkg-pr-new Bot commented May 18, 2026

Copy link
Copy Markdown

Open in StackBlitz

@stephansama/ai-commit-msg

pnpm add https://pkg.pr.new/stephansama/packages/@stephansama/ai-commit-msg@294

@stephansama/alfred-kaomoji

pnpm add https://pkg.pr.new/stephansama/packages/@stephansama/alfred-kaomoji@294

@stephansama/astro-iconify-svgmap

pnpm add https://pkg.pr.new/stephansama/packages/@stephansama/astro-iconify-svgmap@294

@stephansama/auto-readme

pnpm add https://pkg.pr.new/stephansama/packages/@stephansama/auto-readme@294

@stephansama/catppuccin-jsonresume-theme

pnpm add https://pkg.pr.new/stephansama/packages/@stephansama/catppuccin-jsonresume-theme@294

@stephansama/catppuccin-opml

pnpm add https://pkg.pr.new/stephansama/packages/@stephansama/catppuccin-opml@294

@stephansama/catppuccin-rss

pnpm add https://pkg.pr.new/stephansama/packages/@stephansama/catppuccin-rss@294

@stephansama/catppuccin-typedoc

pnpm add https://pkg.pr.new/stephansama/packages/@stephansama/catppuccin-typedoc@294

@stephansama/catppuccin-xsl

pnpm add https://pkg.pr.new/stephansama/packages/@stephansama/catppuccin-xsl@294

@stephansama/eslint-config

pnpm add https://pkg.pr.new/stephansama/packages/@stephansama/eslint-config@294

create-stephansama-example

pnpm add https://pkg.pr.new/stephansama/packages/create-stephansama-example@294

@stephansama/find-makefile-targets

pnpm add https://pkg.pr.new/stephansama/packages/@stephansama/find-makefile-targets@294

@stephansama/github-env

pnpm add https://pkg.pr.new/stephansama/packages/@stephansama/github-env@294

@stephansama/multipublish

pnpm add https://pkg.pr.new/stephansama/packages/@stephansama/multipublish@294

@stephansama/pnpm-hooks

pnpm add https://pkg.pr.new/stephansama/packages/@stephansama/pnpm-hooks@294

@stephansama/prettier-plugin-handlebars

pnpm add https://pkg.pr.new/stephansama/packages/@stephansama/prettier-plugin-handlebars@294

@stephansama/remark-asciinema

pnpm add https://pkg.pr.new/stephansama/packages/@stephansama/remark-asciinema@294

@stephansama/remark-lite-youtube

pnpm add https://pkg.pr.new/stephansama/packages/@stephansama/remark-lite-youtube@294

@stephansama/single-file

pnpm add https://pkg.pr.new/stephansama/packages/@stephansama/single-file@294

@stephansama/svelte-social-share-links

pnpm add https://pkg.pr.new/stephansama/packages/@stephansama/svelte-social-share-links@294

@stephansama/typed-env

pnpm add https://pkg.pr.new/stephansama/packages/@stephansama/typed-env@294

@stephansama/typed-events

pnpm add https://pkg.pr.new/stephansama/packages/@stephansama/typed-events@294

@stephansama/typed-nocodb-api

pnpm add https://pkg.pr.new/stephansama/packages/@stephansama/typed-nocodb-api@294

@stephansama/typed-templates

pnpm add https://pkg.pr.new/stephansama/packages/@stephansama/typed-templates@294

@stephansama/types-github-action-env

pnpm add https://pkg.pr.new/stephansama/packages/@stephansama/types-github-action-env@294

@stephansama/types-lhci

pnpm add https://pkg.pr.new/stephansama/packages/@stephansama/types-lhci@294

commit: e822f9f

@codecov

codecov Bot commented May 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new package, @stephansama/remark-lite-youtube, which is a remark plugin designed to transform YouTube links into custom-element markup. The implementation includes comprehensive unit tests and documentation. The review feedback identifies several important improvements: addressing a potential XSS vulnerability by escaping the videoId, lowering the Node.js engine requirement for better compatibility, and enhancing the robustness of the URL parsing and link text extraction logic (including support for YouTube Shorts).

Comment on lines +9 to +18
const label = (playLabel ?? "")
.replaceAll("&", "&amp;")
.replaceAll('"', "&quot;");
return (
'<lite-youtube videoid="' +
videoId +
'" playlabel="' +
label +
'"></lite-youtube>'
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The videoId is injected directly into the HTML string without escaping. While YouTube IDs are typically alphanumeric, the extractYoutubeId function does not validate the format, meaning a malformed or malicious URL could lead to XSS or broken HTML. Both videoId and playLabel should be properly escaped for use in HTML attributes.

Suggested change
const label = (playLabel ?? "")
.replaceAll("&", "&amp;")
.replaceAll('"', "&quot;");
return (
'<lite-youtube videoid="' +
videoId +
'" playlabel="' +
label +
'"></lite-youtube>'
);
const escape = (str: string) => str.replaceAll("&", "&amp;").replaceAll('"', "&quot;");
const id = escape(videoId);
const label = escape(playLabel ?? "");
return (
'<lite-youtube videoid="' +
id +
'" playlabel="' +
label +
'"></lite-youtube>'
);

"unist-util-visit": "catalog:"
},
"engines": {
"node": ">=24"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The engines field specifies node >= 24. Node.js 24 is not yet a stable or LTS release (v22 is the current stable, v20 is LTS). This restriction will prevent the package from being used in most current environments. Consider lowering this to node >= 20 or node >= 22.

Suggested change
"node": ">=24"
"node": ">=20"

Comment on lines +28 to +32
const linkText = node.children
?.filter((child) => child.type === "text")
.map((child) => child.value ?? "")
.join("")
.trim();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The current logic for extracting link text only considers direct text children. If the link contains any nested formatting (e.g., [**My Video**](...) or [*Video*](...)), the text will not be captured correctly, and the fallback label will be used instead. Consider using a utility like mdast-util-to-string or a recursive helper to extract all text content from the link node.

return;
}

const host = url.host.replace(WWW_PREFIX, "");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Using url.hostname instead of url.host is more robust as it excludes the port number, ensuring the domain check works correctly even if a port is specified in the URL.

Suggested change
const host = url.host.replace(WWW_PREFIX, "");
const host = url.hostname.replace(WWW_PREFIX, "");

Comment on lines +43 to +51
if (host === "youtube.com" || host === "m.youtube.com") {
if (url.pathname === "/watch") {
return url.searchParams.get("v") ?? undefined;
}
if (url.pathname.startsWith("/embed/")) {
const id = url.pathname.slice("/embed/".length).split("/")[0];
return id || undefined;
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The plugin currently does not support YouTube Shorts URLs (e.g., https://www.youtube.com/shorts/{id}). Adding support for this format would improve the plugin's utility.

	if (host === "youtube.com" || host === "m.youtube.com") {
		if (url.pathname === "/watch") {
			return url.searchParams.get("v") ?? undefined;
		}
		if (url.pathname.startsWith("/embed/")) {
			const id = url.pathname.slice("/embed/".length).split("/")[0];
			return id || undefined;
		}
		if (url.pathname.startsWith("/shorts/")) {
			const id = url.pathname.slice("/shorts/".length).split("/")[0];
			return id || undefined;
		}
	}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant