Skip to content

Latest commit

 

History

History
107 lines (63 loc) · 7.05 KB

README.md

File metadata and controls

107 lines (63 loc) · 7.05 KB

waygum

Custom Markup Language written in Rust.

How to run?

cargo run -- --input <path/to/input.wg> --output <path/to/output.html> [--style <path/to/style.css>]

Why?

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.

Syntax

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)

Screenshots

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.

Section Heading

Screenshot 2022-12-29 at 12 07 31 PM

Screenshot 2022-12-29 at 12 07 38 PM


Subsection with Text Snippet (they're auto numbered)

Screenshot 2022-12-29 at 12 07 48 PM

Screenshot 2022-12-29 at 12 07 55 PM


Quote with Inline Styling

Screenshot 2022-12-29 at 12 08 03 PM

Screenshot 2022-12-29 at 12 08 07 PM


Image with caption

Screenshot 2022-12-29 at 12 08 22 PM

Screenshot 2022-12-29 at 12 08 28 PM


Multilevel List

Screenshot 2022-12-29 at 12 09 00 PM

Screenshot 2022-12-29 at 12 09 07 PM


Codeblocks

Screenshot 2022-12-29 at 12 09 33 PM

Screenshot 2022-12-29 at 12 09 56 PM


Small Snippet with Codeblock and styles

Screenshot 2022-12-29 at 12 10 24 PM

Screenshot 2022-12-29 at 12 10 31 PM


Table (supports styling)

Screenshot 2022-12-29 at 12 10 42 PM

Screenshot 2022-12-29 at 12 10 54 PM


About

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.

How to run?

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.