67 lines
1.5 KiB
Rust
67 lines
1.5 KiB
Rust
|
|
//! Link-related AST nodes and supporting types.
|
||
|
|
//!
|
||
|
|
//! See SPEC.md §6.4. All nodes here are inline (`InlineNode` variants);
|
||
|
|
//! they live in their own module because the link model has enough surface
|
||
|
|
//! area (kinds, anchors, interwiki indirection) to warrant separation.
|
||
|
|
|
||
|
|
use std::collections::HashMap;
|
||
|
|
|
||
|
|
use super::inline::InlineNode;
|
||
|
|
use super::span::Span;
|
||
|
|
|
||
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||
|
|
pub enum LinkKind {
|
||
|
|
Wiki,
|
||
|
|
Interwiki,
|
||
|
|
Diary,
|
||
|
|
File,
|
||
|
|
Local,
|
||
|
|
Raw,
|
||
|
|
AnchorOnly,
|
||
|
|
}
|
||
|
|
|
||
|
|
#[derive(Debug, Clone, Default, PartialEq, Eq, Hash)]
|
||
|
|
pub struct LinkTarget {
|
||
|
|
pub kind: LinkKind,
|
||
|
|
pub path: Option<String>,
|
||
|
|
pub wiki_index: Option<usize>,
|
||
|
|
pub wiki_name: Option<String>,
|
||
|
|
pub anchor: Option<String>,
|
||
|
|
pub is_absolute: bool,
|
||
|
|
pub is_directory: bool,
|
||
|
|
}
|
||
|
|
|
||
|
|
impl Default for LinkKind {
|
||
|
|
fn default() -> Self {
|
||
|
|
Self::Wiki
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||
|
|
pub struct WikiLinkNode {
|
||
|
|
pub span: Span,
|
||
|
|
pub target: LinkTarget,
|
||
|
|
pub description: Option<Vec<InlineNode>>,
|
||
|
|
}
|
||
|
|
|
||
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||
|
|
pub struct ExternalLinkNode {
|
||
|
|
pub span: Span,
|
||
|
|
pub url: String,
|
||
|
|
pub description: Option<Vec<InlineNode>>,
|
||
|
|
}
|
||
|
|
|
||
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||
|
|
pub struct TransclusionNode {
|
||
|
|
pub span: Span,
|
||
|
|
pub url: String,
|
||
|
|
pub alt: Option<String>,
|
||
|
|
pub attrs: HashMap<String, String>,
|
||
|
|
}
|
||
|
|
|
||
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||
|
|
pub struct RawUrlNode {
|
||
|
|
pub span: Span,
|
||
|
|
pub url: String,
|
||
|
|
}
|