Coding help/learning opportunity want to convert all files in a githubrepo directory to md and insert javascript markdown

So, over the last 6 months or so, I have put all of the algorithm challenges and other non-trivial challenge solutions in a Github repo. I would like to convert all of these files to md(markdown file) and insert javascript markdown opening and closing tag in the bottom so the syntax will be highlighted.

Rather than doing it manually, I want to turn this into learning opportunity and timesaver. As this is a repetitive simple task I thought it would be a perfect candidate to automate through code or at least perform as a batch process.

In my research, I found something called pandoc that seems to be a popular tool used in Github repository management and other use cases. That’s about as far as I have gotten.

My question is am I headed down the right path and does anyone have any pointers from here?

my algo challenge repo

I’ve been starting to incorporate more and more best practices into all my coding projects. Even for algo challenges, I’m starting to use Github proper version control branching and engineering/compsci practices of pseudocode algorithm development before I even start coding. I find that for most cases rather than slowing me down as I get used to it I end up creating more optimal code in a shorter time on average. Even for small projects I’m trying to keep this habit so it becomes second nature. Not quite there yet, but its always a journey right?

Anyway, any help with this practical application would be greatly appreciated.

From a brief look at the repo, most of the files are entirely JS

To convert a file like that into valid markdown you’d put a line at the beginning of the file containing


and a line at the end containing


and that’s all (though maybe change the file extension too to be clear it’s intended to be interpreted as markdown)

1 Like

I know how to do that I want to complete that task with code or some kind of github plug in task… I know its possible because I saw someone do something similar.

I want to run code on my repo that converts the remaing files to .md and inserts

in the beginning
and then the closing backticks.

pandocs seems to be the right direction.

Thanks for reply :smiley:

pandoc converts between different file formats that it understands the symantics of, such as markdown and pdf etc

It doesn’t understand that a given plain text file is javascript, or how to parse a javascript file

It’s a pretty incredible piece of software, but you’ll have to convert the plain text files to markdown yourself

Prepending that line and appending the other line can be done programmatically, with say bash or python or node, fairly straightforwardly

As an example in bash for a single file:

echo '```javascript' >
cat algoChallengeSlasher >>
echo '```' >>

Edit: I suspect part of the confusion is coming from not knowing that markdown is basically just plain text - there’s nothing special about the markdown format, it’s just a plain old text file so there’s no magic that needs to be done like when converting things to pdf or word docs

1 Like

Thanks for the help. This is exactly what I wanted to know. It’s a great reason to dive in to using CLIs as well. I did read somewhere that pandoc can change the file extension for me in some way, unless I am mistaken. Then those bash commands will take care of the second step. I guess I could write some code in a to cycle wthrough and use the bash you wrote as a callback function in a forEach?

I haven’t used windows in a long time, so not sure if there’s some windows specific thing you’re referring to with file extensions there

In other operating systems like Linux the file extension is just part of the file name, so just renaming the file to is enough

Yes that’s a perfectly reasonable way of breaking down the problem, though interfacing javascript in node with some bash can be pretty ugly

If you’re interested in doing it with a bash environment specifically you should know that you can loop over all the file names quite easily and call a bash function on them

Alternatively if you want to turn it into a really crazy but nifty one-liner later you could use the find command (type man find) to read more about it

one step at a time though obviously

might be worth reading up on node.js and how to manipulate files with it if you want to specifically do it with javascript

I’m not against doing it the bash way.