lib: raw blocks
This commit is contained in:
parent
b3896908a3
commit
5f9a72545b
1 changed files with 22 additions and 8 deletions
30
src/lib.rs
30
src/lib.rs
|
@ -234,13 +234,21 @@ pub enum Atom {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'s> Container<'s> {
|
impl<'s> Container<'s> {
|
||||||
fn from_leaf_block(content: &str, l: block::Leaf) -> Self {
|
fn from_leaf_block(content: &'s str, l: block::Leaf) -> Self {
|
||||||
match l {
|
match l {
|
||||||
block::Leaf::Paragraph => Self::Paragraph,
|
block::Leaf::Paragraph => Self::Paragraph,
|
||||||
block::Leaf::Heading => Self::Heading {
|
block::Leaf::Heading => Self::Heading {
|
||||||
level: content.len(),
|
level: content.len(),
|
||||||
},
|
},
|
||||||
block::Leaf::CodeBlock => panic!(),
|
block::Leaf::CodeBlock => {
|
||||||
|
if let Some(format) = content.strip_prefix('=') {
|
||||||
|
Self::RawBlock { format }
|
||||||
|
} else {
|
||||||
|
Self::CodeBlock {
|
||||||
|
lang: (!content.is_empty()).then(|| content),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
_ => todo!(),
|
_ => todo!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -373,12 +381,7 @@ impl<'s> Parser<'s> {
|
||||||
block::Node::Leaf(l) => {
|
block::Node::Leaf(l) => {
|
||||||
self.inlines.set_spans(self.tree.inlines());
|
self.inlines.set_spans(self.tree.inlines());
|
||||||
self.inline_parser = Some(inline::Parser::new(self.inlines.chars()));
|
self.inline_parser = Some(inline::Parser::new(self.inlines.chars()));
|
||||||
let container = match l {
|
let container = Container::from_leaf_block(content, l);
|
||||||
block::Leaf::CodeBlock { .. } => Container::CodeBlock {
|
|
||||||
lang: (!ev.span.is_empty()).then(|| content),
|
|
||||||
},
|
|
||||||
_ => Container::from_leaf_block(content, l),
|
|
||||||
};
|
|
||||||
Event::Start(container, attributes)
|
Event::Start(container, attributes)
|
||||||
}
|
}
|
||||||
block::Node::Container(c) => {
|
block::Node::Container(c) => {
|
||||||
|
@ -561,6 +564,17 @@ mod test {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn raw_block() {
|
||||||
|
test_parse!(
|
||||||
|
"``` =html\n<table>\n```",
|
||||||
|
Start(RawBlock { format: "html" }, Attributes::new()),
|
||||||
|
Str("<table>".into()),
|
||||||
|
Atom(Softbreak),
|
||||||
|
End(RawBlock { format: "html" }),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn link_inline() {
|
fn link_inline() {
|
||||||
test_parse!(
|
test_parse!(
|
||||||
|
|
Loading…
Reference in a new issue