I haven't been able to find an example for this, but is it possible to import text by reference into a Markdown file? For example, say I have my README.md
. Can Markdown import from somefile.txt
into the README, like with image references?
Easy answer: No, Markdown does not support this.
Slightly more complicated answer: If you don't mind manually concatenating files or writing a simple build script, you can easily fake it. Consider the following simple example:
parts/
is a directory to hold your partial files.
01-introduction.md
contains your Markdown introduction, header, etc.02-somefile.txt
contains the information that you want to include immediately after 01-introduction.md
.03-conclusion.md
contains your Markdown conclusion, outro, copyright information, and whatever else you may want.Now you can concatenate these files into your main Markdown file. If you're on a Unixy system, something like cat parts/* > final.md
will work. On Windows, I believe the equivalent would be type parts\* > final.md
.
Writing a shell script called build.sh
or build.bat
will make this process less painful if you plan on updating your content regularly.
Note that, instead of simply concatenating your files, you may want to play with Pandoc, which can take multiple input files and output Markdown (and several other formats). This will be particularly interesting if your target format isn't actually Markdown, but rather HTML, PDF, or something else.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With