A Markdown-to-HTML compiler written in Ruby. This project demonstrates core concepts of compiler construction, including lexical analysis, parsing, syntax transformation, and code generation.
The compiler follows a classic pipeline:
- Lexer (Tokenizer): Scans the raw Markdown input and produces a list of tokens.
- Parser: Processes tokens into an abstract syntax tree (AST) representing the document structure.
- Code Generator: Converts the AST into the target language (HTML).
The image below shows the compiler integrated into my personal website to compile Markdown in an IDE-like UI. This code has been copied into that repo (pinned on my profile) as has since been altered to fit the needs of that project.
- Headers (
#,##, etc.) - Bold / Italic text
- Ordered and Unordered Lists
- Code Blocks
- Inline Code
- Blockquotes
- Horizontal Rules
- Links & Images
A full example of compiled output can be found in testdata/example.html.
Compiler.compile('# Hello world')
# => '<h1>Hello world</h1>'./test.sh(If needed: chmod +x test.sh to make the script executable.)
MIT