1 3
import re
2 3
import unicodedata
3

4

5 3
def indent(string, places=4, linebreak="\n", singles=False):
6 3
    lines = string.split(linebreak)
7 3
    if not singles and len(lines) == 1:
8 3
        return string
9 3
    for i, line in enumerate(lines):
10 3
        lines[i] = " " * places + line
11 3
    result = linebreak.join(lines)
12 3
    if not singles:
13 3
        result = linebreak + result
14 3
    return result
15

16

17 3
def slugify(value):
18
    """
19
    Converts to lowercase, removes non-word characters (alphanumerics and
20
    underscores) and converts spaces to hyphens. Also strips leading and
21
    trailing whitespace.
22

23
    This function is based on Django's slugify implementation.
24
    """
25 0
    value = unicodedata.normalize("NFKD", value)
26 0
    value = value.encode("ascii", "ignore").decode("ascii")
27 0
    value = re.sub(r"[^\w\s-]", "", value).strip().lower()
28 0
    return re.sub(r"[-\s]+", "-", value)

Read our documentation on viewing source code .

Loading