Fixed blockquote

This commit is contained in:
ef3d0c3e 2024-08-25 13:19:24 +02:00
parent 46d579247b
commit 07970d2745
2 changed files with 132 additions and 120 deletions

View file

@ -103,6 +103,8 @@ impl NavEntries {
std::cmp::Ordering::Greater
} else if rp.as_str() == left_title {
std::cmp::Ordering::Less
} else if rp.as_str() == lp.as_str() {
left_title.cmp(right_title)
} else {
Self::sort_entry(entrymap, lp.as_str(), rp.as_str())
}

View file

@ -76,7 +76,12 @@ impl Element for Blockquote {
fn element_name(&self) -> &'static str { "Blockquote" }
fn compile(&self, compiler: &Compiler, document: &dyn Document, cursor: usize) -> Result<String, String> {
fn compile(
&self,
compiler: &Compiler,
document: &dyn Document,
cursor: usize,
) -> Result<String, String> {
match compiler.target() {
HTML => {
let mut result = r#"<div class="blockquote-content">"#.to_string();
@ -124,7 +129,9 @@ impl Element for Blockquote {
result += "<p>";
for elem in &self.content {
result += elem.compile(compiler, document, cursor+result.len())?.as_str();
result += elem
.compile(compiler, document, cursor + result.len())?
.as_str();
}
result += "</p></blockquote>";
if self.style.author_pos == After {
@ -215,7 +222,8 @@ impl Rule for BlockquoteRule {
fn next_match(&self, _state: &ParserState, cursor: &Cursor) -> Option<(usize, Box<dyn Any>)> {
self.start_re
.find_at(cursor.source.content(), cursor.pos).map(|m| (m.start(), Box::new([false; 0]) as Box<dyn Any>))
.find_at(cursor.source.content(), cursor.pos)
.map(|m| (m.start(), Box::new([false; 0]) as Box<dyn Any>))
}
fn on_match<'a>(
@ -229,10 +237,9 @@ impl Rule for BlockquoteRule {
let content = cursor.source.content();
let mut end_cursor = cursor.clone();
loop {
if let Some(captures) = self.start_re.captures_at(content, end_cursor.pos) {
if captures.get(0).unwrap().start() != end_cursor.pos {
break;
return (end_cursor, reports);
}
// Advance cursor
end_cursor = end_cursor.at(captures.get(0).unwrap().end());
@ -258,7 +265,7 @@ impl Rule for BlockquoteRule {
)
.finish(),
);
break;
return (end_cursor, reports);
}
Ok(props) => (author, cite, url) = props,
}
@ -269,6 +276,9 @@ impl Rule for BlockquoteRule {
let mut entry_content = captures.get(2).unwrap().as_str().to_string();
let mut spacing: Option<(Range<usize>, &str)> = None;
while let Some(captures) = self.continue_re.captures_at(content, end_cursor.pos) {
if captures.get(0).unwrap().start() != end_cursor.pos {
break;
}
// Advance cursor
end_cursor = end_cursor.at(captures.get(0).unwrap().end());
@ -326,7 +336,7 @@ impl Rule for BlockquoteRule {
)
.finish(),
);
break;
return (end_cursor, reports);
}
Ok(mut paragraph) => std::mem::take(&mut paragraph.content),
};
@ -343,10 +353,7 @@ impl Rule for BlockquoteRule {
state.push(
document,
Box::new(Blockquote {
location: Token::new(
entry_start..end_cursor.pos,
end_cursor.source.clone(),
),
location: Token::new(entry_start..end_cursor.pos, end_cursor.source.clone()),
content: parsed_content,
author,
cite,
@ -354,9 +361,6 @@ impl Rule for BlockquoteRule {
style,
}),
);
} else {
break;
}
}
(end_cursor, reports)
@ -426,6 +430,8 @@ BEFORE
> contin**ued here
> **
AFTER
> Another quote
END
"#
.to_string(),
None,
@ -446,6 +452,10 @@ AFTER
Style;
};
Paragraph { Text{ content == "AFTER" }; };
Blockquote {
Text { content == "Another quote" };
};
Paragraph { Text{ content == "END" }; };
);
}