Skip to content

Commit

Permalink
feat: add abbr plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Mister-Hope committed May 3, 2024
1 parent f5e79e9 commit 45fdfcb
Show file tree
Hide file tree
Showing 15 changed files with 647 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"docs:dev": "vuepress-vite dev src"
},
"dependencies": {
"@mdit/plugin-abbr": "workspace:*",
"@mdit/plugin-container": "workspace:*",
"@mdit/plugin-snippet": "workspace:*",
"@mdit/plugin-spoiler": "workspace:*",
Expand Down
2 changes: 2 additions & 0 deletions docs/src/.vuepress/config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { abbr } from "@mdit/plugin-abbr";
import { container } from "@mdit/plugin-container";
// import { demo } from "@mdit/plugin-demo";
import { snippet } from "@mdit/plugin-snippet";
Expand Down Expand Up @@ -37,6 +38,7 @@ export default defineUserConfig({
pagePatterns: ["**/*.md", "!**/*.snippet.md", "!.vuepress", "!node_modules"],

extendsMarkdown: (md) => {
md.use(abbr);
md.use(container, {
name: "hint",
openRender: (tokens, index): string => {
Expand Down
5 changes: 5 additions & 0 deletions docs/src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ icon: home
home: true
heroImage: /logo.svg
features:
- title: abbr
icon: book
details: Abbreviation
link: ./abbr.html

- title: alert
icon: bell
details: GFM alerts
Expand Down
87 changes: 87 additions & 0 deletions docs/src/abbr.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
---
title: "@mdit/plugin-abbr"
icon: book
---

Plugin to support abbreviation tag `<abbr>`.

<!-- more -->

## Usage

::: code-tabs#language

@tab TS

```ts
import MarkdownIt from "markdown-it";
import { abbr } from "@mdit/plugin-abbr";

const mdIt = MarkdownIt().use(abbr);

mdIt.render(`
*[HTML]: Hyper Text Markup Language
*[W3C]: World Wide Web Consortium
The HTML specification is maintained by the W3C.
`);
```

@tab JS

```js
const MarkdownIt = require("markdown-it");
const { abbr } = require("@mdit/plugin-abbr");

const mdIt = MarkdownIt().use(abbr);

mdIt.render(`
*[HTML]: Hyper Text Markup Language
*[W3C]: World Wide Web Consortium
The HTML specification is maintained by the W3C.
`);
```

:::

<!-- markdownlint-disable MD028 -->

## Syntax

With this plugin you can declare abbreviations using reference beginning with an extra `*`:

<!-- prettier-ignore-start -->

```md
*[Abbr word]: Abbr content
```

<!-- prettier-ignore-end -->

::: tip Escaping

Escaping can be done by adding `\` to escape the `*` `[` or `]` marker:

```md
\*[text]: content
```

will be

\*[text]: content

:::

## Demo

<!-- prettier-ignore-start -->

::: md-demo Demo

*[HTML]: Hyper Text Markup Language
*[W3C]: World Wide Web Consortium

The HTML specificationis maintained by the W3C.

:::

<!-- prettier-ignore-end -->
5 changes: 5 additions & 0 deletions docs/src/zh/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ icon: home
home: true
heroImage: /logo.svg
features:
- title: abbr
icon: book
details: 缩写词
link: ./abbr.html

- title: alert
icon: bell
details: GFM 警示
Expand Down
87 changes: 87 additions & 0 deletions docs/src/zh/abbr.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
---
title: "@mdit/plugin-abbr"
icon: book
---

支持缩写词 `<abbr>` 标签的插件。

<!-- more -->

## Usage

::: code-tabs#language

@tab TS

```ts
import MarkdownIt from "markdown-it";
import { abbr } from "@mdit/plugin-abbr";

const mdIt = MarkdownIt().use(abbr);

mdIt.render(`
*[HTML]: Hyper Text Markup Language
*[W3C]: World Wide Web Consortium
The HTML specification is maintained by the W3C.
`);
```

@tab JS

```js
const MarkdownIt = require("markdown-it");
const { abbr } = require("@mdit/plugin-abbr");

const mdIt = MarkdownIt().use(abbr);

mdIt.render(`
*[HTML]: Hyper Text Markup Language
*[W3C]: World Wide Web Consortium
The HTML specification is maintained by the W3C.
`);
```

:::

<!-- markdownlint-disable MD028 -->

## 语法

通过此插件,你可以通过以额外 `*` 开头的链接声明来声明缩略词。

<!-- prettier-ignore-start -->

```md
*[缩略词]: 内容
```

<!-- prettier-ignore-end -->

::: tip 转移

转义可以通过添加额外的 `\` 以转义 `*` `[``]` 字符:

```md
\*[文字]: 内容
```

will be

\*[文字]: 内容

:::

## 示例

<!-- prettier-ignore-start -->

::: md-demo 示例

*[HTML]: Hyper Text Markup Language
*[W3C]: World Wide Web Consortium

The HTML specificationis maintained by the W3C.

:::

<!-- prettier-ignore-end -->
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"typescript-eslint": "7.8.0",
"vitest": "1.5.3"
},
"packageManager": "pnpm@9.0.5",
"packageManager": "pnpm@9.0.6",
"engines": {
"node": ">=18.18.0"
},
Expand Down
22 changes: 22 additions & 0 deletions packages/abbr/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
The MIT License (MIT)

Copyright (c) 2014-2015 Vitaly Puzrin, Alex Kocharin.
Copyright (C) 2024 - PRESENT by MrHope

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
16 changes: 16 additions & 0 deletions packages/abbr/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# @mdit/plugin-abbr

[![Version](https://img.shields.io/npm/v/@mdit/plugin-abbr.svg?style=flat-square&logo=npm) ![Downloads](https://img.shields.io/npm/dm/@mdit/plugin-abbr.svg?style=flat-square&logo=npm) ![Size](https://img.shields.io/bundlephobia/min/@mdit/plugin-abbr?style=flat-square&logo=npm)](https://www.npmjs.com/package/@mdit/plugin-abbr)

abbr plugin for MarkdownIt.

## Install / 安装

```bash
# pnpm
pnpm add -D @mdit/plugin-abbr
# npm
npm i -D @mdit/plugin-abbr
# yarn
yarn add -D @mdit/plugin-abbr
```

0 comments on commit 45fdfcb

Please sign in to comment.