use super::{CheckOptions, CheckOutput};
use crate::{
Locator, RepoPath, Spanned,
grammar::States,
markdown::{Body, Dialect, Segments},
};
#[derive(Debug, Clone, Copy)]
pub struct DocView<'a> {
pub path: &'a RepoPath,
pub frontmatter: Option<&'a Spanned>,
pub body: &'a Body,
pub segments: &'a Segments,
pub line_count: usize,
pub text: &'a str,
pub body_line: usize,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Subject {
Text(String),
Document,
Unknown,
}
pub trait Host: tramlines_core::frontmatter::Host {
fn dialect(&self) -> Dialect;
fn image(&self, reference: &str) -> Subject;
fn region(&self, target: &str) -> Subject;
fn scaffold_front(&self, _states: &States) -> Option<ScaffoldFront> {
Some(ScaffoldFront::default())
}
fn records_accepted(&self) -> bool {
false
}
fn check(
&self,
_doc: &DocView<'_>,
_states: &States,
_options: CheckOptions,
_locator: &Locator,
_out: &mut CheckOutput,
) {
}
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct ScaffoldFront {
pub leading: Vec<(String, Option<String>)>,
pub trailing: Vec<String>,
}
#[derive(Debug, Clone, Copy, Default)]
pub struct NullHost;
impl Host for NullHost {
fn dialect(&self) -> Dialect {
Dialect::default()
}
fn image(&self, _: &str) -> Subject {
Subject::Unknown
}
fn region(&self, _: &str) -> Subject {
Subject::Unknown
}
}
impl tramlines_core::frontmatter::Host for NullHost {
fn scalar_format(&self, _: &str, _: &str) -> Option<Result<(), String>> {
None
}
fn reserved_keys(&self) -> &[&str] {
&[]
}
}