diff options
author | Aaditya Dhruv <[email protected]> | 2025-08-10 22:10:11 -0500 |
---|---|---|
committer | Aaditya Dhruv <[email protected]> | 2025-08-10 22:10:11 -0500 |
commit | d862b84ce868353e3482b380d0b68495de12eb6b (patch) | |
tree | d114c4b44460b9d1eaf689ea2ffed10c21943ecc /src/types/elements.rs | |
parent | 63dbc54db1c33e341f2e843a6c71807e51a4dd7b (diff) |
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
Diffstat (limited to 'src/types/elements.rs')
-rw-r--r-- | src/types/elements.rs | 13 |
1 files changed, 7 insertions, 6 deletions
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<Box<dyn Renderable>>, + pub items: Vec<Box<dyn Renderable>>, } impl HTML { @@ -111,13 +111,14 @@ impl HTML { impl Renderable for HTML { fn render(&self) -> String { let mut master = String::new(); - let start_tag = "<html>"; + let start_tag = "<html>\n"; let end_tag = "</html>"; 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 |