From d862b84ce868353e3482b380d0b68495de12eb6b Mon Sep 17 00:00:00 2001 From: Aaditya Dhruv Date: Sun, 10 Aug 2025 22:10:11 -0500 Subject: Add Parser support - Parser is able to take Lexer tokens and generate AST with Text (Paragraph) and Headings - Scanner has been renamed to Lexer - main.rs has been updated to use the Lexer and Parser --- src/types/elements.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/types/elements.rs') diff --git a/src/types/elements.rs b/src/types/elements.rs index 0f766e4..3e81b9a 100644 --- a/src/types/elements.rs +++ b/src/types/elements.rs @@ -35,8 +35,8 @@ pub struct Paragraph { } impl Paragraph { - pub fn new() -> Self { - Paragraph { text: String::new() } + pub fn new(text: String) -> Self { + Paragraph { text: text } } } impl Renderable for Paragraph { @@ -80,8 +80,8 @@ pub struct Heading { } impl Heading { - pub fn new() -> Self { - Heading { text: String::new(), level: 1 } + pub fn new(text: String, level: u8) -> Self { + Heading { text: text, level: level } } } impl Renderable for Heading { @@ -99,7 +99,7 @@ impl Renderable for Heading { // Heading pub struct HTML { - items: Vec>, + pub items: Vec>, } impl HTML { @@ -111,13 +111,14 @@ impl HTML { impl Renderable for HTML { fn render(&self) -> String { let mut master = String::new(); - let start_tag = ""; + let start_tag = "\n"; let end_tag = ""; master.push_str(&start_tag); for child in &self.items { let text = child.render(); master.push_str(text.as_str()); + master.push_str("\n"); } master.push_str(&end_tag); master -- cgit