Skip to content

_writer

Markdown Machine.

Attributes⚓︎

HandlerLookupT module-attribute ⚓︎

HandlerLookupT = Dict[str, Callable[[str, Path], List[str]]]

Handler Lookup.

Functions⚓︎

write_autoformatted_md_sections ⚓︎

write_autoformatted_md_sections(handler_lookup=None, paths_md=None)

Populate the auto-formatted sections of markdown files with user-configured logic.

Source code in calcipy/md_writer/_writer.py
@beartype
def write_autoformatted_md_sections(
    handler_lookup: Optional[HandlerLookupT] = None,
    paths_md: Optional[List[Path]] = None,
) -> None:
    """Populate the auto-formatted sections of markdown files with user-configured logic."""
    _lookup: HandlerLookupT = handler_lookup or {
        'COVERAGE ': _handle_coverage,
        'SOURCE_FILE=': _handle_source_file,
    }

    paths = paths_md or find_project_files_by_suffix(get_project_path()).get('md') or []
    for path_md in paths:
        logger.text_debug('Processing', path_md=path_md)
        if md_lines := _ReplacementMachine().parse(read_lines(path_md), _lookup, path_md):
            path_md.write_text('\n'.join(md_lines) + '\n', encoding='utf-8')