textlane-core 0.6.0

Textlane's core: unist, mdast, hast and nlcst trees, the file and the plugin contract its crates share
Documentation
use crate::models::position::UnistPosition;

/// The document a pipeline processes: where it came from and what plugins reported about it.
#[derive(Clone, Debug, Default)]
pub struct File {
    pub path: Option<String>,
    /// The text the tree was parsed from, which byte spans point into.
    pub value: Option<String>,
    pub messages: Vec<Message>,
    /// What plugins store for whoever reads the result, as vfile's `data` holds it.
    pub data: serde_json::Map<String, serde_json::Value>,
}

/// A diagnostic a plugin reported, as vfile-message does.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Message {
    pub reason: String,
    pub source: Option<String>,
    pub rule: Option<String>,
    /// Where in the file the message is about.
    pub place: Option<UnistPosition>,
}

impl File {
    pub fn new() -> Self {
        Self::default()
    }

    /// Record a warning against the file.
    pub fn warn(&mut self, reason: impl Into<String>, rule: Option<&str>) {
        self.messages.push(Message {
            reason: reason.into(),
            source: None,
            rule: rule.map(str::to_string),
            place: None,
        });
    }
}