npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

strip-gh-theme-links

v5.0.0

Published

Strip Github dark/light theme image links

Downloads

6

Readme

strip-gh-theme-links

In Github you can specify the theme an image is displayed to by using <picture> HTML blocks in Markdown. See Specifying the theme an image is shown to.

However, other platforms currently do not support this tag and will display both versions of the image. So you might want to delete one of the images before uploading your documents to other platforms like, for example, Packagist (PHP) or PyPI (Python).

These npm package, CLI and Github Action are for you. They strip all the image theme links about one of the Github theme versions from your files. Perfect for running it before your packaging step in your release pipelines.

Note
The latest version supporting the deprecated #gh-dark-mode-only and #gh-light-mode-only hashes in inline images is v3.

Install

npm install strip-gh-theme-links

Usage

Node.js

import stripGhThemeLinks from "strip-gh-theme-links";

const content = `
<picture>
  <source media="(prefers-color-scheme: dark)" srcset="https://user-images.githubusercontent.com/dark">
  <source media="(prefers-color-scheme: light)" srcset="https://user-images.githubusercontent.com/light">
  <img alt="Alt text" title="Title text" src="https://user-images.githubusercontent.com/default" width=70>
</picture>
`;

console.log(await stripGhThemeLinks(content, "light"));
/* OUTPUT:
<img src="https://user-images.githubusercontent.com/light" alt="Alt text" title="Title text" width="70">
*/

console.log(await stripGhThemeLinks(content, "dark"));
/* OUTPUT:
<img src="https://user-images.githubusercontent.com/dark" alt="Alt text" title="Title text" width="70">
*/

console.log(await stripGhThemeLinks(content));
/* OUTPUT:
<img src="https://user-images.githubusercontent.com/default" alt="Alt text" title="Title text" width="70">
*/

Reference

# stripGhThemeLinks(content: string, keep?: 'light' | 'dark'): Promise<string>

  • # content ⇒ Content for which the Github theme image links will be stripped.
  • # keep ⇒ Theme variant links to keep in the content. If not specified the src attribute of the <img> tag will be used.

CLI

strip-gh-theme-links --help

Github Action

name: Release
on:
  workflow_dispatch:

jobs:
  release-pr:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Strip Github theme image links
        uses: mondeja/strip-gh-theme-links@v5
        with:
          files: |
            README.md
            CONTRIBUTING.md

Warning
It is recomended to run the CLI with strip-gh-theme-links --diff file.md to check that your files are correctly stripped before configure this action in your release pipeline.

Reference

Inputs
  • # files (required) ⇒ Path to files or globs to strip, separated by newlines.
  • # keep ⇒ Theme variant links to keep in the content of the files.
  • # strict (default: false) ⇒ Treat warnings as errors and exit with code 1. Warnings are raised when a file specified in files input is not found or when no image links are stripped from a file.