Skip to content

fix(svg): add accessible title and desc tags#116

Open
tanu13708-commits wants to merge 1 commit into
JhaSourav07:mainfrom
tanu13708-commits:patch-1
Open

fix(svg): add accessible title and desc tags#116
tanu13708-commits wants to merge 1 commit into
JhaSourav07:mainfrom
tanu13708-commits:patch-1

Conversation

@tanu13708-commits
Copy link
Copy Markdown

Fixes #70

Summary

Added semantic <title> and <desc> tags inside generated SVGs to improve accessibility for screen readers.

Changes Made

  • Added role="img" to SVG elements
  • Added dynamic <title> tags
  • Added dynamic <desc> tags using contribution stats
  • Updated both standard and auto-theme SVG generators

Pillar

  • 🎨 Pillar 1 — New Theme Design
  • 📐 Pillar 2 — Geometric SVG Improvement
  • 🕐 Pillar 3 — Timezone Logic Optimization
  • 🛠️ Other (Bug fix, refactoring, docs)

Visual Preview

N/A — accessibility-focused update with no visual rendering changes.

Checklist before requesting a review:

  • I have read the CONTRIBUTING.md file.
  • I have tested these changes locally (localhost:3000/api/streak?user=YOUR_USERNAME).
  • I have run npm run format and npm run lint locally and resolved all errors (CI will fail otherwise).
  • My commits follow the Conventional Commits format (e.g., feat(themes): ..., fix(calculate): ...).
  • I have updated README.md if I added a new theme or URL parameter.
  • I have started the repo.
  • I have made sure that i have only one commit to merge in this PR.
  • The SVG output matches the CommitPulse "premium quality" aesthetic standard (no raw elements, smooth animations, correct fonts).

Result

Screen readers can now interpret contribution statistics without affecting visual rendering.

Copilot AI review requested due to automatic review settings May 16, 2026 17:28
@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented May 16, 2026

@tanu13708-commits is attempting to deploy a commit to the jhasourav07's projects Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Copy Markdown
Contributor

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

Adds semantic accessibility metadata to the generated SVG so screen readers can announce what the badge represents and summarize contribution stats (per Issue #70).

Changes:

  • Adds role="img" to the root <svg> element.
  • Injects a root-level <title> containing the username.
  • Injects a root-level <desc> summarizing totalContributions and longestStreak for both static and auto-theme SVG renderers.
Comments suppressed due to low confidence (2)

lib/svg/generator.ts:388

  • Same issue in the auto-theme renderer: <title>/<desc> interpolate params.user without XML escaping, which can produce invalid SVG or allow markup injection. Apply the same XML-escape helper here to keep both render paths consistent and safe.
  <title>CommitPulse Stats for ${params.user || 'GitHub User'}</title>
  <desc>
    ${params.user || 'This user'} has ${stats.totalContributions} total contributions and a longest streak of ${stats.longestStreak} days.
  </desc>

lib/svg/generator.ts:230

  • There are existing Vitest tests for generateSVG, but none assert the new accessibility output. Please add/adjust tests to verify the root-level <title> and <desc> are present and that usernames are safely escaped (e.g., a username containing & or <). This will prevent regressions across both static and auto-theme code paths.
  <title>CommitPulse Stats for ${params.user || 'GitHub User'}</title>
  <desc>
    ${params.user || 'This user'} has ${stats.totalContributions} total contributions and a longest streak of ${stats.longestStreak} days.
  </desc>

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

Comment thread lib/svg/generator.ts Outdated
Comment on lines +227 to +230
<title>CommitPulse Stats for ${params.user || 'GitHub User'}</title>
<desc>
${params.user || 'This user'} has ${stats.totalContributions} total contributions and a longest streak of ${stats.longestStreak} days.
</desc>
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Kindly Address this

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

okk let me check

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

yes got it ,let me try to fix

Copy link
Copy Markdown
Author

@tanu13708-commits tanu13708-commits left a comment

Choose a reason for hiding this comment

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

Thanks for the feedback!
I’ve added XML escaping for the username and updated the related title, description, and text fields in both SVG generators.

Copy link
Copy Markdown
Author

@tanu13708-commits tanu13708-commits left a comment

Choose a reason for hiding this comment

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

added the function escapeXML

@tanu13708-commits
Copy link
Copy Markdown
Author

tanu13708-commits commented May 16, 2026

@JhaSourav07 KINDLY check it and please let me know if any errors

@JhaSourav07
Copy link
Copy Markdown
Owner

can you keep the commit to one?

@JhaSourav07
Copy link
Copy Markdown
Owner

  • I have made sure that i have only one commit to merge in this PR.

This is Mandatory

@tanu13708-commits
Copy link
Copy Markdown
Author

tanu13708-commits commented May 17, 2026

@JhaSourav07 Ok sir

Added semantic title and desc tags to improve SVG accessibility for screen readers.

Escape XML characters in user title and labels

Thanks for pointing this out!

I’ve added XML escaping for user-controlled strings using an escapeXML() helper and updated the affected <title>, <desc>, and SVG text usages in both SVG generators to prevent malformed SVG/XML injection issues.

Implement escapeXML function for XML escaping

Add escapeXML function to sanitize XML strings

fix(svg): add accessible title/desc tags and escape XML

- Added semantic title and desc tags for accessibility
- Implemented escapeXML helper to sanitize user strings
- Escaped XML characters in user-controlled labels
@tanu13708-commits
Copy link
Copy Markdown
Author

tanu13708-commits commented May 17, 2026

@JhaSourav07 Hello! I’ve squashed all commits into a single one.
Please let me know if there’s anything else needed.
Thanks again for your time and support!

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.

Core: Inject semantic <title> and <desc> into generated SVGs

3 participants