Skip to main content
# Pinyin and Python and Markdown, together!

Type Chinese pinyin with tone numbers, and have them automagically converted to beautiful accented pinyin.

[![travis](https://travis-ci.org/bcaller/pinyin_markdown.svg)](https://travis-ci.org/bcaller/pinyin_markdown)
[![PyPI version](https://badge.fury.io/py/pinyin_markdown.svg)](https://badge.fury.io/py/pinyin_markdown)

A Markdown extension that looks through your text for things like `yi1dian3r`, `Xi3an4` and `lu:5` and replaces
them with accented pinyin. The pinyin syllables are marked up with span tags with classes denoting
the tone.

Add `'pinyin_markdown'` to your Markdown call and watch the magic unfold:

```python
>>> from markdown import Markdown

>>> markdown = Markdown(extensions=['pinyin_markdown']
>>> markdown.convert('i ♥ Xi3an4!')
<p>i ♥ <span class="tone3">Xǐ</span><span class="pyap">'</span><span class="tone4">àn</span></p>

>>> markdown = Markdown(extensions=['pinyin_markdown(tone_class=, apostrophe_class=apo)']
>>> markdown.convert('i ♥ Xi3an4!')
<p>i ♥ <span>Xǐ</span><span class="apo">'</span><span>àn</span></p>
```

The three examples above are rendered as: yīdiǎnr, Xǐ'àn and lü, with HTML:

```html
<span class="tone1">yī</span><span class="tone3">diǎn</span><span class="erhua">r</span>
<span class="tone3">Xǐ</span><span class="pyap">'</span><span class="tone4">àn</span>
<span class="tone5">lü</span>
```

## Options
| Option | Type | Default |Description |
|-----------|------|---------|------------|
| tone_class | str | 'tone{}' | HTML class name for tones, which will be formatted with tone_class.format(tone) where tone is a number 1-5|
| apostrophe_class | str | 'pyap' | HTML class name for apostrophes needed between vowels |
| erhua_class | str | 'erhua' | HTML class name for the erhua 'r' e.g. in dianr |
| entities | bool | False | If True, output the accented characters as entity codes `&466#;` |


## Installation
>From Github:

```
git clone https://github.com/bcaller/pinyin_markdown.git
pip install -e ./pinyin_markdown
```

>From Pypi:

```
pip install pinyin_markdown
```

Also have a look at [tsroten's zhon](https://github.com/tsroten/zhon) for more Python pinyin goodness.


Metadata

Release files for pinyin_markdown 0.8.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pinyin_markdown 0.8.2
File Size Uploaded Provenance Actions
pinyin_markdown-0.8.2.tar.gz 30.1 kB Without provenance Details for pinyin_markdown-0.8.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pinyin_markdown 0.8.2
File Interpreter ABI Platform Actions
pinyin_markdown-0.8.2-py3-none-any.whl Python 3 none any Details for pinyin_markdown-0.8.2-py3-none-any.whl

Total release size: 39.2 kB

Release files / pinyin_markdown-0.8.2.tar.gz

Download URL pinyin_markdown-0.8.2.tar.gz
Size 30.1 kB
Tags Source
SHA-256 checksum
How to use checksums
0d07a9ccdfcf9b359d9dd1470c2f0e8c9b429a2a0fc4f663c1edbcc06aa97a9b
BLAKE2b-256 checksum
How to use checksums
0e2ecd8110d3cb14f7d04bd1600d321960884de20a703dd4d5b55e966617008e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / pinyin_markdown-0.8.2-py3-none-any.whl

Download URL pinyin_markdown-0.8.2-py3-none-any.whl
Size 9.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0dc5f04a185fda984e3db8008c993360a7eed86af7de06c4a22c5bdf2663a283
BLAKE2b-256 checksum
How to use checksums
05d0b455ec8a16e11bc97056adbff8e7656c1782d49292824a8c31d7152a9714
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for pinyin_markdown 0.8.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.8.2 This release

2 release files No provenance

0.8

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page