Skip to content

Strings

Utils for strings.

Handsdown API Index / Handsdown / Utils / Strings

Auto-generated documentation for handsdown.utils.strings module.

extract_md_title

Show source in strings.py:48

Extract title from the first line of content.

If title is present - return a title and a remnaing content. if not - return an empty title and untouched content.

Examples

extract_md_title('# Title\ncontent')
('Title', 'content')

extract_md_title('no title\ncontent')
('', 'no title\ncontent')

Returns

A tuple fo title and remaining content.

Signature

def extract_md_title(content: str) -> Tuple[str, str]:
    ...

make_title

Show source in strings.py:7

Convert pathlib.Path part or any other string to a human-readable title.

Replace underscores with spaces and capitalize result.

Examples

make_title(Path("my_module/my_path.py").stem)
"My Path"

make_title("my_title")
"My Title"

make_title("__init__.py")
"Init Py"

make_title(Path("my_module/__main__.py").stem)
"Module"

Arguments

  • file_stem - Stem from path.

Returns

A human-readable title as a string.

Signature

def make_title(file_stem: str) -> str:
    ...