Is copying from open source projects stealing?
Tags: opensource, programming, beginners, codenewbie
Published: 2023-11-01 03:55:26

### Good programmers copy; Greater programmers steal?


> Good artists copy; Great artists steal
> \- Pablo Picasso

Pablo Picasso is often credited for saying the above quote. I'm not going to provide my own interpretation of this quote, as there are loads of interpretations available online for those interested. However, I've often wondered how this quote could apply to programming and to Open Source development.

### Is our programming knowledge really our own?
The Internet is full of resources to teach you almost anything programming related. Myself and many of my classmates have learned practically all of their programming knowledge from textbooks, online resources/documentation, and YouTube tutorials. These resources have taught us the programming knowledge we have and apply today, but is all of that knowledge stolen? Are you stealing code if you're learned to write your first `Hello World` program from a YouTube tutorial thousands of others have watched? What are the chances the video uploader also learned to write a `Hello World` program using external resources? Is the uploader's knowledge stolen?

I can't say whether this knowledge is stolen, but I believe this kind of knowledge is necessary for us to build on and expand our skills. No one person can know every perfect implementation or program every line of code for every project.

### Open Source software is made to be used!
Open Source software does not exist to be ignored, Open Source software is meant to be used! If an Open Source project provides the functionalities you need, why implement the functionalities yourself when others have painstakingly done it for you? As long as the library is actively maintained and does what you need it to, you should use and study the Open Source library. Should you find any bugs, issues, or missing features, try and create your own solution and contribute to the project to make it better for everyone! Similarly, if an Open Source library provides functionality you need but you cannot integrate the library, implement the feature in your own project using the Open Source project as an inspiration.

### Taking inspiration from other projects
In my previous [blog post on Code Reading](https://dev.to/rjwignar/code-reading-i7h), I read the codebase of Docusaurus to research how the project implements Syntax Highlighting for fenced code blocks. My research taught me that Docusaurus actually uses [Prism-React-Renderer](https://github.com/FormidableLabs/prism-react-renderer), a third-party library, to provide Syntax Highlighting. This knowledge was useful because I wanted to add syntax highlighting to [ctil](https://github.com/rjwignar/ctil), my Markdown-to-HTML converter, but didn't want to implement the feature from scratch. Although I can't use Prism React Renderer in my own project, researching Docusaurus gave me the idea to find a Open Source library I could use.

### Syntax Highlighting with highlight.js
My search for a third-party syntax highlighter brought me to [highlight.js](https://highlightjs.org/). ctil converts text (`.txt`) and Markdown (`.md`) to generated HTML (`.html`) files, so I want the generated HTML files to support syntax highlighting. highlight.js can be used as HTML Tags by using a Content Delivery Network, CDN, so I was able to add highlight.js by adding the following lines to the generated HTML files:
```html
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/default.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
<script>hljs.highlightAll();</script>

```
and with these lines, I was able to [add syntax highlighting](https://github.com/rjwignar/ctil/commit/c597f05724b60731e129aead33f1c3017a99ec17):

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k74q82mbi46fbbqupbri.png)


### Comparison to Docusaurus approach
In my [previous blog post](https://dev.to/rjwignar/code-reading-i7h), I described how Docusaurus used Prism React Renderer to add syntax highlighting. Like Docusaurus, I used a third-party library, highlight.js, to add syntax highlighting. However, in Docusaurus configuration files were added and modified to setup Prism React Renderer, and syntax highlighting was added by using the `<Highlight />` component. Prism React Renderer also provides highlighting themes that users can configure in their projects. For my project just added highlight.js to my generated HTML files as HTML tags to be delivered through CDN. For now I'm content with basic syntax highlighting, so I'm not concerned about having a specific highlighting theme. One disadvantage of using highlight.js via CDN is that the syntax highlighting likely won't work if the user is online. In the future I may add highlight.js to the project itself so syntax highlighting will work offline.

### Next steps.
This feature is still in development. In the current iteration, html is used as the default language class for the `<code>...</code>` block. This is acceptable for now, but this solution will ignore any language class settings in the original Markdown file(s). I want ctil to parse language tags from the Markdown files to determine which language to use for highlighting. That will be an issue to fix in the future. The issue is available [here](https://github.com/rjwignar/ctil/issues/11) for those interested.

### So is copying code from Open Source projects stealing?
As long as copying is allowed under the project's license and you follow the requirements of the project's license you aren't stealing. Similarly, I would argue looking to open source projects for inspiration is not stealing.