use std::fmt;
use std::ops::Range;
use std::path::Path;
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct PageId(String);
impl PageId {
pub fn from_path(path: &Path) -> Option<Self> {
path.file_stem()
.and_then(|s| s.to_str())
.map(|s| Self(s.to_ascii_lowercase()))
}
pub fn as_str(&self) -> &str {
&self.0
}
}
impl fmt::Display for PageId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.0)
}
}
impl From<&str> for PageId {
fn from(s: &str) -> Self {
Self(s.to_ascii_lowercase())
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct BlockId(String);
impl BlockId {
pub fn as_str(&self) -> &str {
&self.0
}
}
impl From<&str> for BlockId {
fn from(s: &str) -> Self {
Self(s.to_owned())
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum WikilinkFragment {
Heading(String),
Block(BlockId),
}
#[derive(Debug, Clone)]
pub struct WikilinkOccurrence {
pub page: PageId,
pub fragment: Option<WikilinkFragment>,
pub is_embed: bool,
pub byte_range: Range<usize>,
}
#[derive(Debug, Clone)]
pub struct Heading {
pub level: u8,
pub text: String,
pub byte_range: Range<usize>,
}