A marked extension to support GFM alert
npm install marked-alertA marked extension to support GFM alerts.
- Install
- Usage
- Options
- Default Alert Variants
- Related
- Contributing
- License
You can install marked-alert using npm or yarn:
``bash`
npm i marked-alertor
yarn add marked-alert

Once you've installed this extension, you can use it in your marked configuration. Here's an example of how to configure it:
Say we have the following file example.md:
`mdExample
> [!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.
> [!WARNING]
> Critical content demanding immediate user attention due to potential risks.
> [!CAUTION]
> Negative potential consequences of an action.
`
And our module example.js looks as follows:
`js
import { readFileSync } from 'node:fs'
import { Marked } from 'marked'
import markedAlert from 'marked-alert'
const html = new Marked()
.use(markedAlert())
.parse(readFileSync('example.md', 'utf8'))
console.log(html)
`
Now, running node example.js yields:
` Optional information to help a user be more successful. Crucial information necessary for users to succeed. Negative potential consequences of an action.html`Example
class="octicon octicon-info mr-2"
viewBox="0 0 16 16"
width="16"
height="16"
aria-hidden="true"
>
> >Note
Highlights information that users should take into account, even when
skimming.
class="octicon octicon-light-bulb mr-2"
viewBox="0 0 16 16"
width="16"
height="16"
aria-hidden="true"
>
> >Tip
class="octicon octicon-report mr-2"
viewBox="0 0 16 16"
width="16"
height="16"
aria-hidden="true"
>
> >Important
class="octicon octicon-alert mr-2"
viewBox="0 0 16 16"
width="16"
height="16"
aria-hidden="true"
>
> >Warning
Critical content demanding immediate user attention due to potential risks.
class="octicon octicon-stop mr-2"
viewBox="0 0 16 16"
width="16"
height="16"
aria-hidden="true"
>
> >Caution
The markedAlert extension accepts the following configuration options:
- className: A string representing a custom CSS class for the alerts.variants
- : An array of alert variants, where each variant is configured with a type, icon, and title class name. This allows you to create different alert types.
The extension includes default alert variants:
- [!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.[!WARNING]
- : Critical content demanding immediate user attention due to potential risks.[!CAUTION]
- : Negative potential consequences of an action.
Each variant has an associated icon and title class name.
You can customize the default alert variants and add your own. Here's an example:
`js`
const options = {
variants: [
{
type: 'danger',
icon: '🚨',
title: 'Oh snap!', // optional
titleClassName: 'text-danger' // optional
}
]
}
See extensions list.
We 💛 issues.
When committing, please conform to the semantic-release commit standards. Please install commitizen and the adapter globally, if you have not already.
`bash`
npm i -g commitizen cz-conventional-changelog
Now you can use git cz or just cz instead of git commit when committing. You can also use git-cz, which is an alias for cz.
`bash``
git add . && git cz
A project by Stilearning © 2023-2024.