This repo demonstrates Markdown Embed Code From File (GitHub Action).
This would helps testing for your code within readme (actually for markdown).
You could put code in external file and test them, as same as ordinary testing your code. You don't need copy & paste code and feel anxisous about compatibility anymore.
This action could inspect your code, if you add a file path in code block as "```lang:external/file/path.py```".
The following code block has a file path src/helloworld.py
:
def hello():
return "world"
See with src/helloworld.py as:
- Synchronized code.
- Highlighting code in readme.
- Not affected code rendering.
And notice that nothing to do re-embedding new/modified code. This action overrides code if you change code in external file.
You might add one file path (ex. src/mul.py) for multiple code blocks:
from math import pow
def multiple(x):
return pow(x, 2)
It works!:
from math import pow
def multiple(x):
return pow(x, 2)
However, the other is not available.
Notice that this action goes to "fail" if a file you add does not exist.
This action could work for any programming "language".
Ideally you could write as "```lang:external/file/path.py```", but actually this action does not inspect "lang", just read path and copy&paste strings into target code block in markdown.
So, missing "lang" is available:
#!/bin/bash
echo "hello"