Package: mdsplit
mdsplitmdsplitis a python command line tool tosplit markdown filesinto chaptersat a givenheading level.Each chapter (or subchapter) is written to its own file,
which is named after the heading title.
These files are written to subdirectories representing the document's structure.
Optionally a table of contents (toc.md) can be created for each input file.Note:Code blocks(```)are detected (and headers inside ignored)The output isguaranteed to be identicalwith the input
(except for the separation into multiple files of course)This means: no touching of whitespace or changing-to*of your lists
like some viusual markdown editors tend to doText before the first heading is written to a file with the same name as the markdown fileChapters with the same heading name are written to the same file.Reading fromstdinis supportedCan easily handle large files,
e.g. a 1 GB file is split into 30k files in 35 seconds on my 2015 Thinkpad (with an SSD)Limitations:OnlyATX headingssuch as# Heading 1are supported.Setext headings(underlined headings) are not recognised.Similar projects:You may also be interested inhttps://github.com/alandefreitas/mdsplit(C++-based).InstallationEither use pip:pip install mdsplit
mdsplitOr simply downloadmdsplit.pyand run it (it does not use any dependencies but python itself):python3 mdsplit.pyUsageShow documentation and supported arguments:mdsplit--helpusage: mdsplit.py [-h] [-e ENCODING] [-l {1,2,3,4,5,6}] [-t] [-o OUTPUT] [-f] [-v] [input]

positional arguments:
  input                 path to input file/folder (omit or set to '-' to read from stdin)

options:
  -h, --help            show this help message and exit
  -e ENCODING, --encoding ENCODING
                        force a specific encoding, default: python's default platform encoding
  -l {1,2,3,4,5,6}, --max-level {1,2,3,4,5,6}
                        maximum heading level to split, default: 1
  -t, --table-of-contents
                        Generate a table of contents (one 'toc.md' per input file)
  -o OUTPUT, --output OUTPUT
                        path to output folder (must not exist)
  -f, --force           write into output folder even if it already exists
  -v, --verboseSplit a file at level 1 headings, e.g.# This Heading, and write results to an output folder based on the input name:mdsplitin.md%%{init: {'themeVariables': { 'fontFamily': 'Monospace', 'text-align': 'left'}}}%%
flowchart LR
    subgraph in.md
        SRC[# Heading 1<br>lorem ipsum<br><br># HeadingTwo<br>dolor sit amet<br><br>## Heading 2.1<br>consetetur sadipscing elitr]
    end
    SRC --> MDSPLIT(mdsplit in.md)
    MDSPLIT --> SPLIT_A
    MDSPLIT --> SPLIT_B
    subgraph in/HeadingTwo.md
        SPLIT_B[# HeadingTwo<br>dolor sit amet<br><br>## Heading 2.1<br>consetetur sadipscing elitr]
    end
    subgraph in/Heading 1.md
        SPLIT_A[# Heading 1<br>lorem ipsum<br><br>]
    end
    style SRC text-align:left
    style SPLIT_A text-align:left
    style SPLIT_B text-align:left
    style MDSPLIT fill:#000,color:#0F0Split a file at level 2 headingsand higher, e.g.# This Headingand## That Heading, and write to a specific output directory:mdsplitin.md--max-level2--outputout%%{init: {'themeVariables': { 'fontFamily': 'Monospace', 'text-align': 'left'}}}%%
flowchart LR
    subgraph in.md
        SRC[# Heading 1<br>lorem ipsum<br><br># HeadingTwo<br>dolor sit amet<br><br>## Heading 2.1<br>consetetur sadipscing elitr]
    end
    SRC --> MDSPLIT(mdsplit in.md -l 2 -o out)
    subgraph out/HeadingTwo/Heading 2.1.md
        SPLIT_C[## Heading 2.1<br>consetetur sadipscing elitr]
    end
    subgraph out/HeadingTwo.md
        SPLIT_B[# HeadingTwo<br>dolor sit amet<br><br>]
    end
    subgraph out/Heading 1.md
        SPLIT_A[# Heading 1<br>lorem ipsum<br><br>]
    end
    MDSPLIT --> SPLIT_A
    MDSPLIT --> SPLIT_B
    MDSPLIT --> SPLIT_C
    style SRC text-align:left
    style SPLIT_A text-align:left
    style SPLIT_B text-align:left
    style MDSPLIT fill:#000,color:#0F0Split markdown from stdin:catin.md|mdsplit--outputoutDevelopment (Ubuntu 22.04)Add thedeadsnakes PPAand install additional python versions for testingsudoadd-apt-repositoryppa:deadsnakes/ppa
sudoaptinstallpython3.7python3.7-distutils
...InstallpoetryPrepare virtual environment and download dependenciespoetry installRun tests (for the default python version)poetry run pytestRun tests for all supported python versionspoetry run toxRelease new versionpoetry build
poetry publishDownload statistics