Skip to main content

use_markdown/
image.rs

1use crate::link::{InlineReferenceKind, extract_inline_references};
2
3/// A Markdown inline image.
4#[derive(Clone, Debug, Eq, PartialEq)]
5pub struct MarkdownImage {
6    /// The cleaned alt text.
7    pub alt: String,
8    /// The image source.
9    pub source: String,
10    /// The optional inline title.
11    pub title: Option<String>,
12    /// The 1-based line where the image was found.
13    pub line: usize,
14}
15
16/// Extracts inline images while ignoring fenced code blocks.
17pub fn extract_images(markdown: &str) -> Vec<MarkdownImage> {
18    extract_inline_references(markdown, InlineReferenceKind::Image)
19        .into_iter()
20        .map(|reference| MarkdownImage {
21            alt: reference.label,
22            source: reference.target,
23            title: reference.title,
24            line: reference.line,
25        })
26        .collect()
27}