Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

支持叠字符号「々」的注音 #201

Open
yisibl opened this issue Mar 21, 2024 · 2 comments
Open

支持叠字符号「々」的注音 #201

yisibl opened this issue Mar 21, 2024 · 2 comments

Comments

@yisibl
Copy link
Collaborator

yisibl commented Mar 21, 2024

功能描述

这是一个特殊功能,建议增加一个选项,默认关闭。

々的读音就是读被反复的字的读音,例如,天々(tiān)向上,这里读前面一个字的音。

@warm-ice0x00
Copy link

“自己动手,丰衣足食。”

var resolveIterationMark = function(string) {
  var current = string.charAt(0);
  var result = current;
  for (var i = 1; i < string.length; ++i) {
    if (string.charAt(i) !== '々') {
      current = string.charAt(i);
    }
    result += current;
  }
  return result;
};

@koaqiu
Copy link

koaqiu commented Apr 16, 2024

“自己动手,丰衣足食。”

var resolveIterationMark = function(string) {
  var current = string.charAt(0);
  var result = current;
  for (var i = 1; i < string.length; ++i) {
    if (string.charAt(i) !== '々') {
      current = string.charAt(i);
    }
    result += current;
  }
  return result;
};
const resolveIterationMark = (str) => typeof str  === 'string'  
  ? str.split('々').reduce((s,c, i, a)=> a.length===1?s:`${s}${s.slice(-1)}${c}`) 
  : str;

在线测试

import { html } from 'pinyin-pro';
const resolveIterationMark = (str:string) => typeof str  === 'string' && !/^々{1,}$/ig.test(str) 
  ? str.split('々').reduce((s,c, _, a)=> a.length===1?s:`${s}${s.slice(-1)}${c}`) 
  : str;
const htmlString = [
    html(resolveIterationMark('天々向上')),
    html(resolveIterationMark('天々向上,好々学习')),
    html(resolveIterationMark('々')),
    html(resolveIterationMark('々々')),
    html(resolveIterationMark('')),
    html(resolveIterationMark('々天々')),//开头的“々”会被抛弃
    html(resolveIterationMark('施氏食狮史')),
    html(resolveIterationMark('牛逼々々')),
].map(html => html?`<div>${html}</div>`:'<div>&lt;空行&gt;</div>').join('');

document.body.innerHTML = htmlString;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants