First Open Source Contribution
Tags: opensource, programming
Published: 2023-09-22 22:36:44

Hi everyone, I recently had the chance to work on amazing repo called [Learn2Blog](https://github.com/Yousef-Majidi/Learn2Blog). Learn2Blog is a cmd tool built in C# that is similar to my own [txt-to-html-convertor](https://github.com/Pasqua101/txt-to-HTML-converter). It allows you to convert a text file to html. However, I wanted to expand on this functionality and add in support for markdown (.md) files. More specifically, I also wanted it to convert the bold tag (`**word**`) in markdown to the `<strong>` tag in HTML.

I followed these step to make my first contribution:

1. I first created an issue on the repo. In the issue I described what it is that I wanted to do. You can find my issue [here](https://github.com/Yousef-Majidi/Learn2Blog/issues/7). Once I was given the go ahead from the owner it was time to move on to the next step.

2. I forked the repo into my own account, so I could edit my own version without it affecting the repo owner's code. 

3. I then cloned the forked version onto my PC and made a branch named after the issue. It was my first time using a branch, so I wasn't really sure how it  worked. But after seeing that it allows me to work in my own isolated environment from the main branch. I discovered how useful it can be for feature testing and bug fixes. I then started to work on the repo.

## Working on The Repo

After reading through the README and looking at the code I started to work on my implementation. I have a basic understanding of C#, so I was worried that I would have a hard time contributing to this repo. However, my worries were cleared up when I looked at the code. The code was easy to follow and I learned a lot of things by looking at it. 

When I started working on it, I was conflicted on if I wanted to make my feature in a separate file or in the same file containing the logic for converting a text file to html. This was a problem for me, because either I make a file containing a lot of the same logic (copied code) or I continue in the file that has already been made and make it look a little cluttered. I went for the former, but later was asked to go for the latter by the repo owner. Ignoring that for now, when working on the logic for my code, I built it to be similar to the function for converting txt files to html. The main difference in the logic of my md convertor is that my function reads line by line, instead of paragraph by paragraph. This is done so I can be able to determine when to insert the `<strong>` tag. To catch when the bold markdown tag is used I had to use a regular expression that I generated with a website, which looked like this `\*\*(.*?)\*\*`. It's very simple, it just looks for any text encased by ** on both ends.

After I implemented my code I committed and pushed my code. Then I made my pull request. I waited to get feedback from the repo owner, and when I did I was told to cleanup some of the copied code and remove some redundant code. I cleaned up the copied code by moving my newly created function to convert md to html into the file containing the logic to convert a txt file to html. I also updated the same file to support the conversion of md files, and removed any redundant code. I then again made a commit and updated the pull request. This commit cleared up a lot of issues, but some modifications I made when moving my function into the file containing the txt to html function could be more efficient. Thankfully these changes were very simple, and once I did it my pull request was approved and merged with the repo. I think next time, I will search for how I can make my code more efficient and probably make a contribution that adds on to functionality exist in the same file, if it will be reusing a lot of code.

## Contributions Made to my Repo

During this time, I also had someone contribute to my repo. It was for a similar request, which was adding support for md files and parsing links in md. I gave the person the go ahead and they made the contribution and the pull request. Their contribution was very good, but I did ask them to move it to a separate file, as I will be needing to go back to my repo when I have the chance and cleaning up my code. Since my main function for converting txt to html handles a lot more than that, and I would like to simplify it.  When they made that change, they also noticed a big issue with their contribution. The issue was that if two files of the same name but different extension existed in the same directory. The first file to be processed would be overwritten. For example, I have two files called test.txt and test.md in my notes directory. When I convert the two files in my notes directory, both files will be processed, but only the input from the test.md file will be shown in the output folder as the html file containing the input from test.txt will be overwritten. To fix this, they created a helper function similar to the Windows feature when duplicate file names exist, which is creating a test.html and test(1).html file. I'm glad they noticed this, because I then filed an issue for this problem on the repo I worked on.

I learned quite a bit contributing to open source projects. I didn't just expand on my C# knowledge, but I also learned more about git. I'm looking forward to seeing what else I can learn. Catch you all in the next post!