Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you import/reference info from text files into a Markdown file?

Tags:

markdown

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?

like image 728
jadengore Avatar asked Feb 14 '14 02:02

jadengore


Video Answer


1 Answers

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.

like image 198
Chris Avatar answered Oct 11 '22 20:10

Chris