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
|
33
src/block.rs
33
src/block.rs
|
@ -284,7 +284,6 @@ fn lines(src: &str) -> impl Iterator<Item = Span> + '_ {
|
|||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::tree::EventKind::*;
|
||||
use crate::Span;
|
||||
|
||||
use super::Atom::*;
|
||||
use super::Block;
|
||||
|
@ -326,12 +325,12 @@ mod test {
|
|||
fn parse_heading_multi() {
|
||||
test_parse!(
|
||||
concat!(
|
||||
"# 2\n",
|
||||
"\n",
|
||||
" # 8\n",
|
||||
" 12\n",
|
||||
"15\n", //
|
||||
),
|
||||
"# 2\n",
|
||||
"\n",
|
||||
" # 8\n",
|
||||
" 12\n",
|
||||
"15\n", //
|
||||
),
|
||||
(Enter(Leaf(Heading { level: 1 })), "#"),
|
||||
(Element(Inline), "2"),
|
||||
(Exit(Leaf(Heading { level: 1 })), "#"),
|
||||
|
@ -346,6 +345,26 @@ mod test {
|
|||
|
||||
#[test]
|
||||
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!(
|
||||
concat!(
|
||||
"> 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 {
|
||||
match e {
|
||||
Event::Start(c, _attrs) => {
|
||||
if c.is_block() {
|
||||
self.out.write_char('\n')?;
|
||||
}
|
||||
match c {
|
||||
Container::Blockquote => self.out.write_str("<blockquote>")?,
|
||||
Container::List(..) => todo!(),
|
||||
|
@ -86,6 +89,9 @@ impl<'s, I: Iterator<Item = Event<'s>>, W: std::fmt::Write> Writer<I, W> {
|
|||
}
|
||||
}
|
||||
Event::End(c) => {
|
||||
if c.is_block_container() && !matches!(c, Container::Footnote { .. }) {
|
||||
self.out.write_char('\n')?;
|
||||
}
|
||||
match c {
|
||||
Container::Blockquote => self.out.write_str("</blockquote>")?,
|
||||
Container::List(..) => todo!(),
|
||||
|
|
|
@ -40,6 +40,7 @@ pub enum Delimiter {
|
|||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum Symbol {
|
||||
Ampersand,
|
||||
Asterisk,
|
||||
Caret,
|
||||
Equal,
|
||||
|
@ -162,6 +163,7 @@ impl<'s> Lexer<'s> {
|
|||
Open(Brace)
|
||||
}
|
||||
}
|
||||
'&' => self.maybe_eat_close_brace(Ampersand, BraceAsterisk),
|
||||
'*' => self.maybe_eat_close_brace(Asterisk, BraceAsterisk),
|
||||
'^' => self.maybe_eat_close_brace(Caret, BraceCaret),
|
||||
'=' => self.maybe_eat_close_brace(Equal, BraceEqual),
|
||||
|
|
70
src/lib.rs
70
src/lib.rs
|
@ -78,12 +78,78 @@ pub enum Container<'s> {
|
|||
Emphasis,
|
||||
/// A highlighted inline element.
|
||||
Mark,
|
||||
/// An quoted element, using single quotes.
|
||||
/// An quoted inline element, using single quotes.
|
||||
SingleQuoted,
|
||||
/// A quoted inline element, using double quotes.
|
||||
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)]
|
||||
pub enum LinkType {
|
||||
Inline,
|
||||
|
@ -130,7 +196,7 @@ pub enum OrderedListFormat {
|
|||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub enum Atom {
|
||||
/// An ellipsis, i.e. a set of three periods.
|
||||
/// A horizontal ellipsis, i.e. a set of three periods.
|
||||
Ellipsis,
|
||||
/// An en dash.
|
||||
EnDash,
|
||||
|
|
Loading…
Reference in a new issue