|
1 | 1 | # pinyinify |
2 | | -A simple JavaScript function for converting pinyin containing tone numbers (`pin4yin1`) to pinyin using standard Unicode tone marks (<code>pìnyīn</code>). |
| 2 | +A simple JavaScript function for converting pinyin containing tone numbers (`pin4yin1`) to pinyin using standard Unicode tone marks (<code>pìnyīn</code>). A list of Unicode tone marks for HTML can be found [here](http://pinyin.info/unicode/unicode_test.html). |
3 | 3 |
|
4 | 4 | ## Usage |
5 | 5 | The function `pinyinify()` takes a string parameter, which can be one of the following: |
6 | 6 |
|
7 | 7 | + A single character, which must be one of: `a`, `e`, `i`, `o`, `u`, or <code>ü</code>, followed by a tone mark. `v` is an acceptable substitute for <code>ü</code>. |
8 | 8 | + A pinyin word or phrase using tone numbers. Examples: `mao1`, `chi1fan4`, `wo3 men5`. For simplicity's sake, the function will process most words with tone numbers, including ones that may not be valid pinyin. |
9 | | -+ A string containing both pinyin words and non-pinyin words, characters, or symbols. Example: `My Chinese name is yang2kai3wen2.` **Be careful:** any word that resembles the structure of pinyin (has a number at the end of it, for example) may be given tone marks. Therefore, it is recommended that you avoid this option if possible. |
| 9 | ++ A string containing both pinyin words and non-pinyin words, characters, or symbols. Pinyin must be separated from non-pinyin words by whitespace, but pinyin can have symbols/punctuation adjacent to it. Example: `My Chinese name is yang2kai3wen2.` **Be careful:** any word that resembles the structure of pinyin (has a number at the end of it, for example) may be given tone marks. Therefore, it is recommended that you avoid this option if possible. |
10 | 10 |
|
11 | 11 | If you pass a string that meets one of the requirements above, the function will return a string with the tone numbers converted to tone marks. Otherwise, it will return an unchanged string. |
12 | 12 |
|
13 | 13 | ## Limitations |
14 | | -<!-- TODO lowercase only, incomplete validation, etc.--> |
| 14 | +These are some current limitations, which may be addressed in the future should the need arise. |
| 15 | + |
| 16 | ++ **Lowercase Pinyin Only:** since some typefaces have trouble displaying uppercase pinyin symbols, any pinyin words will be converted to lowercase. Non-pinyin words are not affected. |
| 17 | ++ **Incomplete Validation:** Right now, `pinyinify()` does not ensure that words are valid pinyin words before conversion. It performs several checks to eliminate obviously incorrect cases: |
| 18 | + - Words that are longer than 6 characters (without the tone number) are ignored, since no pinyin words are longer than that. |
| 19 | + - There must be a tone number from 1-5 at the end. |
| 20 | + - There must be at least one pinyin vowel in the word. The placement of tone marks is correct for any valid pinyin word. |
| 21 | + |
| 22 | +## Test Page |
| 23 | +An HTML test page allows you to test the function without writing any of your code. Simply open `test.html`, located in the `test/` directory, in your browser, and type some text into the text box to see the result. |
| 24 | + |
| 25 | +## Bugs |
| 26 | +Feel free to report bugs on the issue tracker. I will do my best to get around to them in a timely manner. If you want to contribute improvements to the code, let me know by [sending me an email ](mailto:[email protected]) or opening an issue. |
0 commit comments