diff --git a/.gitignore b/.gitignore
index 53eaa21..4ae822d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
/target
**/*.rs.bk
+.idea
\ No newline at end of file
diff --git a/.idea/.gitignore b/.idea/.gitignore
deleted file mode 100644
index 73f69e0..0000000
--- a/.idea/.gitignore
+++ /dev/null
@@ -1,8 +0,0 @@
-# Default ignored files
-/shelf/
-/workspace.xml
-# Datasource local storage ignored files
-/dataSources/
-/dataSources.local.xml
-# Editor-based HTTP Client requests
-/httpRequests/
diff --git a/.idea/dictionaries/trivernis.xml b/.idea/dictionaries/trivernis.xml
deleted file mode 100644
index 03c99f1..0000000
--- a/.idea/dictionaries/trivernis.xml
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
-
- striked
-
-
-
\ No newline at end of file
diff --git a/.idea/markdown-rs.iml b/.idea/markdown-rs.iml
deleted file mode 100644
index c254557..0000000
--- a/.idea/markdown-rs.iml
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
deleted file mode 100644
index 28a804d..0000000
--- a/.idea/misc.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
deleted file mode 100644
index 87cca7f..0000000
--- a/.idea/modules.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
deleted file mode 100644
index 94a25f7..0000000
--- a/.idea/vcs.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/parser.rs b/src/parser.rs
index 447f875..c581aca 100644
--- a/src/parser.rs
+++ b/src/parser.rs
@@ -44,6 +44,16 @@ impl Parser {
}
}
+ pub fn seek_whitespace(&mut self) {
+ if self.current_char.is_whitespace() {
+ while let Some(next_char) = self.next_char() {
+ if !next_char.is_whitespace() {
+ break;
+ }
+ }
+ }
+ }
+
pub fn parse(&mut self) {
let mut document = Document::new();
while self.index < self.text.len() {
@@ -73,6 +83,7 @@ impl Parser {
}
}
+ /// Parses a section that consists of a header and one or more blocks
pub fn parse_section(&mut self) -> Result {
let start_index = self.index;
if self.current_char == '#' {
@@ -89,7 +100,7 @@ impl Parser {
self.revert_to(start_index)?;
return Err(ParseError::new(index));
}
- let _ = self.next_char();
+ self.seek_whitespace();
let mut header = self.parse_header()?;
header.size = size;
self.section_nesting = size;
@@ -106,7 +117,16 @@ impl Parser {
}
pub fn parse_paragraph(&mut self) -> Result {
- unimplemented!()
+ let mut paragraph = Paragraph::new();
+ while let Ok(token) = self.parse_inline() {
+ paragraph.add_element(token);
+ }
+
+ if paragraph.elements.len() > 0 {
+ Ok(paragraph)
+ } else {
+ Err(ParseError::new(self.index))
+ }
}
pub fn parse_list(&mut self) -> Result {
@@ -120,10 +140,18 @@ impl Parser {
pub fn parse_header(&mut self) -> Result {
Ok(Header {
size: 0,
- text: self.parse_text()?,
+ line: self.parse_inline()?,
})
}
+ pub fn parse_list_item(&mut self) -> Result {
+ unimplemented!()
+ }
+
+ pub fn parse_inline(&mut self) -> Result {
+ unimplemented!()
+ }
+
pub fn parse_text(&mut self) -> Result {
unimplemented!()
}
diff --git a/src/tokens.rs b/src/tokens.rs
index ad01649..1b7b44a 100644
--- a/src/tokens.rs
+++ b/src/tokens.rs
@@ -1,3 +1,5 @@
+use std::ops::Sub;
+
pub enum Block {
Section(Section),
Paragraph(Paragraph),
@@ -7,7 +9,6 @@ pub enum Block {
pub enum Inline {
Text(Text),
- Code(Code),
}
pub struct Document {
@@ -20,8 +21,8 @@ pub struct Section {
}
pub struct Header {
- pub(crate) size: u8,
- pub(crate) text: Text,
+ pub size: u8,
+ pub line: Inline,
}
pub struct BlockQuote {
@@ -29,16 +30,16 @@ pub struct BlockQuote {
}
pub struct Paragraph {
- elements: Vec,
+ pub elements: Vec,
}
pub struct List {
- ordered: bool,
- items: Vec,
+ pub ordered: bool,
+ pub items: Vec,
}
pub struct ListItem {
- text: Vec,
+ text: Inline,
}
pub struct Table {
@@ -51,7 +52,7 @@ pub struct Row {
}
pub struct Cell {
- text: Vec,
+ text: Inline,
}
pub struct CodeBlock {
@@ -64,13 +65,38 @@ pub struct Code {
}
pub struct Text {
- bold: bool,
- italic: bool,
- underlined: bool,
- striked: bool,
+ subtext: Vec,
+}
+
+pub enum SubText {
+ Plain(PlainText),
+ Code(Code),
+ Bold(BoldText),
+ Italic(ItalicText),
+ Underlined(UnderlinedText),
+ Striked(StrikedText),
+}
+
+pub struct PlainText {
value: String,
}
+pub struct BoldText {
+ value: Box,
+}
+
+pub struct ItalicText {
+ value: Box,
+}
+
+pub struct UnderlinedText {
+ value: Box,
+}
+
+pub struct StrikedText {
+ value: Box,
+}
+
impl Document {
pub fn new() -> Self {
Self {
@@ -95,3 +121,30 @@ impl Section {
self.elements.push(element)
}
}
+
+impl Paragraph {
+ pub fn new() -> Self {
+ Self {
+ elements: Vec::new(),
+ }
+ }
+
+ pub fn add_element(&mut self, element: Inline) {
+ self.elements.push(element)
+ }
+}
+
+impl List {
+ pub fn new() -> Self {
+ Self {
+ ordered: false,
+ items: Vec::new(),
+ }
+ }
+
+ pub fn add_item(&mut self, item: ListItem) {
+ self.items.push(item)
+ }
+}
+
+// TODO: Images, URIs