lib.text

Text related utilities for Django Docutils.

django_docutils.lib.text.is_uncapitalized_word(value)
function[source]
function[source]
django_docutils.lib.text.is_uncapitalized_word(value)

Return True if term/word segment is special uncap term (e.g. “django-“).

Parameters:

value (str) – string value from template

Returns:

True if term or word is uncapitalized.

Return type:

bool

Functions can be declared via DJANGO_DOCUTILS_LIB_TEXT in Django settings via string imports. The filters accept one argument (the word). If you don’t want the word or pattern capitalized, return True. Anything else capitalizes as normal.

How to create filters:

def handle_uncapped_word(value: str) -> bool:
    if value.startswith('django-'):
        return True
    if 'vs' in value:
        return True
    return False

In your settings:

DJANGO_DOCUTILS_LIB_TEXT = {
    'uncapitalized_word_filters': [
        'project.path.to.handle_uncapped_word'
    ]
}
django_docutils.lib.text.smart_capfirst(value)
function[source]
function[source]
django_docutils.lib.text.smart_capfirst(value)

Capitalize the first character of the value.

Parameters:

value (str)

Return type:

str

django_docutils.lib.text.smart_title(value)
function[source]
function[source]
django_docutils.lib.text.smart_title(value)

Convert a string into titlecase, except for special cases.

Django can still be capitalized, but it must already be like that.

Parameters:

value (str)

Return type:

str