1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
mod hyper_link;
mod image_link;
mod other;
mod rd;
mod reference;
mod two_way;
pub use self::{
hyper_link::{HyperLink, HyperLinkTarget},
image_link::{ImageLayout, ImageLink},
other::EmailLink,
rd::ResourceDescriptor,
reference::TagReference,
two_way::TwoWayLink,
};
use super::*;
/// 智能链接是指类似 `[ ]` 以及 `[[ ]]` 的结构
#[derive(Clone, Eq, PartialEq, Hash)]
pub enum SmartLink {
///
/// - `[<RD>]`: Resource Descriptor
///
/// ```note
/// [./relative-path]: 使用相对路径
/// [file://]: 使用绝对路径
/// [https://]: 使用远程 url 路径
/// [id/path]: 使用默认储存库
/// [@storage/id/path]: 使用具体的某个储存库
/// ```
ExternalResource(Box<ResourceDescriptor>),
/// ```note
/// [name@example.com](options)
/// ```
EMail(Box<EmailLink>),
/// ```note
/// [<RD>](options)
/// [describe][<RD>](options)
/// ```
Normal(Box<HyperLink>),
/// ```note
/// [<RD>](options)
/// [!image-alt][<RD>](opts)
/// ```
Image(Box<ImageLink>),
/// ## Tag Definition Block
/// ```note
/// [^tag-define]:
/// text text text
/// text text text
/// ```
/// ## Tag Reference Inline
/// ```note
/// [<RD>](opts)
/// [^tag-name](options)
/// [^tag-name][<RD>](opts)
/// ```
Reference(Box<TagReference>),
/// ```note
/// [[<RD>](options)]
/// [[text][<RD>](opts)]
/// ```
TwoWay(Box<TwoWayLink>),
}
impl ASTKind {
/// Constructor for [`ImageLink`]
#[inline]
pub fn image_link(src: impl Into<String>, range: MaybeRanged) -> ASTNode {
ImageLink { source: src.into(), ..Default::default() }.into_node(range)
}
/// Constructor for [`ImageLink`]
#[inline]
pub fn image_link_alt(src: impl Into<String>, alt: impl Into<String>, range: MaybeRanged) -> ASTNode {
ImageLink { source: src.into(), description: Some(alt.into()), ..Default::default() }.into_node(range)
}
/// Constructor for [`HyperLink`]
#[inline]
pub fn hyper_link(src: impl Into<String>, range: MaybeRanged) -> ASTNode {
HyperLink { src: src.into(), is_bare: false, ..Default::default() }.into_node(range)
}
/// Constructor for [`HyperLink`]
#[inline]
pub fn hyper_link_text(src: impl Into<String>, text: impl Into<String>, range: MaybeRanged) -> ASTNode {
HyperLink { src: src.into(), is_bare: false, text: Some(text.into()), ..Default::default() }.into_node(range)
}
/// Constructor for [`HyperLink`]
#[inline]
pub fn bare_link(src: impl Into<String>, range: MaybeRanged) -> ASTNode {
HyperLink { src: src.into(), is_bare: true, ..Default::default() }.into_node(range)
}
}