An open API service indexing awesome lists of open source software.

https://github.com/mondeja/strip-gh-theme-links

Strip Github dark/light theme image links
https://github.com/mondeja/strip-gh-theme-links

Last synced: 4 months ago
JSON representation

Strip Github dark/light theme image links

Awesome Lists containing this project

README

          

# strip-gh-theme-links

In Github you can specify the theme an image is displayed to
by using `` HTML blocks in Markdown. See [Specifying the
theme an image is shown to][modes-docs].

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](https://github.com/mondeja/strip-gh-theme-links/releases/tag/v3).

## Install

```sh
npm install strip-gh-theme-links
```

## Usage

### Node.js

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

const content = `



Alt text

`;

console.log(await stripGhThemeLinks(content, "light"));
/* OUTPUT:
Alt text
*/

console.log(await stripGhThemeLinks(content, "dark"));
/* OUTPUT:
Alt text
*/

console.log(await stripGhThemeLinks(content));
/* OUTPUT:
Alt text
*/
```

#### Reference

#
**stripGhThemeLinks**(_content: string_,
_keep?: 'light' | 'dark'_): _Promise\_

- #
_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 `` tag will be used.

### CLI

```sh
strip-gh-theme-links --help
```

### Github Action

```yaml
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](#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](#input-files) is not found or when no image links
are stripped from a file.

[modes-docs]: https://docs.github.com/en/github/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#specifying-the-theme-an-image-is-shown-to