fixup! 27d710969473894b59f23ad981fc50cbd3b78977
This commit is contained in:
parent
1ce8570543
commit
78d6d502b6
5 changed files with 103 additions and 10 deletions
|
@ -1 +1 @@
|
||||||
Subproject commit 97eb7955346617da88545e38a44b81957af51651
|
Subproject commit 4b3bf26dde0fa46a5d22b536154e3634619ef3a4
|
21
src/block.rs
21
src/block.rs
|
@ -284,7 +284,6 @@ fn lines(src: &str) -> impl Iterator<Item = Span> + '_ {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use crate::tree::EventKind::*;
|
use crate::tree::EventKind::*;
|
||||||
use crate::Span;
|
|
||||||
|
|
||||||
use super::Atom::*;
|
use super::Atom::*;
|
||||||
use super::Block;
|
use super::Block;
|
||||||
|
@ -346,6 +345,26 @@ mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_blockquote() {
|
fn parse_blockquote() {
|
||||||
|
test_parse!(
|
||||||
|
"> a\n",
|
||||||
|
(Enter(Container(Blockquote)), ">"),
|
||||||
|
(Enter(Leaf(Paragraph)), ""),
|
||||||
|
(Element(Inline), "a"),
|
||||||
|
(Exit(Leaf(Paragraph)), ""),
|
||||||
|
(Exit(Container(Blockquote)), ">"),
|
||||||
|
);
|
||||||
|
test_parse!(
|
||||||
|
"> \n",
|
||||||
|
(Enter(Container(Blockquote)), ">"),
|
||||||
|
(Element(Blankline), " \n"),
|
||||||
|
(Exit(Container(Blockquote)), ">"),
|
||||||
|
);
|
||||||
|
test_parse!(
|
||||||
|
">",
|
||||||
|
(Enter(Container(Blockquote)), ">"),
|
||||||
|
(Element(Blankline), ""),
|
||||||
|
(Exit(Container(Blockquote)), ">"),
|
||||||
|
);
|
||||||
test_parse!(
|
test_parse!(
|
||||||
concat!(
|
concat!(
|
||||||
"> a\n",
|
"> a\n",
|
||||||
|
|
|
@ -56,6 +56,9 @@ impl<'s, I: Iterator<Item = Event<'s>>, W: std::fmt::Write> Writer<I, W> {
|
||||||
for e in &mut self.events {
|
for e in &mut self.events {
|
||||||
match e {
|
match e {
|
||||||
Event::Start(c, _attrs) => {
|
Event::Start(c, _attrs) => {
|
||||||
|
if c.is_block() {
|
||||||
|
self.out.write_char('\n')?;
|
||||||
|
}
|
||||||
match c {
|
match c {
|
||||||
Container::Blockquote => self.out.write_str("<blockquote>")?,
|
Container::Blockquote => self.out.write_str("<blockquote>")?,
|
||||||
Container::List(..) => todo!(),
|
Container::List(..) => todo!(),
|
||||||
|
@ -86,6 +89,9 @@ impl<'s, I: Iterator<Item = Event<'s>>, W: std::fmt::Write> Writer<I, W> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Event::End(c) => {
|
Event::End(c) => {
|
||||||
|
if c.is_block_container() && !matches!(c, Container::Footnote { .. }) {
|
||||||
|
self.out.write_char('\n')?;
|
||||||
|
}
|
||||||
match c {
|
match c {
|
||||||
Container::Blockquote => self.out.write_str("</blockquote>")?,
|
Container::Blockquote => self.out.write_str("</blockquote>")?,
|
||||||
Container::List(..) => todo!(),
|
Container::List(..) => todo!(),
|
||||||
|
|
|
@ -40,6 +40,7 @@ pub enum Delimiter {
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
pub enum Symbol {
|
pub enum Symbol {
|
||||||
|
Ampersand,
|
||||||
Asterisk,
|
Asterisk,
|
||||||
Caret,
|
Caret,
|
||||||
Equal,
|
Equal,
|
||||||
|
@ -162,6 +163,7 @@ impl<'s> Lexer<'s> {
|
||||||
Open(Brace)
|
Open(Brace)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
'&' => self.maybe_eat_close_brace(Ampersand, BraceAsterisk),
|
||||||
'*' => self.maybe_eat_close_brace(Asterisk, BraceAsterisk),
|
'*' => self.maybe_eat_close_brace(Asterisk, BraceAsterisk),
|
||||||
'^' => self.maybe_eat_close_brace(Caret, BraceCaret),
|
'^' => self.maybe_eat_close_brace(Caret, BraceCaret),
|
||||||
'=' => self.maybe_eat_close_brace(Equal, BraceEqual),
|
'=' => self.maybe_eat_close_brace(Equal, BraceEqual),
|
||||||
|
|
70
src/lib.rs
70
src/lib.rs
|
@ -78,12 +78,78 @@ pub enum Container<'s> {
|
||||||
Emphasis,
|
Emphasis,
|
||||||
/// A highlighted inline element.
|
/// A highlighted inline element.
|
||||||
Mark,
|
Mark,
|
||||||
/// An quoted element, using single quotes.
|
/// An quoted inline element, using single quotes.
|
||||||
SingleQuoted,
|
SingleQuoted,
|
||||||
/// A quoted inline element, using double quotes.
|
/// A quoted inline element, using double quotes.
|
||||||
DoubleQuoted,
|
DoubleQuoted,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'s> Container<'s> {
|
||||||
|
/// Is a block element.
|
||||||
|
fn is_block(&self) -> bool {
|
||||||
|
match self {
|
||||||
|
Self::Blockquote
|
||||||
|
| Self::List(..)
|
||||||
|
| Self::ListItem
|
||||||
|
| Self::DescriptionList
|
||||||
|
| Self::DescriptionDetails
|
||||||
|
| Self::Footnote { .. }
|
||||||
|
| Self::Table
|
||||||
|
| Self::TableRow
|
||||||
|
| Self::Div
|
||||||
|
| Self::Paragraph
|
||||||
|
| Self::Heading { .. }
|
||||||
|
| Self::TableCell
|
||||||
|
| Self::RawBlock { .. }
|
||||||
|
| Self::CodeBlock { .. } => true,
|
||||||
|
Self::Span
|
||||||
|
| Self::Link(..)
|
||||||
|
| Self::Image(..)
|
||||||
|
| Self::Subscript
|
||||||
|
| Self::Superscript
|
||||||
|
| Self::Insert
|
||||||
|
| Self::Delete
|
||||||
|
| Self::Strong
|
||||||
|
| Self::Emphasis
|
||||||
|
| Self::Mark
|
||||||
|
| Self::SingleQuoted
|
||||||
|
| Self::DoubleQuoted => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Is a block element that may contain children blocks.
|
||||||
|
fn is_block_container(&self) -> bool {
|
||||||
|
match self {
|
||||||
|
Self::Blockquote
|
||||||
|
| Self::List(..)
|
||||||
|
| Self::ListItem
|
||||||
|
| Self::DescriptionList
|
||||||
|
| Self::DescriptionDetails
|
||||||
|
| Self::Footnote { .. }
|
||||||
|
| Self::Table
|
||||||
|
| Self::TableRow
|
||||||
|
| Self::Div => true,
|
||||||
|
Self::Paragraph
|
||||||
|
| Self::Heading { .. }
|
||||||
|
| Self::TableCell
|
||||||
|
| Self::RawBlock { .. }
|
||||||
|
| Self::CodeBlock { .. }
|
||||||
|
| Self::Span
|
||||||
|
| Self::Link(..)
|
||||||
|
| Self::Image(..)
|
||||||
|
| Self::Subscript
|
||||||
|
| Self::Superscript
|
||||||
|
| Self::Insert
|
||||||
|
| Self::Delete
|
||||||
|
| Self::Strong
|
||||||
|
| Self::Emphasis
|
||||||
|
| Self::Mark
|
||||||
|
| Self::SingleQuoted
|
||||||
|
| Self::DoubleQuoted => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
pub enum LinkType {
|
pub enum LinkType {
|
||||||
Inline,
|
Inline,
|
||||||
|
@ -130,7 +196,7 @@ pub enum OrderedListFormat {
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
pub enum Atom {
|
pub enum Atom {
|
||||||
/// An ellipsis, i.e. a set of three periods.
|
/// A horizontal ellipsis, i.e. a set of three periods.
|
||||||
Ellipsis,
|
Ellipsis,
|
||||||
/// An en dash.
|
/// An en dash.
|
||||||
EnDash,
|
EnDash,
|
||||||
|
|
Loading…
Reference in a new issue