Skip to content

Commit

Permalink
Convert markdown-it plugin to remark plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
7nohe committed Mar 23, 2024
1 parent 23d2d84 commit 475c9b2
Show file tree
Hide file tree
Showing 16 changed files with 1,318 additions and 2,442 deletions.
1 change: 0 additions & 1 deletion .github/FUNDING.yml

This file was deleted.

18 changes: 9 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Install pnpm
uses: pnpm/action-setup@v2
uses: pnpm/action-setup@v3

- name: Set node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: lts/*

Expand All @@ -35,13 +35,13 @@ jobs:
typecheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Install pnpm
uses: pnpm/action-setup@v2
uses: pnpm/action-setup@v3

- name: Set node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: lts/*

Expand All @@ -64,13 +64,13 @@ jobs:
fail-fast: false

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Install pnpm
uses: pnpm/action-setup@v2
uses: pnpm/action-setup@v3

- name: Set node ${{ matrix.node }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install pnpm
uses: pnpm/action-setup@v2
uses: pnpm/action-setup@v3

- name: Set node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: lts/*

Expand Down
1 change: 0 additions & 1 deletion CONTRIBUTING.md

This file was deleted.

21 changes: 0 additions & 21 deletions LICENSE

This file was deleted.

81 changes: 40 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
# markdown-it-github-alerts
# remark-alerts

[![npm version][npm-version-src]][npm-version-href]
[![npm downloads][npm-downloads-src]][npm-downloads-href]
[![bundle][bundle-src]][bundle-href]
[![JSDocs][jsdocs-src]][jsdocs-href]
[![License][license-src]][license-href]
[remark](https://github.com/remarkjs/remark) plugin to support GitHub-style alerts.

This project is a fork of the [antfu/markdown-it-github-alerts](https://github.com/antfu/markdown-it-github-alerts) project.

Support [GitHub-style alerts](https://github.com/orgs/community/discussions/16925) for [markdown-it](https://github.com/markdown-it/markdown-it).

> [!NOTE]
> Highlights information that users should take into account, even when skimming.
Expand Down Expand Up @@ -43,18 +40,43 @@ Support [GitHub-style alerts](https://github.com/orgs/community/discussions/1692
## Usage

```bash
npm i markdown-it-github-alerts
npm i remark-alerts
```

```js
import MarkdownIt from 'markdown-it'
import MarkdownItGitHubAlerts from 'markdown-it-github-alerts'
import { unified } from "unified";
import remarkHtml from "remark-html";
import remarkParse from "remark-parse";
import remarkAlerts from 'remark-alerts'

const content = `
# Hello
> [!NOTE]
> Highlights information that users should take into account, even when skimming.
> [!TIP]
> Optional information to help a user be more successful.
> [!IMPORTANT]
> Crucial information necessary for users to succeed.
const md = MarkdownIt()
> [!WARNING]
> Critical content demanding immediate user attention due to potential risks.
> [!CAUTION]
> Negative potential consequences of an action.
`

md.use(MarkdownItGitHubAlerts, /* Options */)
const parsedContent = await unified()
.use(remarkParse)
.use(remarkAlerts)
.use(remarkHtml, { sanitize: false })
.process(content);

console.log(parsedContent)

const html = md.render(/* ... */)
```

For the options available, please refer to [the jsdoc](./src/index.ts).
Expand Down Expand Up @@ -86,9 +108,9 @@ You can write your custom styles for your alerts.
We also provide some CSS extracted from GitHub's styles for you to use.

```js
import 'markdown-it-github-alerts/styles/github-colors-light.css'
import 'markdown-it-github-alerts/styles/github-colors-dark-media.css'
import 'markdown-it-github-alerts/styles/github-base.css'
import 'remark-alerts/styles/github-colors-light.css'
import 'remark-alerts/styles/github-colors-dark-media.css'
import 'remark-alerts/styles/github-base.css'
```

You might change `github-colors-dark-media.css` to `github-colors-dark-class.css` if you are using class-based (`.dark`) dark mode.
Expand All @@ -100,9 +122,7 @@ Refer to the [source code](./styles) for more details.
In order to also support [Obsidian callouts syntax](https://help.obsidian.md/Editing+and+formatting/Callouts) it is possible to allow any type of markers with the following setting:

```js
md.use(MarkdownItGitHubAlerts, {
markers: '*'
})
unified().use(remarkAlerts, { markers: "*" })
```
Alternative titles are also supported, by appending it to the marker like this:

Expand All @@ -111,27 +131,6 @@ Alternative titles are also supported, by appending it to the marker like this:
> The custom title will replace the regular title.
```

## Sponsors

<p align="center">
<a href="https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg">
<img src='https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg'/>
</a>
</p>

## License

[MIT](./LICENSE) License © 2023-PRESENT [Anthony Fu](https://github.com/antfu)

<!-- Badges -->

[npm-version-src]: https://img.shields.io/npm/v/markdown-it-github-alerts?style=flat&colorA=080f12&colorB=1fa669
[npm-version-href]: https://npmjs.com/package/markdown-it-github-alerts
[npm-downloads-src]: https://img.shields.io/npm/dm/markdown-it-github-alerts?style=flat&colorA=080f12&colorB=1fa669
[npm-downloads-href]: https://npmjs.com/package/markdown-it-github-alerts
[bundle-src]: https://img.shields.io/bundlephobia/minzip/markdown-it-github-alerts?style=flat&colorA=080f12&colorB=1fa669&label=minzip
[bundle-href]: https://bundlephobia.com/result?p=markdown-it-github-alerts
[license-src]: https://img.shields.io/github/license/antfu/markdown-it-github-alerts.svg?style=flat&colorA=080f12&colorB=1fa669
[license-href]: https://github.com/antfu/markdown-it-github-alerts/blob/main/LICENSE
[jsdocs-src]: https://img.shields.io/badge/jsdocs-reference-080f12?style=flat&colorA=080f12&colorB=1fa669
[jsdocs-href]: https://www.jsdocs.io/package/markdown-it-github-alerts
MIT
17 changes: 17 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"$schema": "https://biomejs.dev/schemas/1.6.2/schema.json",
"organizeImports": {
"enabled": true
},
"linter": {
"enabled": true,
"rules": {
"recommended": true
},
"ignore": [".vscode"]
},
"formatter": {
"enabled": true,
"ignore": [".vscode"]
}
}
19 changes: 9 additions & 10 deletions build.config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { defineBuildConfig } from 'unbuild'
import { defineBuildConfig } from "unbuild";

export default defineBuildConfig({
entries: [
'src/index',
],
declaration: true,
clean: true,
rollup: {
emitCJS: true,
},
})
entries: ["src/index"],
declaration: true,
clean: true,
rollup: {
emitCJS: true,
},
externals: ["mdast"],
});
15 changes: 0 additions & 15 deletions eslint.config.js

This file was deleted.

Loading

0 comments on commit 475c9b2

Please sign in to comment.