aboutsummaryrefslogtreecommitdiffstats
path: root/src/content
diff options
context:
space:
mode:
authorLibravatar Titus Wormer <tituswormer@gmail.com>2022-06-13 18:42:36 +0200
committerLibravatar Titus Wormer <tituswormer@gmail.com>2022-06-13 18:42:36 +0200
commitef644f4def7d5cad3fb5307ec5e00fc7b0b025ff (patch)
tree1d284b657d2cade8e3d4e60db09750c768bbc76f /src/content
parent06b4ff3531874c95ec07b8440de526795408ef86 (diff)
downloadmarkdown-rs-ef644f4def7d5cad3fb5307ec5e00fc7b0b025ff.tar.gz
markdown-rs-ef644f4def7d5cad3fb5307ec5e00fc7b0b025ff.tar.bz2
markdown-rs-ef644f4def7d5cad3fb5307ec5e00fc7b0b025ff.zip
Add basic html (text)
* Add all states for html (text) * Fix to link paragraph tokens together * Add note about uncovered bug where linking paragraph tokens together doesn’t work 😅
Diffstat (limited to 'src/content')
-rw-r--r--src/content/content.rs17
-rw-r--r--src/content/text.rs14
2 files changed, 22 insertions, 9 deletions
diff --git a/src/content/content.rs b/src/content/content.rs
index 7bf692f..4660fbe 100644
--- a/src/content/content.rs
+++ b/src/content/content.rs
@@ -52,7 +52,7 @@ fn paragraph_initial(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult {
_ => {
tokenizer.enter(TokenType::Paragraph);
tokenizer.enter(TokenType::ChunkText);
- data(tokenizer, code)
+ data(tokenizer, code, tokenizer.events.len() - 1)
}
}
}
@@ -63,7 +63,7 @@ fn paragraph_initial(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult {
/// |\&
/// |qwe
/// ```
-fn data(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult {
+fn data(tokenizer: &mut Tokenizer, code: Code, previous_index: usize) -> StateFnResult {
match code {
Code::None => {
tokenizer.exit(TokenType::ChunkText);
@@ -74,11 +74,20 @@ fn data(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult {
tokenizer.consume(code);
tokenizer.exit(TokenType::ChunkText);
tokenizer.enter(TokenType::ChunkText);
- (State::Fn(Box::new(data)), None)
+ let next_index = tokenizer.events.len() - 1;
+ tokenizer.events[previous_index].next = Some(next_index);
+ tokenizer.events[next_index].previous = Some(previous_index);
+ (
+ State::Fn(Box::new(move |t, c| data(t, c, next_index))),
+ None,
+ )
}
_ => {
tokenizer.consume(code);
- (State::Fn(Box::new(data)), None)
+ (
+ State::Fn(Box::new(move |t, c| data(t, c, previous_index))),
+ None,
+ )
}
}
}
diff --git a/src/content/text.rs b/src/content/text.rs
index a7b40e7..3db82f5 100644
--- a/src/content/text.rs
+++ b/src/content/text.rs
@@ -7,7 +7,7 @@
//!
//! * [Autolink][crate::construct::autolink]
//! * Attention
-//! * HTML (text)
+//! * [HTML (text)][crate::construct::html-text]
//! * Hard break escape
//! * Code (text)
//! * Line ending
@@ -18,7 +18,7 @@
use crate::construct::{
autolink::start as autolink, character_escape::start as character_escape,
- character_reference::start as character_reference,
+ character_reference::start as character_reference, html_text::start as html_text,
};
use crate::tokenizer::{Code, State, StateFnResult, TokenType, Tokenizer};
@@ -34,9 +34,13 @@ use crate::tokenizer::{Code, State, StateFnResult, TokenType, Tokenizer};
pub fn start(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult {
match code {
Code::None => (State::Ok, None),
- _ => tokenizer.attempt_3(character_reference, character_escape, autolink, |ok| {
- Box::new(if ok { start } else { before_data })
- })(tokenizer, code),
+ _ => tokenizer.attempt_4(
+ character_reference,
+ character_escape,
+ autolink,
+ html_text,
+ |ok| Box::new(if ok { start } else { before_data }),
+ )(tokenizer, code),
}
}