Skip to main content

No project description provided

Project description

dir2md

dir2md is a command-line tool that converts directories of files into Markdown code blocks. It also provides a reverse function, md2dir, which converts Markdown code blocks back into their original files.

Installation

Install dir2md using pip:

pip install dir2md

Usage

dir2md can be used as a command-line tool or imported as a module.

Command-Line Tool

To convert a directory of files to Markdown code blocks, run:

dir2md [files...]

This will print the resulting Markdown to the console.

To convert Markdown code blocks back into their original files, run:

md2dir [options] 

This will create the files in the current working directory.

For more options and usage details, use the --help flag.

Module

import dir2md

# Convert a directory of files to Markdown code blocks
markdown = dir2md.dir2md("file1.py", "file2.py")

# Convert Markdown code blocks back into their original files
dir2md.md2dir_save(markdown, output_dir="output/")

Wildcard support

You can use wildcards (*) to pass multiple files at once.

For example, to include all Python files in the current directory:

dir2md *.py

To do so recursively, use **:

dir2md **/*.py

dir2md uses glob to parse your path pattern. To turn this off, use the --no-glob flag.

Truncation

dir2md now supports truncating long files with the {start_line,end_line} syntax added to the file or directory path.

For example:

  • Get the first 10 lines of a file: dir2md "path/to/file.py[:10]"
  • Get lines 10 to 20: dir2md "path/to/file.py[10:20]"
  • Get everything from line 10 until the end of the file: dir2md "path/to/file.py[10:]"
  • Get the first 10 lines of a file followed by an ellpsis: dir2md "path/to/file.py[:10...]"
  • Negative indices: dir2md "path/to/file.py[-10:]"
  • Multiple truncations: dir2md "path/to/file.py[:10 20:]"
  • Omit the entire contents of the file with an ellipsis: dir2md "path/to/file.py[..]"

This syntax can be used with wildcards as well.

The quotation marks are required to prevent your shell from interpreting the brackets as special characters.

dir2md *.py[:10]   # First 10 lines of all .py files
dir2md **/*.py[5:]  # All lines after the first 5 lines in all .py files recursively

Handling missing files

You can customize the behavior when a specified file is not found using the on_missing option. By default, it is set to "error" which will raise a FileNotFoundError. To ignore the missing file and continue processing other files, pass on_missing="ignore" as an argument to the dir2md function.

dir2md("missing_file.py", on_missing="ignore")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dir2md-0.3.1.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dir2md-0.3.1-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file dir2md-0.3.1.tar.gz.

File metadata

  • Download URL: dir2md-0.3.1.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.1 CPython/3.11.0 Darwin/22.4.0

File hashes

Hashes for dir2md-0.3.1.tar.gz
Algorithm Hash digest
SHA256 eea30c466d2506571dc32c6631486480efbe96bbc249d8b36f1ce4458fc5c668
MD5 ddbc254c82ea3bd1479a9f35fc97f314
BLAKE2b-256 a9cf7524ad878993fb49838985743265c999bd9aa2c2424703d613b8385d5f6a

See more details on using hashes here.

File details

Details for the file dir2md-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: dir2md-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.1 CPython/3.11.0 Darwin/22.4.0

File hashes

Hashes for dir2md-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 71429661d5b16b30aef3edc4f2be4624631d6a10878a105b35db8c47861539ea
MD5 b9145ab0f8ac8b7f6e113b4154c3f47d
BLAKE2b-256 3ecd80efa2993c2904a050f690f0b8a5f530d385f1eb3fad568d58cd3f1cf3c4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page