rehype-han 0.1.1 → 0.2.0

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.
Files changed (3) hide show
  1. package/README.md +2 -2
  2. package/index.js +9 -1
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -23,7 +23,7 @@ const file = await unified()
23
23
  .process("<p>Mom's note——“中文”</p>");
24
24
 
25
25
  console.log(String(file));
26
- // => <p>Mom's note——</span><span class="cjk-punc">“</span>中文<span class="cjk-punc">”</span></p>
26
+ // => <p>Mom's note——<span class="cjk-punc">“</span>中文<span class="cjk-punc">”</span></p>
27
27
  ```
28
28
 
29
29
  ## Options
@@ -34,7 +34,7 @@ console.log(String(file));
34
34
 
35
35
  ## Behavior
36
36
 
37
- - Wrapping targets punctuation from Unicode `\p{P}` (including ASCII and full-width/CJK variants).
37
+ - Wrapping targets non-ASCII punctuation from Unicode `\p{P}` (full-width/CJK marks); ASCII punctuation is ignored.
38
38
  - Exactly two consecutive em dashes (`——`) are wrapped as one token.
39
39
  - Exactly two consecutive CJK ellipsis characters (`……`) are wrapped as one token.
40
40
  - Single `-`, `–`, and `—` are intentionally excluded and never wrapped.
package/index.js CHANGED
@@ -43,8 +43,16 @@ const ADJ_LEFT_CLASS = 'adj-l';
43
43
  const ADJ_RIGHT_CLASS = 'adj-r';
44
44
  const ADJ_MIDDLE_CLASS = 'adj-m';
45
45
 
46
+ function isHalfWidthAsciiPunctuation(ch) {
47
+ return Boolean(ch) && ch.charCodeAt(0) <= 0x7f;
48
+ }
49
+
46
50
  function isWrappablePunctuation(ch) {
47
- return PUNCTUATION_REGEX.test(ch) && !EXCLUDED_PUNCTUATION.has(ch);
51
+ return (
52
+ PUNCTUATION_REGEX.test(ch) &&
53
+ !isHalfWidthAsciiPunctuation(ch) &&
54
+ !EXCLUDED_PUNCTUATION.has(ch)
55
+ );
48
56
  }
49
57
 
50
58
  function isLatinLetter(ch) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rehype-han",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "Rehype plugin to wrap text segments with proper tags.",
5
5
  "type": "module",
6
6
  "main": "./index.js",