Package: gfm-toc
gfm-toc中文文档|READMETable of ContentsOverviewInstallationUsageSingle fileMultiple filesConfigurationcustomize the header levelWrite results to a file or print to standard outputAdd a title to the generated TOCDependencyLicenseOverviewEasy and customizable way togenerate TOCfor README.md on GitHub.Automatically generate table of contents in accordance with Github Favored Markdown formatJust a single .py file can be done with no other dependenciesSupport for text content in both Chinese and English languagesSupport for customizing the header level of the table of contentsSupports automatic write results to files, and also can print results to standard output for further processingSupports generating table of contents for multiple files at the same timeSupport for repeating headers, filtering headers in code blocksIf you don't want to download any files or read the command instructions below, you can try my online build tool.InstallationPypi$pip3installgfm-toc--upgradeManually$gitclonehttps://github.com/waynerv/github-markdown-toc
$cdgithub-markdown-toc
$python3setup.pyinstallYou can also directly download the filegfm_toc/md_toc.pyin the repository and run this script manually like this:$python3md-toc.py[-h][-s{1,2,3,4,5,6}][-e{1,2,3,4,5,6}][-o]file[file...]UsageThe command syntax is as follows：$gfm-toc[-h][-s{1,2,3,4,5,6}][-e{1,2,3,4,5,6}][-o]file[file...]Run the command as follows to get help information for the command options（you can replace-hwith--help).:$gfm-toc-hNote: Make sure your device has successfully installed Python3 before run it.Single fileAutomatically generateTOCfor a single markdown file and print result to standard output with only 2-4 title levels:$gfm-toc-s2-e4-oREADME_eng.md
Generatefromfile:README_eng.md

-[TableofContents](#table-of-contents)-[md-toc](#md-toc)-[Installation](#installation)-[Usage](#usage)-[Singlefile](#single-file)-[Multiplefiles](#multiple-files)-[Configuration](#configuration)-[customizethetitlelevel](#customize--the-title-level)-[Writeresultstoafileorprinttostandardoutput](#write-results-to-a-file-or-print-to-standard-output)-[Dependency](#dependency)Tableofcontentsgenerated.Then copy/paste result between prompt sentence from console into original README.md.Multiple filesUse the default configuration to generateTOCfor multiple markdown files and write them to a file separately:$gfm-tocfile01.mdfile02.mdfile03.md
Tableofcontentsgenerated.Here's an example：File_without_TOC.mdAfter generatingTOCand writing to the file：File_with_TOC.mdConfigurationcustomize the header levelUse the command line options-sor--startand add parameters to set the start header level ofTOC. The default value of the parameter is 1.Use the command line options-eor--endand add parameters to set the end header level ofTOC. The default value of the parameter is 6.The title level parameter must be an integer between 1 and 6, and the start header level cannot be greater than the end header level.-s{1,2,3,4,5,6},--start{1,2,3,4,5,6}choosethestartlevelofTOC,defaultvalueis1-e{1,2,3,4,5,6},--end{1,2,3,4,5,6}choosetheendlevelofTOC,defaultvalueis6GenerateTOCof 1-6 header levels (default option):$gfm-toctest/Mastering_Markdown.md-o
Generatefromfile:test/Mastering_Markdown.md

-[MasteringMarkdown](#mastering-markdown)-[WhatisMarkdown?](#what-is-markdown)-[Examples](#examples)-[Syntaxguide](#syntax-guide)-[Headers](#headers)-[Emphasis](#emphasis)-[Lists](#lists)-[Unordered](#unordered)-[Ordered](#ordered)-[Images](#images)-[Links](#links)-[Blockquotes](#blockquotes)-[Inlinecode](#inline-code)Tableofcontentsgenerated.Only generate 2-3 header levels:$gfm-tocexamples/Mastering_Markdown.md-o-s2-e3Generatefromfile:examples/Mastering_Markdown.md

-[WhatisMarkdown?](#what-is-markdown)-[Examples](#examples)-[Syntaxguide](#syntax-guide)-[Headers](#headers)-[Emphasis](#emphasis)-[Lists](#lists)-[Images](#images)-[Links](#links)-[Blockquotes](#blockquotes)-[Inlinecode](#inline-code)Tableofcontentsgenerated.Write results to a file or print to standard outputBy default, the program automatically writes the generatedTOCto the beginning of the original file.Add the option-oor--outputwhen you want to print the results to standard output for copying or other processing.-o,--outputprinttoctostdoutinsteadofwritingtofileUse the>on the command line to export the generated directory to a separate file:$gfm-toc-oREADME.md>table_of_content.mdAdd a title to the generated TOCThis option is not very common, because in many cases, people write Markdown documents according to different specifications or their own habits. But if you need, you can add-tor--titleoptions when executing commands. This will add a level 2 header calledTable of contensto the generatedTOC, as follows:$gfm-tocexamples/Mastering_Markdown.md-o-s2-e3-t
Generatefromfile:examples/Mastering_Markdown.md## Table of contents-[WhatisMarkdown?](#what-is-markdown)-[Examples](#examples)-[Syntaxguide](#syntax-guide)-[Headers](#headers)-[Emphasis](#emphasis)-[Lists](#lists)-[Images](#images)-[Links](#links)-[Blockquotes](#blockquotes)-[Inlinecode](#inline-code)Tableofcontentsgenerated.DependencyPython3Tested on Ubuntu 18.04 in bash with Python 3.6.7.LicenseMIT