Custom Markup Language written in Rust.
cargo run -- --input <path/to/input.wg> --output <path/to/output.html> [--style <path/to/style.css>]
I wanted to make a blogging website, and I thought building a custom language that I can write the blogs with would be an interesting experience. I come from C++, and I know the frustrations involved in developing C++ applications. Unlike what many touted as Rust's defining features such as type safety or the borrow checker, I found cargo
, rust's package manager, to be the most useful one. The former were nice to haves but they can be easily achieved in C++ with good practices, while external libraries is a huge pain in C++, especially with the necessity of build tools such as make
or cmake
. In the end, I found writing code in rust to be a very rewarding experience.
The syntax is a breed between markdown and latex(more of markdown). Here's a table of syntax:
Name | Syntax | Example Output |
---|---|---|
Section Heading | @ Hello, World! | 1 Hello, World |
Subsection Heading | @@ About Me | 2.1 About Me |
Subsubsection Heading | @@@ Info | 1.1.3 Info |
List | - Apple | |
Sublist | -- Second Level Item | |
Blockquote | > Hello! -Me | |
Code Block | $$$ lines_of_code_here $$$ | |
Table | Same as markdown | The first row is automatically treated as header |
Image | #[caption](link) | |
Button | #![text](link) | |
Styles | *bold* /Italics/ $ code$ _underline_ ~strikethrough~ ![link-name](link) |
The screenshots show how the code looks and how the generated html looks. The default html codegen doesn't have any styles, this is just one example styling. The styling is extremely simple and you need to modify very few selectors.
I've written and rewritten this parser multiple times now. After multiple attempts at manually writing a lexer, I've come to realize that doing all that with regex would reduce my headache by about 10 times.
The parser itself doesn't use regex.
The whole thing is pretty small (~2000 sloc) including the tests, which occupy the most sloc anyway. It's extremely fast being written in rust and all, and this has been a good learning experience for me, learning both about simple languages and rust.
I'll be uploading this as a crate soon, so look out for that. In the mean time, you can just clone this repo.
To convert a document manually when you clone this repo, you'll need to follow these steps:
Use the Document
struct to construct a document object with the from
function. This takes in the path of the .wg
file and the path to an optional css
file. Use the convert_to_html
method - this should return a string containing the html contents.