Skip to main content

This filter changes a given text to Title Caps, and attempts to be clever about SMALL words like a/an/the in the input. The list of "SMALL words" which are not capped comes from the New York Times Manual of Style, plus some others like 'vs' and 'v'.

The filter employs some heuristics to guess abbreviations that don't need conversion.

Example ... 'this is a text' is converted to 'This Is The Text'.

More examples and expected behavior for corner cases are available in the package test suite.

Issues, updates, pull requests, etc should be directed to github.

Installation

The easiest method is to simply use pip:

(sudo) pip install headline_style

Usage

headline_style provides only one function, simply:

>>> from headLineStyle import headLineStyle
>>> headLineStyle('a thing')
'A Thing'

A callback function may also be supplied, which will be called for every word:

>>> def abbreviations(word, **kwargs):
...   if word.upper() in ('TCP', 'UDP'):
...     return word.upper()
...
>>> headLineStyle.headLineStyle('a simple tcp and udp wrapper', callback=abbreviations)
'A Simple TCP and UDP Wrapper'

The callback function is supplied with an all_caps keyword argument, indicating whether the entire line of text was entirely capitalized. Returning None from the callback function will allow headLineStyle to process the word as normal.

Command Line Usage

headLineStyle also provides a command line utility headLineStyle:

>>>  $ headLineStyle make me a title
... Make Me a Title
... $ echo "Can pipe and/or whatever else" | headLineStyle
... Can Pipe and/or Whatever Else
... # Or read/write files:
... $ headLineStyle -f infile -o outfile

In addition, commonly used acronyms can be kept in a local file at ~/.headLineStyle.txt. This file contains one acronym per line. The acronym will be maintained in the title as it is provided. Once there is e.g. one line saying TCP, then it will be automatically used when used from the command line.

>>> $ headLineStyle I LOVE TCP
>>> I Love TCP

Limitations

This is a best-effort library that uses regexes to try to do intelligent things, but will have limitations. For example, it does not have the contextual awareness to distinguish acronyms from words: us (we) versus US (United States).

The regexes and titlecasing rules were written for American English. While there is basic support for Unicode characters, such that something like "El Niño" will work, it is likely that accents or non-English phrases will not be handled correctly.

If anyone has concrete solutions to improve these or other shortcomings of the library, pull requests are very welcome!

License


Copyright [2022] [Vinod Baste]

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Release files for headline-style 1.5.7

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

Source distribution (sdist)

Source distribution for headline-style 1.5.7
File Size Uploaded
headline_style-1.5.7.tar.gz 18.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for headline-style 1.5.7
File Interpreter ABI Platform
headline_style-1.5.7-py3-none-any.whl Python 3 none any Details

Total release size: 29.6 kB

Release files / headline_style-1.5.7.tar.gz

Download URL headline_style-1.5.7.tar.gz
Size 18.1 kB
Tags Source
SHA-256 checksum
How to use checksums
e5dd292315204ac7570503455f2cae0df93f12916a7551fbfe8a567b95e3a5ab
BLAKE2b-256 checksum
How to use checksums
3c5c2576c3b4f7836e2946d3854c3a5870320be5caee5942e01fb3c9b5836fab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.13

Release files / headline_style-1.5.7-py3-none-any.whl

Download URL headline_style-1.5.7-py3-none-any.whl
Size 11.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b956323b1c6cb6e294988c1aaeb468861a4a9e5075d71f07e3fef567143fca29
BLAKE2b-256 checksum
How to use checksums
a05dbe160839d4910039880e4e025c3dd57f62c8b2375b38e85dbaf9e8699e9e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.13

Release history Release notifications | RSS feed

This release

1.5.7 This release

2 release files

1.5.5

2 release files

1.5.1

2 release files

1.5.0

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

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