Github markdown load code block from a repo file

Viewed 1310

I want to add a JSON code block in my README.md and the code block needs to be loaded from the repo file.

E.g, is it possible to do the following?

```json
<<load data from res/data.json>>
```

where res/data.json is a file in the same repo? I know it is possible to have a hyperlink, but I want the JSON data to appear there directly without clicking on the hyperlink.

2 Answers

This is not possible to do with GitHub Flavored Markdown.

You could programmatically update your README.md and then commit the resulting file, though. The simplest solution would probably be to have a README-top.md containing everything up to ```json and a README-bottom.md containing ``` to the end of the file.

Then you could simply do something like

cat README-top.md res/data.json README-bottom.md > README.md

There are lots of other options, including fairly complex templating tools.

A pre-commit hook would let you automate this even further, updating your README.md every time you commit locally.

Related