@celhive/tool.js 0.0.10 → 0.0.11

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.
@@ -1,6 +1,17 @@
1
+ /**
2
+ * markdownPatch 配置选项
3
+ */
4
+ export interface MarkdownPatchConfig {
5
+ /**
6
+ * 是否删除所有 emoji 表情符号
7
+ * @default false
8
+ */
9
+ removeEmoji?: boolean;
10
+ }
1
11
  /**
2
12
  * 修复 markdown 格式缺失问题
3
13
  * @param md - 需要修复的 markdown 字符串
14
+ * @param config - 可选配置项
4
15
  * @returns string 修复后的 markdown 字符串
5
16
  */
6
- export declare const markdownPatch: (input: string) => string;
17
+ export declare const markdownPatch: (md: string, config?: MarkdownPatchConfig) => string;
@@ -1,12 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.markdownPatch = void 0;
4
- /**
5
- * 组合多个函数,从左到右依次执行,类似 lodash 的 flow
6
- */
7
- const flow = (...fns) => {
8
- return (input) => fns.reduce((acc, fn) => fn(acc), input);
9
- };
10
4
  /**
11
5
  * 在标题 # 和内容之间添加空格(跳过代码块)
12
6
  */
@@ -74,10 +68,48 @@ const addNewlineBeforeVideoTags = (md) => {
74
68
  result = result.replace(/([^\n])\n(<video\b[^>]*>)/g, '$1\n\n$2');
75
69
  return result;
76
70
  };
71
+ /**
72
+ * 删除所有 emoji 表情符号
73
+ */
74
+ const removeEmojis = (md) => {
75
+ // 匹配所有 emoji 字符,包括:
76
+ // - 基础 emoji 字符 (\u{1F300}-\u{1F9FF})
77
+ // - 补充符号和象形文字 (\u{1FA00}-\u{1FAFF})
78
+ // - 传统 emoji 符号 (\u{2600}-\u{26FF}, \u{2700}-\u{27BF})
79
+ // - 杂项符号 (\u{2300}-\u{23FF})
80
+ // - 装饰符号 (\u{FE00}-\u{FE0F})
81
+ // - 组合字符和肤色修饰符 (\u{1F3FB}-\u{1F3FF})
82
+ // - 其他常见 emoji 范围
83
+ const emojiRegex = /[\u{1F300}-\u{1F9FF}\u{1FA00}-\u{1FAFF}\u{2600}-\u{26FF}\u{2700}-\u{27BF}\u{2300}-\u{23FF}\u{FE00}-\u{FE0F}\u{1F1E0}-\u{1F1FF}\u{1F900}-\u{1F9FF}\u{1F600}-\u{1F64F}\u{1F680}-\u{1F6FF}\u{2190}-\u{21FF}\u{2B50}\u{231A}-\u{231B}\u{23E9}-\u{23FA}\u{25AA}-\u{25FE}\u{2934}-\u{2935}\u{2B05}-\u{2B07}\u{3030}\u{303D}\u{3297}\u{3299}\u{1F004}\u{1F0CF}\u{1F170}-\u{1F171}\u{1F17E}-\u{1F17F}\u{1F18E}\u{1F191}-\u{1F19A}\u{1F201}-\u{1F202}\u{1F21A}\u{1F22F}\u{1F232}-\u{1F23A}\u{1F250}-\u{1F251}\u{1F3FB}-\u{1F3FF}][\u{FE00}-\u{FE0F}]?/gu;
84
+ // 删除 emoji 并清理多余的连续空格
85
+ return md.replace(emojiRegex, '').replace(/ {2,}/g, ' ');
86
+ };
77
87
  /**
78
88
  * 修复 markdown 格式缺失问题
79
89
  * @param md - 需要修复的 markdown 字符串
90
+ * @param config - 可选配置项
80
91
  * @returns string 修复后的 markdown 字符串
81
92
  */
82
- exports.markdownPatch = flow(fixHeadingSpaces, trimWhitespace, convertBoldToHtml, fixMermaidSpacing, addNewlineBeforeHeadings, addNewlineBeforeVideoTags, fixHeadingSpaces // 再次修复标题空格,处理新插入的换行符后的标题
83
- );
93
+ const markdownPatch = (md, config) => {
94
+ const { removeEmoji = false } = config || {};
95
+ // 构建处理函数数组
96
+ const processors = [
97
+ fixHeadingSpaces,
98
+ trimWhitespace,
99
+ convertBoldToHtml,
100
+ fixMermaidSpacing,
101
+ addNewlineBeforeHeadings,
102
+ addNewlineBeforeVideoTags,
103
+ // 再次修复标题空格,处理新插入的换行符后的标题
104
+ fixHeadingSpaces,
105
+ ];
106
+ // 如果需要删除 emoji,添加到处理流程中
107
+ if (removeEmoji) {
108
+ processors.push(removeEmojis);
109
+ // 删除 emoji 后再次 trim,清理可能留下的首尾空格
110
+ processors.push(trimWhitespace);
111
+ }
112
+ // 依次执行所有处理函数
113
+ return processors.reduce((result, fn) => fn(result), md);
114
+ };
115
+ exports.markdownPatch = markdownPatch;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@celhive/tool.js",
3
- "version": "0.0.10",
3
+ "version": "0.0.11",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"