Skip to content

CLI

cli()

CLI tool to remove and restore markdown links.

Source code in src/mdminify/cli.py
6
7
8
9
@click.group()
@click.version_option()
def cli():
    """CLI tool to remove and restore markdown links."""

remove(input_md_file, output_md_file, output_json_file)

Removes markdown links from the input file and saves the plain text (without links) to the output markdown file, while storing the extracted links in a JSON file.

Parameters:

Name Type Description Default
input_md_file str

Path to the markdown file that contains links.

required
output_md_file str

Path where the processed markdown (without links) will be saved.

required
output_json_file str

Path where the extracted links (as JSON) will be stored.

required
Side Effects
  • Creates or overwrites the output markdown file with the plain text (links removed).
  • Creates or overwrites the JSON file with the extracted links.
Example

$ mdminify remove input.md output.md links.json

This will process input.md, save the plain text (without links) to output.md, and store the extracted links in links.json.

Source code in src/mdminify/cli.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
@click.command()
@click.argument("input_md_file", type=click.Path(exists=True))
@click.argument("output_md_file", type=click.Path())
@click.argument("output_json_file", type=click.Path())
def remove(input_md_file, output_md_file, output_json_file):
    """
    Removes markdown links from the input file and saves the plain text (without links)
    to the output markdown file, while storing the extracted links in a JSON file.

    Args:
        input_md_file (str): Path to the markdown file that contains links.
        output_md_file (str): Path where the processed markdown (without links) will be saved.
        output_json_file (str): Path where the extracted links (as JSON) will be stored.

    Side Effects:
        - Creates or overwrites the output markdown file with the plain text (links removed).
        - Creates or overwrites the JSON file with the extracted links.

    Example:
        $ mdminify remove input.md output.md links.json

    This will process `input.md`, save the plain text (without links) to `output.md`,
    and store the extracted links in `links.json`.
    """
    process_markdown_file(input_md_file, output_md_file, output_json_file)
    click.echo(f"Processed markdown saved to {output_md_file}, links saved to {output_json_file}")

restore(plain_md_file, json_file, output_md_file)

Restores markdown links in the plain markdown file using the stored links from the JSON file, and saves the result to a new markdown file.

Parameters:

Name Type Description Default
plain_md_file str

Path to the plain markdown file (without links).

required
json_file str

Path to the JSON file that contains the extracted links.

required
output_md_file str

Path where the markdown file with restored links will be saved.

required
Side Effects
  • Creates or overwrites the output markdown file with the restored markdown (links reinserted).
Example

$ mdminify restore output.md links.json restored.md

This will restore links in output.md using links.json, and save the result to restored.md.

Source code in src/mdminify/cli.py
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
@click.command()
@click.argument("plain_md_file", type=click.Path(exists=True))
@click.argument("json_file", type=click.Path(exists=True))
@click.argument("output_md_file", type=click.Path())
def restore(plain_md_file, json_file, output_md_file):
    """
    Restores markdown links in the plain markdown file using the stored links
    from the JSON file, and saves the result to a new markdown file.

    Args:
        plain_md_file (str): Path to the plain markdown file (without links).
        json_file (str): Path to the JSON file that contains the extracted links.
        output_md_file (str): Path where the markdown file with restored links will be saved.

    Side Effects:
        - Creates or overwrites the output markdown file with the restored markdown (links reinserted).

    Example:
        $ mdminify restore output.md links.json restored.md

    This will restore links in `output.md` using `links.json`, and save the result to `restored.md`.
    """
    restore_links_from_json(plain_md_file, json_file, output_md_file)
    click.echo(f"Restored markdown with links saved to {output_md_file}")