txt2html

Converts plaintext to HTML
git clone git://src.gearsix.net/txt2html
Log | Files | Refs | Atom | README

commit d76c269e2fc5b1567b0c9932c45a8ddc22c5a7aa
parent 811e7c2dfdcad5cf5c59ad0566435da8011f739a
Author: gearsix <gearsix@tuta.io>
Date:   Thu, 19 Aug 2021 00:21:10 +0100

updated README; added items to BUGS

Diffstat:
MBUGS | 2++
MREADME | 42+++++++++++++++++++++++++++++++++++++++---
Mtxt2html.c | 2+-
3 files changed, 42 insertions(+), 4 deletions(-)

diff --git a/BUGS b/BUGS @@ -1,3 +1,5 @@ +5. [ ] PRE tags don't seem to be working correctly +4. [ ] lists with sub-items aren't parsed properly (e.g. `1.a.`) 3. [*] binaries compiled with musl don't work as intended (no reason for this to be compiler-bound) 2. [*] there are a few memory leaks to fix (see valgrind output) 1. [*] for some reason the first <ol> in test.txt is parsed as a single <li>. diff --git a/README b/README @@ -3,11 +3,47 @@ txt2html ======== txt2html is a tool for converting text files to HTML. +Written as a exercise in writing a simple syntax parser. -The goal is to be simple and not to create set of syntax rules for another markup language but take conventions commonly found in .txt files and convert them to HTML. +The goal is to be simple and not to create set of syntax rules for another markup language - just to take conventions commonly found in .txt files and convert them to HTML. Which has just resulted in a subset of Markdown anyway. -You could probably use a cmark (https://github.com/commonmark/cmark) or another markdown parser to achieve the same goal but this was written as an educational project in writing an AST in C. +If you're looking for a good tool that does the same job, I'd recommend cmark (https://github.com/commonmark/cmark). + +usage +----- + + usage: txt2html [OPTIONS] FILE... + + Convert content in txt files to html. + + FILE... A list of 1 filepaths that point to files to be converted to HTML + + OPTIONS + -br Treat newlines within paragraphs as line breaks. + -v Print verbose logs during runtime + -h, --help Print this message + +syntax +------ + +The following rules from Markdown are followed: + +- Paragraphs +- Heading 1 +- Heading 2 +- Ordered lists +- Unordered lists (using `*` and `-`) +- Pre blocks (only indented blocks) + +notes +----- + +- I made a point to avoid using recursion (which is typically how ast trees are built). +Partly as a challenge and partly because I thought I could get away without it. +- There could probably be a fair bit of cleanup but I've been checking the tool against Valgrind (both compiled with gcc and musl) to avoid memory leaks and other issues. authors ------- -- gearsix + +- gearsix (gearsix@tuta.io) + diff --git a/txt2html.c b/txt2html.c @@ -44,7 +44,7 @@ void help() puts(""); puts("Convert content in txt files to html."); puts(""); - puts("FILE... A list of 1 filepaths that point to files to be converted to HTML"); + puts("FILE... A list of filepaths that point to files to be converted to HTML"); puts(""); puts("OPTIONS"); puts("-br Treat newlines within paragraphs as line breaks.");