aboutsummaryrefslogtreecommitdiffstats
path: root/src/construct/block_quote.rs
diff options
context:
space:
mode:
authorLibravatar Titus Wormer <tituswormer@gmail.com>2022-07-07 17:21:38 +0200
committerLibravatar Titus Wormer <tituswormer@gmail.com>2022-07-07 17:36:35 +0200
commit4806864e5377a5fef937b3fa02542e620c547969 (patch)
treec91ae2bbd1dc2037f425efd24d62d05e706e3e60 /src/construct/block_quote.rs
parentc2b4402223e53498078fc33dd55aabc0a48cdb56 (diff)
downloadmarkdown-rs-4806864e5377a5fef937b3fa02542e620c547969.tar.gz
markdown-rs-4806864e5377a5fef937b3fa02542e620c547969.tar.bz2
markdown-rs-4806864e5377a5fef937b3fa02542e620c547969.zip
Add basic support for block quotes
Diffstat (limited to 'src/construct/block_quote.rs')
-rw-r--r--src/construct/block_quote.rs58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/construct/block_quote.rs b/src/construct/block_quote.rs
new file mode 100644
index 0000000..cd5b872
--- /dev/null
+++ b/src/construct/block_quote.rs
@@ -0,0 +1,58 @@
+//! To do.
+
+use crate::constant::TAB_SIZE;
+use crate::construct::partial_space_or_tab::space_or_tab_min_max;
+use crate::tokenizer::{Code, State, StateFnResult, TokenType, Tokenizer};
+
+pub fn start(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult {
+ // To do: allow arbitrary when code (indented) is turned off.
+ tokenizer.go(space_or_tab_min_max(0, TAB_SIZE - 1), before)(tokenizer, code)
+}
+
+fn before(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult {
+ match code {
+ Code::Char('>') => {
+ tokenizer.enter(TokenType::BlockQuote);
+ cont_before(tokenizer, code)
+ }
+ _ => cont_before(tokenizer, code),
+ }
+}
+
+pub fn cont(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult {
+ // To do: allow arbitrary when code (indented) is turned off.
+ tokenizer.go(space_or_tab_min_max(0, TAB_SIZE - 1), cont_before)(tokenizer, code)
+}
+
+fn cont_before(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult {
+ match code {
+ Code::Char('>') => {
+ tokenizer.enter(TokenType::BlockQuotePrefix);
+ tokenizer.enter(TokenType::BlockQuoteMarker);
+ tokenizer.consume(code);
+ tokenizer.exit(TokenType::BlockQuoteMarker);
+ (State::Fn(Box::new(cont_after)), None)
+ }
+ _ => (State::Nok, None),
+ }
+}
+
+fn cont_after(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult {
+ match code {
+ Code::VirtualSpace | Code::Char('\t' | ' ') => {
+ tokenizer.enter(TokenType::BlockQuotePrefixWhitespace);
+ tokenizer.consume(code);
+ tokenizer.exit(TokenType::BlockQuotePrefixWhitespace);
+ tokenizer.exit(TokenType::BlockQuotePrefix);
+ (State::Ok, None)
+ }
+ _ => {
+ tokenizer.exit(TokenType::BlockQuotePrefix);
+ (State::Ok, Some(vec![code]))
+ }
+ }
+}
+
+pub fn end() -> Vec<TokenType> {
+ vec![TokenType::BlockQuote]
+}