├── .gitignore ├── README.md ├── mddoc.nimble └── src └── mddoc.nim /.gitignore: -------------------------------------------------------------------------------- 1 | # ignore files with no extention: 2 | * 3 | !*/ 4 | !*.* 5 | 6 | # normal ignores: 7 | *.exe 8 | nimcache 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # mddoc 2 | A tool to generate Nim API docs in markdown for GitHub's README.md files. Great for small libraries with simple APIs. 3 | 4 | Run this in the same folder as the `README.md` file: 5 | ```sh 6 | mddoc .\src\flippy.nim 7 | ``` 8 | 9 | Your `README.md` should now have an API section. 10 | -------------------------------------------------------------------------------- /mddoc.nimble: -------------------------------------------------------------------------------- 1 | # Package 2 | 3 | version = "0.0.4" 4 | author = "treeform" 5 | description = "Generate Nim API docs in markdown for GitHub's README.md files." 6 | license = "MIT" 7 | srcDir = "src" 8 | 9 | bin = @["mddoc"] 10 | 11 | # Dependencies 12 | 13 | requires "nim >= 1.0.0" 14 | -------------------------------------------------------------------------------- /src/mddoc.nim: -------------------------------------------------------------------------------- 1 | import json, os, re, strutils 2 | 3 | if paramCount() != 1: 4 | echo "Got to the root of your library, where the README.md is." 5 | echo "Usage: mddoc path/to/library.nim" 6 | quit() 7 | 8 | echo paramStr(1) 9 | 10 | discard os.execShellCmd("nim jsondoc -o:doc.json " & paramStr(1)) 11 | 12 | var doc = parseJson(readFile("doc.json")) 13 | 14 | var md = "" 15 | md.add "# API: " & doc["nimble"].getStr() & "\n" 16 | md.add "\n```nim\n" 17 | md.add "import " & doc["nimble"].getStr() & "\n" 18 | md.add "```\n" 19 | md.add "\n" 20 | if "description" in doc and doc["moduleDescription"].getStr() != "": 21 | md.add doc["moduleDescription"].getStr() 22 | md.add "\n" 23 | 24 | for entry in doc["entries"]: 25 | echo "* ", entry["name"].getStr() 26 | md.add "## **" & 27 | entry["type"].getStr()[2..^1].toLowerAscii() & 28 | "** " & entry["name"].getStr() & "\n" 29 | md.add "\n" 30 | if "description" in entry: 31 | md.add entry["description"].getStr() 32 | .replace("