@kawapress/plugin-emoji 0.0.0-stage → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) KawaPress contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,49 @@
1
+ # @kawapress/plugin-emoji
2
+
3
+ 为 KawaPress 提供 `:tada:` 等 Emoji 短代码支持。
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@kawapress/plugin-emoji?label=npm&color=42b883)](https://www.npmjs.com/package/@kawapress/plugin-emoji) · [English](https://github.com/kawapress/kawapress/blob/main/packages/plugin-emoji/README.md)
6
+
7
+ `@kawapress/plugin-emoji` 是 [KawaPress](https://github.com/kawapress/kawapress) 的一部分。KawaPress 是一个以 Vue 为核心的静态站点生成器。
8
+
9
+ ## 特性
10
+
11
+ - 按 GitHub 名称表把 `:name:` 短代码渲染成 Emoji。
12
+ - 未知名称、行内代码与代码围栏中的短代码保持原样。
13
+ - `:)` 等字符表情不作转换,避免把技术文档里的标点误改成表情。
14
+ - 标题纯文本、大纲和锚点仍保留源码里的 `:name:` 短代码。
15
+
16
+ ## 安装
17
+
18
+ 这个包已经包含在 `kawapress` 里。使用 `kawapress/nagi` 的站点自带它,不需要再安装。
19
+
20
+ 只有不使用 nagi 预设搭建站点时,才需要单独安装它。
21
+
22
+ ```sh
23
+ npm install --save-dev @kawapress/plugin-emoji
24
+ ```
25
+
26
+ 也可以用 `pnpm add --save-dev @kawapress/plugin-emoji` 或 `yarn add --dev @kawapress/plugin-emoji`。
27
+
28
+ ## 使用
29
+
30
+ ```md
31
+ 发布完成 :tada:
32
+ ```
33
+
34
+ ```ts
35
+ import emojiPlugin from '@kawapress/plugin-emoji'
36
+ import { defineConfig } from 'kawapress'
37
+
38
+ export default defineConfig({
39
+ plugins: [emojiPlugin()],
40
+ })
41
+ ```
42
+
43
+ ## 文档
44
+
45
+ [文档](https://kawapress.dev/guide/markdown-extensions#emoji) · [反馈问题](https://github.com/kawapress/kawapress/issues)
46
+
47
+ ## 许可证
48
+
49
+ [MIT](https://github.com/kawapress/kawapress/blob/main/LICENSE) © KawaPress contributors
package/README.md CHANGED
@@ -1,3 +1,49 @@
1
- # Temporary Holding Version
1
+ # @kawapress/plugin-emoji
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Emoji shortcodes such as `:tada:` for KawaPress.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@kawapress/plugin-emoji?label=npm&color=42b883)](https://www.npmjs.com/package/@kawapress/plugin-emoji) · [简体中文](https://github.com/kawapress/kawapress/blob/main/packages/plugin-emoji/README-zh-CN.md)
6
+
7
+ `@kawapress/plugin-emoji` is part of [KawaPress](https://github.com/kawapress/kawapress), a Vue-first static site generator.
8
+
9
+ ## Features
10
+
11
+ - Replaces `:name:` shortcodes with emoji using GitHub's shortcode list.
12
+ - Leaves unknown names, inline code, and fenced code blocks untouched.
13
+ - Keeps ASCII emoticons such as `:)` as plain text so punctuation is never turned into emoji.
14
+ - Heading titles, outlines, and anchors keep the written `:name:` shortcode.
15
+
16
+ ## Install
17
+
18
+ This package is already included in `kawapress`. A site that uses `kawapress/nagi` has it, so there is nothing to install.
19
+
20
+ Install it yourself only when you build a site without the nagi preset.
21
+
22
+ ```sh
23
+ npm install --save-dev @kawapress/plugin-emoji
24
+ ```
25
+
26
+ `pnpm add --save-dev @kawapress/plugin-emoji` and `yarn add --dev @kawapress/plugin-emoji` work too.
27
+
28
+ ## Usage
29
+
30
+ ```md
31
+ Release complete :tada:
32
+ ```
33
+
34
+ ```ts
35
+ import emojiPlugin from '@kawapress/plugin-emoji'
36
+ import { defineConfig } from 'kawapress'
37
+
38
+ export default defineConfig({
39
+ plugins: [emojiPlugin()],
40
+ })
41
+ ```
42
+
43
+ ## Documentation
44
+
45
+ [Documentation](https://kawapress.dev/en/guide/markdown-extensions#emoji) · [Report a problem](https://github.com/kawapress/kawapress/issues)
46
+
47
+ ## License
48
+
49
+ [MIT](https://github.com/kawapress/kawapress/blob/main/LICENSE) © KawaPress contributors
package/package.json CHANGED
@@ -1,6 +1,44 @@
1
1
  {
2
2
  "name": "@kawapress/plugin-emoji",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "type": "module",
4
+ "version": "0.0.1",
5
+ "description": "Emoji shortcodes such as :tada: for KawaPress",
6
+ "license": "MIT",
7
+ "homepage": "https://kawapress.dev/",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/kawapress/kawapress.git",
11
+ "directory": "packages/plugin-emoji"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/kawapress/kawapress/issues"
15
+ },
16
+ "exports": {
17
+ ".": {
18
+ "types": "./src/index.ts",
19
+ "import": "./src/index.ts",
20
+ "default": "./src/index.ts"
21
+ },
22
+ "./package.json": "./package.json"
23
+ },
24
+ "files": [
25
+ "README-zh-CN.md",
26
+ "src/**/!(*.test.*)"
27
+ ],
28
+ "engines": {
29
+ "node": ">=22.12.0"
30
+ },
31
+ "publishConfig": {
32
+ "access": "public",
33
+ "registry": "https://registry.npmjs.org/"
34
+ },
35
+ "peerDependencies": {
36
+ "kawapress": "^0.0.1"
37
+ },
38
+ "dependencies": {
39
+ "markdown-it-emoji": "^3.1.0"
40
+ },
41
+ "devDependencies": {
42
+ "markdown-exit": "^1.3.0"
43
+ }
6
44
  }
package/src/emoji.ts ADDED
@@ -0,0 +1,43 @@
1
+ import type { MarkdownExit, RenderRule, Token } from 'markdown-exit'
2
+ import { useMarkdownItPlugin } from 'kawapress'
3
+ import { full as emojiPlugin } from 'markdown-it-emoji'
4
+
5
+ interface EmojiTokenMeta {
6
+ emoji: string
7
+ }
8
+
9
+ const renderEmoji: RenderRule = (tokens, index) => (
10
+ (tokens[index].meta as EmojiTokenMeta).emoji
11
+ )
12
+
13
+ /**
14
+ * Replaces `:name:` shortcodes, such as `:tada:`, with their emoji, using the
15
+ * GitHub names of `markdown-it-emoji` like VitePress does. Emoticons such as
16
+ * `:)` stay text: in technical writing they are more often punctuation than a
17
+ * request for an emoji.
18
+ *
19
+ * The emoji token keeps the shortcode it was written with, as a `:` markup
20
+ * around the name, so the plain-text title of a heading keeps `:tada:` exactly
21
+ * like a page reader that never loads this plugin.
22
+ */
23
+ export function installEmoji(markdown: MarkdownExit): void {
24
+ useMarkdownItPlugin(markdown, emojiPlugin, { shortcuts: {} })
25
+
26
+ markdown.core.ruler.after('emoji', 'kawapress:emoji-source', (state) => {
27
+ for (const block of state.tokens) {
28
+ for (const token of block.children ?? []) {
29
+ if (token.type === 'emoji') {
30
+ keepShortcode(token)
31
+ }
32
+ }
33
+ }
34
+ })
35
+ markdown.renderer.rules.emoji = renderEmoji
36
+ }
37
+
38
+ function keepShortcode(token: Token): void {
39
+ const meta: EmojiTokenMeta = { emoji: token.content }
40
+ token.meta = { ...token.meta, ...meta }
41
+ token.content = token.markup
42
+ token.markup = ':'
43
+ }
package/src/index.ts ADDED
@@ -0,0 +1,19 @@
1
+ import type { KawaPressPlugin } from 'kawapress'
2
+ import { definePlugin } from 'kawapress'
3
+ import { installEmoji } from './emoji'
4
+
5
+ /** Emoji shortcodes such as `:tada:`, the same syntax as VitePress. */
6
+ export function emojiPlugin(): KawaPressPlugin {
7
+ return definePlugin({
8
+ name: '@kawapress/plugin-emoji',
9
+ setup(api) {
10
+ api.markdown((markdown) => {
11
+ installEmoji(markdown)
12
+ })
13
+ },
14
+ })
15
+ }
16
+
17
+ export default emojiPlugin
18
+
19
+ export { installEmoji } from './emoji'