Skip to main content

Justify and hyphenate text in files and/or standard input

Project description

Python Text Justifier

https://img.shields.io/pypi/v/justifier.svg Documentation Status

Justify and hyphenate text in files and/or standard input. The program can be invoked as either text-justifier or justify .

Installation/Upgrade

``pip3 install -U text-justifier``

Options

-w, --width *INTEGER*

Width of text, not counting indent

-i, --indent *INTEGER*

Number of spaces to add before text

-r, --right-margin *INTEGER*

Determine the width of text to suit a specific column, i.e. right margin is indent plus width.

-c, --centre, --no-centre, --center, --no-center

Automatically determine line width based on terminal width, with indent mirrored on the right. Will probably not work with indent of 0 (the default). Uses $COLUMNS if the terminal size cannot be queried.

-s, --simple-hyphen

Use simple hyphenation method.

-h, --hyphen

Use pyphen library to hyphenate, which uses OpenOffice hyphenation dictionaries.

-H, --no-hyphenate

Turn hyphenation off.

Features

  • Can centre text according to the screen/terminal width

  • Indent text

TO DO

  • Em dashes (— or –) should be used padded before random padding is done

  • Don’t hyphenate URLs

  • Extract URLs, replace with placeholders and dump after paragraph; Use Markdown style or something similar i.e.

    • [text](url) -> [text][URL_PLACEHOLDER] and [URL_PLACEHOLDER]: url

    • [url] -> [0] and [0]: url

  • Option (-f n) to add a first-line indent to each paragraph

  • Option (-n) to split paragraphs on newline instead of blank lines

  • Treat lines that begin with a list character as their own paragraph

Algorithm

  1. Grab a line’s worth of text plus the word that would push it over the limit

  2. Count the number of characters in the “safe” line

  3. The delta equals the difference between the line length and (limit subtract the number of full stops except one at the end of a line)

  4. Determine the hyphenation threshold n = limit / 20, i.e. one extra space per 20 characters

  5. If the overflow word is at least n*2 characters long, attempt to hyphenate it

  6. Find the largest usable fragment of the overflow word no longer than delta - 1

  7. Add the fragment if hyphenating and change delta to (delta subtract (fragment length + 1))

  8. Add a space after at most (limit subtract line length) full stops (determined randomly)

  9. Add a space before and after at most delta/2 em dashes and recalculate delta

  10. Add a space after delta random spaces

  11. If hyphenating and the next line’s delta would be greater than this one’s without hyphenation, don’t hyphenate

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

History

0.9.0 (2022-12-17)

  • First release on PyPI.

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

text-justifier-0.10.0.tar.gz (21.3 kB view details)

Uploaded Source

Built Distribution

text_justifier-0.10.0-py2.py3-none-any.whl (11.3 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file text-justifier-0.10.0.tar.gz.

File metadata

  • Download URL: text-justifier-0.10.0.tar.gz
  • Upload date:
  • Size: 21.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.2

File hashes

Hashes for text-justifier-0.10.0.tar.gz
Algorithm Hash digest
SHA256 6ea908cbdea1843d1d11aa48bb3cc763d2530b7df7703557cd0f639d901262a1
MD5 fc0e788b925fd208c1525ddab26029cd
BLAKE2b-256 4c25a2d0b306af5f7ca08d305517319095b7dea636c552ef9c042561c8ec05ec

See more details on using hashes here.

File details

Details for the file text_justifier-0.10.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for text_justifier-0.10.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 75ff3ece90118b75c1da98fa4368b857fac381b699c7ccff16c201f96b6e9972
MD5 9e24d862a2025272a2e4ae656c5c3409
BLAKE2b-256 54398ae3d687c12279ec53d8e0728081a09fbb6a521185b6456882d887821d97

See more details on using hashes here.

Supported by

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