Repository: zh-lx/pinyin-pro (ts)

Issue:
支持叠字符号「々」的注音
## 功能描述

这是一个特殊功能，建议增加一个选项，默认关闭。

々的读音就是读被反复的字的读音，例如，天々(tiān)向上，这里读前面一个字的音。


- https://baike.baidu.com/item/%E3%80%85/9045440
- https://zh.wikipedia.org/wiki/%E5%8F%A0%E5%AD%97%E7%AC%A6%E5%8F%B7


Pull request description:
Feature support reduplication
close #201

Patch:
diff --git a/lib/data/special.ts b/lib/data/special.ts
index d9892e9..d3ec2c9 100644
--- a/lib/data/special.ts
+++ b/lib/data/special.ts
@@ -230,8 +230,20 @@ export function processToneSandhiLiao(cur: string, pre: string) {
   }
 }
 
+// 处理叠字符[々]
+function processReduplicationChar(cur: string, pre: string) {
+  if (cur === '々') {
+    if (!pre || !DICT1.get(pre)) {
+      return 'tóng';
+    } else {
+      return DICT1.get(pre).split(' ')[0];
+    }
+  }
+}
+
 export function processSepecialPinyin(cur: string, pre: string, next: string) {
   return (
+    processReduplicationChar(cur, pre) ||
     processToneSandhiLiao(cur, pre) ||
     processToneSandhi(cur, pre, next) ||
     getSingleWordPinyin(cur)


Test patch:
diff --git a/test/special.test.js b/test/special.test.js
index 2eb767e..351ef5e 100644
--- a/test/special.test.js
+++ b/test/special.test.js
@@ -291,4 +291,15 @@ describe('[special tone sandhi]绕口令', () => {
     const result = pinyin('了吧');
     expect(result).to.be.equal('liǎo ba');
   });
+
+  it('[special 々]々', () => {
+    const result = pinyin('天々向上，好々学习');
+    expect(result).to.be.equal('tiān tiān xiàng shàng ， hǎo hǎo xué xí');
+
+    const result1 = pinyin('々々');
+    expect(result1).to.be.equal('tóng tóng');
+
+    const result2 = pinyin('々，々');
+    expect(result2).to.be.equal('tóng ， tóng');
+  });
 });