Skip to main content

Convert headings in a Markdown file (.md) into a tree-like structure and output.

Project description

marktree

GitHub License PyPI - Version PyPI - Downloads

This command converts headings in a Markdown file (.md) into a tree-like structure and outputs it.

Table of Contents

Setup

Install via pip:

pip install marktree

Handling "Warning" on Windows

If you encounter a "WARNING: The script clipcount.exe is installed in 'path' which is not on PATH." when running the above command on Windows, please refer to the following article:

Reference: 【Python Windows】pip install でPATHが通らない時の解決方法 | ゆすノート

If you see "WARNING: Failed to write executable - trying to use .deleteme logic", please refer to the following article:

Reference: 【Windows】警告が出て「pip install」できない時の解決方法 | ゆすノート

Quick Usage

$ marktree [Options] [foo.md]
Options Description
marktree -h Display the help screen.
marktree --help-jp Display the help screen in Japanese.
marktree -L 3 Determines the depth at which the tree is displayed (default: 6).
marktree -C Outputs the Markdown text copied to the clipboard directly in tree format.
marktree -P Outputs only the headings without tree formatting (plain view).
marktree -E Specifies the file encoding (example: utf-8, cp932, shift_jis). Use this if you get a "Decode Failed" error (default: utf-8).

Example

Prepare the following Markdown file foo.md:

# h1
This is an introduction paragraph under h1. It gives an overview of the section.

## h2
Here we discuss the first topic in detail, providing some context and background.

### h3
This subsection contains more specific details about the topic introduced above.

#### h4
Additional notes and clarifications are provided here to help understand the subtopic.

#### h4
Another set of points and examples relevant to this sub-subsection.

## h2
The second main point of this section is introduced here with supporting information.

## h2
This section explains another topic of equal importance, with examples and discussion.

### h3
A deeper dive into the details of the second topic, explaining key concepts.

#### h4
Specific use cases and examples are provided here to clarify the points above.

##### h5
Minor subpoints or notes that are relevant but not central to the discussion.

###### h6
Detailed footnotes, references, or additional tips can be added here for completeness.

### h3
Concluding remarks for this subsection, summarizing key takeaways.

# h1
Final section summarizing the overall content and providing closure.
  • Regular output (default depth is 6):
$ marktree foo.md
├── h1
│  ├── h2
│    └── h3
│       ├── h4
│       └── h4
│  ├── h2
│  └── h2
│     ├── h3
│       └── h4
│          └── h5
│             └── h6
│     └── h3
└── h1
  • Using -L 3 to limit depth:
$ marktree -L 3 foo.md
├── h1
│  ├── h2
│    └── h3
│  ├── h2
│  └── h2
│     ├── h3
│     └── h3
└── h1
  • Using -C to read from clipboard directly (can combine with -L):
$ marktree -C -L 3
├── h1
│  ├── h2
│    └── h3
│  ├── h2
│  └── h2
│     ├── h3
│     └── h3
└── h1
  • Using -P to output headings only:
$ marktree -C -P
# h1
## h2
### h3
#### h4
#### h4
## h2
## h2
### h3
#### h4
##### h5
###### h6
### h3
# h1

Usage

The marktree command outputs the file as a tree hierarchy based on the # headings in the Markdown file.

  • The -L option specifies the output depth, similar to the original tree command. Depth can be from 1 to 6; specifying more than that will result in an error (default: 6).
  • The -C option outputs Markdown text copied to the clipboard directly in tree format. This eliminates the need to copy the Markdown text to another file before outputting.
  • The -P option outputs headings in plain format without tree formatting. Use this if you only want the headings.
  • The -E option allows you to specify the file encoding (examples: utf-8, cp932, shift_jis). Use this if you encounter a "Decode Failed" error (default: utf-8).

The order of options is flexible, including the Markdown file to be processed. If multiple files are provided (e.g., markdown foo.md hoge.md), only the last file will be converted and output.

Dependencies

Dev-diary

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

marktree-1.2.0.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

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

marktree-1.2.0-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file marktree-1.2.0.tar.gz.

File metadata

  • Download URL: marktree-1.2.0.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.0 CPython/3.13.6 Windows/11

File hashes

Hashes for marktree-1.2.0.tar.gz
Algorithm Hash digest
SHA256 e5606204ea7fdc842be6512dc2651154dd940ed569231919886329fa9998e60d
MD5 213cd0d84d4f3be3356d22443c65c823
BLAKE2b-256 059e91b84eb898482a6d67903e2ee0670a457e4dfaf141a2939897882388067e

See more details on using hashes here.

File details

Details for the file marktree-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: marktree-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.0 CPython/3.13.6 Windows/11

File hashes

Hashes for marktree-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b8f058cc7e5b2f106b2cc1f00248dfff2806965a883715db390594ad5e0e3552
MD5 657bda49f0ac5a89f4d14921587aba85
BLAKE2b-256 31644a255fdaba86e64da12902465d19fc0c4a539294b2d8be08f3c1605e640e

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