Skip to main content

A context-dependent text wrapper.

Project description

Summary

Text Cut is meant to wrap text naturally, preferring to cut the sentence where this is the least disturbing for the reader.

Install

python -m pip install textcut

Usage

from textcut import TextCut
print(TextCut().fill(my_text))

Methods

The textcut package offers two main methods: wrap cuts a long text into multiple lines, and fill does the same but join the resulting list with new line character for easy printing.

Options

Several options are available to configure the wrapping:

  • language: for now only fr (French), the rules to wrap text depends on the language. Although fr works quite well with English too.
  • width: the maximum width of the lines
  • tolerance: whether it's ok to have shorter lines that other (high tolerance >0.5) or not (low tolerance, <0.1)
  • trim: whether to trim the lines to remove extra spaces
  • len_func: a function to determine the length of a string, defaults to len
  • normalise: tries to minimise the length differences between lines (not optimised)

Example

TextCut(language = 'fr', width = 80, tolerance = 0.4, trim = True, len_func = len).fill(text)

Output:

If I were asked to answer the following question: What is slavery?
and I should answer in one word, It is murder!,
my meaning would be understood at once.
No extended argument would be required to show that the power to remove a man's
mind, will, and personality, is the power of life and death,
and that it makes a man a slave. It is murder. Why, then,
to this other question: What is property? may I not likewise answer,
It is robbery!, without the certainty of being misunderstood;
the second proposition being no other than a transformation of the first?

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

textcut-0.0.4.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

textcut-0.0.4-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file textcut-0.0.4.tar.gz.

File metadata

  • Download URL: textcut-0.0.4.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for textcut-0.0.4.tar.gz
Algorithm Hash digest
SHA256 156bbcbd4677515b37bb307e082673e421cd4661ecc15999c6a220d9fca1a403
MD5 e9ef68e8ccf0dfb793f669a4f5996c81
BLAKE2b-256 95a41dd88b676b92072b1bf9046b77976661b20b05da01987dbaa92a27c8b5ee

See more details on using hashes here.

File details

Details for the file textcut-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: textcut-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for textcut-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 ebd3faf59dd508dbcc81cfbebf5cdcc3b18f8dbe2e3377bfa3137134d93d0ac8
MD5 d902bbd2aa452faa637745e6361fc9a7
BLAKE2b-256 d345443701c634f8a374691065914ec489ae19bbcd980e95050dd8dc14eeb840

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page