DEV Community

Marco Pasqua
Marco Pasqua

Posted on

TXT to HTML Conversion Tool

Hi everyone!

I'm excited to share with you all that I've built my first command line tool! It's a very simple tool that can convert txt files to HTML. The tool is called txt-to-HTML-converter. Its built in Python 3, and allows you to convert either a single txt file or several txt files in a folder to html. I'll discuss about it below.

How to Use

  1. Start off by cloning the repo containing my code here. You can clone the repo like so git clone https://github.com/Pasqua101/txt-to-HTML-converter.

  2. Go into the newly created directory cd txt-to-HTML-converter and make sure you have python 3 installed by typing python --version into your command line. If you aren't running python 3 you can download it from here.

  3. Then provide the tool with an input txt file or directory have it converted to an HTML file. python txt_to_html.py filename.txt or foldername.

  4. Check the output folder for your newly converted files! By default the converted files will be placed in the til folder in your current working directory. You can change the output path, but I'll mention that in the features part of the post. Warning: this tool is designed to delete and recreate your output directory if it already exists. If you are using the same output directory, make sure you back up any files you may not want to lose.

Features

  1. Version Information: Typing in python txt_to_html.py -v or --version tells you what version of the tool you're currently running. As of writing this, the program is on version 0.1.

  2. Help Messages: Typing in python txt_to_html.py -h or --help brings up a help message telling you about the different arguments you can provide to the tool. It also shows a brief description and example of the tool, so you don't always have to refer back to this blog post or the repo.

  3. Stylesheets: You can customize the look of your generated html file with a stylesheet. Use the -s or --stylesheet argument followed by the link to your stylesheet. For example txt_to_html -s https://cdnjs.cloudflare.com/ajax/libs/tufte-css/1.8.0/tufte.min.css filename.txt

  4. Changing the Default Output Directory: Using the -o or --output argument followed by the directory name will allow you to change the output directory from the default til directory. You can use it like so txt_to_html -o .\foldername filename.txt. Please be aware of the warning I issued earlier, in case you use the same output folder again.

  5. HTML Generation: As mentioned earlier, this tool allows you to convert your txt files to HTML. It can either take in a single txt file or several txt files from a folder. If you use the latter, the tool will generate a HTML file for each txt file in the directory and give it a title based on the name of the file. This feature is also available for converting a single txt file.

Closing Off

Thanks to everyone who stuck around this far to read about my first open source project. If you're interested in trying it, you can get it from my repo. If you do use it, feel free to modify it to fit your needs or leave issue reports if you discover any issues. Thanks again and see you in the next post!

Top comments (0)