Experience of Project Contribution
Tags: javascript, opensource, beginners
Published: 2022-09-23 18:22:23

**The Background**
This week, I'm dealing with project contribution on GitHub, for both contributing to a project and accepting contribution.

**My Conbtirbution**
I openned an [issue](https://github.com/cychu42/ssg-cli-tool/tree/issue-8) and made a corresponding [pull request](https://github.com/alexsam29/ssg-cli-tool/pull/10) for an open source [Static Site Generator project](https://github.com/alexsam29/ssg-cli-tool) by Alexander Samaniego[(alexsam29)](https://github.com/alexsam29).
The goal was to add support for parsing Markdown files into HTML files, while also supporting italicization for those. Of course, I needed to update the README.md to reflect the changes.

**Code Changes**
- Added `isMd` boolean variable as flag for processing `.md` files
- Added code to use `isMd` when a file has the `.md` extension, to process them correctly
- Amended extension checking to include `.md` files for markdown file support
- Changed one error message to include markdown file when user uses a single invalid file as input, to update the message for the new markdown support
- Added code to wrap italicized markdown text (`*text*` or `_text_`) with `<i>` tag when writing output files, to support italicization in markdown files

**The Process And The Problem**
Initially, I open an issue that get accepted on the original repo. Then, I forked the repo, made my changes there, and made a pull request on the original repo. The changes include using `match()` function with regex to find the italicization markings and use `replace()` function to replace the 1st one with `<i>` and 2nd one with `</i>`.
Then, Alexander realized it didn't work for certain paragraphs or inclusion of some special characters. I figured out the issue is that the regex I used to catch the italicization markings didn't catch some special characters, so I updated the regex to do that, like:`/_[—!@#$%^&()+;/<>.\s\w\d,?"“”-]+_/`
There might be a better way to do it, but this is what I have managed to figured out. Alexander suggested `/_(.*?)_/`, but it didn't work for the `match()` function I was using.
With that done, I pushed the change to the forked repo to address the feedback. In the end, we decided to go with the solution, and Alexander merged the pull request. The tool now has the new features!

**The Learning**
I must say I learned new ways to use built-in functions and third-party tools from observing how Alexander code his static site generator differently from mine. For example, he uses `createHTML()` to generate HTML pages in standard format, and he uses Chalk npm package to provide messages to users with colours.
I think I'll try to use those new things in the future to be better and more versatile with my code. Knowing a way to give more colourful messages and having an easier way of creating standard HTML pages are both certainly nice to know.

**Accepting Contribution**
For my [repo](https://github.com/cychu42/staticSiteCon), Alexander opened an [issue](https://github.com/cychu42/staticSiteCon/issues/7) to [add features](https://github.com/cychu42/staticSiteCon/pull/8) to support `.md` input files and bolded text from those files into HTML files.

He also opened a [second issue](https://github.com/cychu42/staticSiteCon/issues/9) to [amend that](https://github.com/cychu42/staticSiteCon/pull/10), since the first attempt only recognized `**` for bolding text but not `__`.

It's interesting seeing another developer handling my code, given the difference in experience and style. Other than the main changes, Alexander proposed quite a few optimization to the change, which I greatly appreciates. For example, he turned some code into functions for re-usability and employed some functions I didn't think of initially, like `path.extname()`. I also gain some experience in collaborating with others on GitHub and Slack(I used this to chat with him) for my own open source projects.

**Giving Feedback**
Alexander didn't realize I intentionally left a String variable content that way it was in my program, so he tried to add space to it for code readability, which caused formatting issue when it's written into HTML files, so I had to ask him to revert the change. I manually written a part of standard HTML format, as template literal with some other variables inserted, into the String to be written to the HTML files, so the spacing is rather specific. In the end, things worked as expected, so I merged the first pull request.

During the second pull request from him, I noticed his solution doesn't deal with cases where a pair of bold markings are separated across multiple lines in a paragraph. The features stops working then, so I provided him with more details of how my program parses lines and hope that he can address such cases.