https://github.com/c-bata/django-wcwidth-filter
A collection of Django template filters for multi-width characters.
https://github.com/c-bata/django-wcwidth-filter
Last synced: 11 months ago
JSON representation
A collection of Django template filters for multi-width characters.
- Host: GitHub
- URL: https://github.com/c-bata/django-wcwidth-filter
- Owner: c-bata
- License: mit
- Created: 2020-05-10T16:14:59.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2021-07-08T12:56:34.000Z (almost 5 years ago)
- Last Synced: 2025-02-10T01:46:16.974Z (over 1 year ago)
- Language: Python
- Homepage:
- Size: 9.77 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
=====================
django-wcwidth-filter
=====================
A collection of Django template filters for multi-width characters.
Installation
------------
.. code-block:: console
$ python3 -m pip install django-wcwidth-filter
Usage
-----
wcswidth filter
~~~~~~~~~~~~~~~
.. code-block:: python
>>> template = Template("{% load wcwidth %}{{ x | wcswidth }}")
>>> context = Context({
>>> "x": "Hello",
>>> })
>>> template.render(context)
5
>>> context = Context({
>>> "x": "こんにちは",
>>> })
>>> template.render(context)
10
truncate_wcswidth filter
~~~~~~~~~~~~~~~~~~~~~~~~
.. code-block:: python
>>> template = Template("{% load wcwidth %}{{ x | truncate_wcswidth:4 }}")
>>> context = Context({
>>> "x": "Hello",
>>> })
>>> template.render(context)
"Hel…"
>>> template = Template("{% load wcwidth %}{{ x | truncate_wcswidth:9 }}")
>>> context = Context({
>>> "x": "こんにちは",
>>> })
>>> template.render(context)
'こんにち…'