org_rust_parser/element/
paragraph.rs1use crate::Expr;
2use crate::node_pool::NodeID;
3use crate::parse::parse_object;
4use crate::types::{Cursor, ParseOpts, Parseable, Parser, Result};
5
6#[derive(Debug, Clone)]
7pub struct Paragraph(pub Vec<NodeID>);
8
9impl<'a> Parseable<'a> for Paragraph {
10 fn parse(
11 parser: &mut Parser<'a>,
12 mut cursor: Cursor<'a>,
13 parent: Option<NodeID>,
14 mut parse_opts: ParseOpts,
15 ) -> Result<NodeID> {
16 let start = cursor.index;
17 let mut content_vec: Vec<NodeID> = Vec::new();
18 parse_opts.from_paragraph = true;
19
20 let new_id = parser.pool.reserve_id();
22
23 while let Ok(id) = parse_object(parser, cursor, Some(new_id), parse_opts) {
24 cursor.index = parser.pool[id].end;
25 content_vec.push(id);
26 }
27
28 Ok(parser.alloc_with_id(
29 Paragraph(content_vec),
30 start,
31 cursor.index + 1, parent,
33 new_id,
34 ))
35 }
36}
37
38impl Paragraph {
39 pub fn is_image(&self, parser: &Parser) -> bool {
40 if let [id] = self.0[..]
41 && let Expr::RegularLink(link) = &parser.pool[id].obj
42 {
43 return link.is_image(parser);
44 }
45 false
46 }
47}