Dynamically insert code blocks in a Markdown file from source script(s)
Inserts complete contents of files as as dynamically generated subsections, or parts (Markdown code blocks), of a newly generated Markdown file (output/new.md).
Allows a static, master template, master_README.md, to have dynamically generated subsections which are populated by the full contents of each file in scripts/.
Each file in scripts/ becomes a Markdown code block in the new outout/new.md.
ie:
Some static content.
Full contents of one of the files in scripts/
More static content.
Full contents of another file in scripts/
$ pip install jinja2)
.├── LICENSE.txt├── README.md├── dynreadme.py├── output│ └── new.md├── scripts│ ├── Auto.sh│ ├── script-with-dashes.py│ ├── test.echo.sh│ └── timed_process_killer.sh└── templates├── master_README.md└── temporary_template.md
README.md: dynreadme.py: output/new.md, combining static content from templates/master_README.md as well as the file contents of each file in scripts/output/new.md: dynreadme.py.scripts/: Auto.sh, timed_process_killer.sh, test.echo.sh, script-with-dashes.py: code blocks within the new output/new.md file. Replace these with your own files. templates/master_README.md: {{ variables }} which represent each file in scripts/ (sections of your README you want to be replaced with full file contents from each file in scripts/). Each {{ variable }} gets dynamically populated with the contents of one of the files from scripts/. templates/temporary_template.md: dynreadme.py to accomodate the per-iteration adding of special prefixes needed for files with a . or - in their name. Gets created / overwritten on every run of dynreadme.py. No configuration needed in this file.In the templates/master_README.md put a reference to each file in scripts/ whose contents you want to become a code block in the final output/new.md on a line by itself, surrounded by {{ }}. These become the master_README.md variables.
For example, for scripts/Auto.sh enter a line that says {{ Auto }} into templates/master_README.md.
master_README.md variables:{{ file_name }}{{ file_name.sh }}-) and dots / periods (.){{ file-name }} {{ file.name }}For every file in scripts/, there should also be a {{ filename }} variable inside templates/master_README.md. Ensure there is a one for one match.
dynreadme.py includes a --suggest function to automatically suggest {{ var-names }} for you to use inside templates/master_README.md.
Example:
$ ./dynreadme.py --suggestSuggested master template variable for scripts/Auto.sh:{{ Auto }}Suggested master template variable for scripts/script-with-dashes.py:{{ script-with-dashes }}Suggested master template variable for scripts/test.echo.sh:{{ test.echo }}Suggested master template variable for scripts/timed_process_killer.sh:{{ timed_process_killer }}
dynreadme.py:
$ ./dynreadme.pyTemplate variables found in templates/master_README.md:Autoscript-with-dashestest.echotimed_process_killerAdding contents of scripts/Auto.sh to output/new.mdAdding contents of scripts/script-with-dashes.py to output/new.mdAdding contents of scripts/test.echo.sh to output/new.mdAdding contents of scripts/timed_process_killer.sh to output/new.md
The newly generated file (combination of static content from templates/master_README.md and the dynamic file contents of each file in scripts/ is created in output/new.md.
If dynreadme has been run previously, and there is already a new.md in output/, a backup of the previous output/new.md is created called new_previous.md (if you need to retain more than one previous version you will need to save it out manually).
$ ./dynreadme.py --help
Please open a new Issue.
| OS | Python version(s) |
|---|---|
| OSX 10.10.2 | 2.7.9 and 3.4.3 |
| Windows 7 | 2.7.2 and 3.4.3 |
| Elementary OS (Ubuntu) | 2.7.6 and 3.4.0 |