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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// Released under the MIT License.
// Copyright, 2026, by Samuel Williams.
#[cfg(feature = "serde")]
use core::fmt;
/// Alignment of phrasing content.
///
/// Used to align the contents of table cells within a table.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum AlignKind {
/// Left alignment.
///
/// See the `left` value of the `text-align` CSS property.
///
/// ```markdown
/// | | aaa |
/// > | | :-- |
/// ^^^
/// ```
Left,
/// Right alignment.
///
/// See the `right` value of the `text-align` CSS property.
///
/// ```markdown
/// | | aaa |
/// > | | --: |
/// ^^^
/// ```
Right,
/// Center alignment.
///
/// See the `center` value of the `text-align` CSS property.
///
/// ```markdown
/// | | aaa |
/// > | | :-: |
/// ^^^
/// ```
Center,
/// No alignment.
///
/// Phrasing content is aligned as defined by the host environment.
///
/// ```markdown
/// | | aaa |
/// > | | --- |
/// ^^^
/// ```
None,
}
/// Implement serde according to <https://github.com/syntax-tree/mdast#aligntype>
#[cfg(feature = "serde")]
impl serde::ser::Serialize for AlignKind {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::ser::Serializer,
{
match self {
AlignKind::Left => serializer.serialize_unit_variant("AlignKind", 0, "left"),
AlignKind::Right => serializer.serialize_unit_variant("AlignKind", 1, "right"),
AlignKind::Center => serializer.serialize_unit_variant("AlignKind", 2, "center"),
AlignKind::None => serializer.serialize_none(),
}
}
}
#[cfg(feature = "serde")]
struct AlignKindVisitor;
#[cfg(feature = "serde")]
impl serde::de::Visitor<'_> for AlignKindVisitor {
type Value = AlignKind;
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str("'left', 'right', 'center' or null")
}
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
where
E: serde::de::Error,
{
match v {
"left" => Ok(AlignKind::Left),
"right" => Ok(AlignKind::Right),
"center" => Ok(AlignKind::Center),
&_ => Err(serde::de::Error::invalid_type(
serde::de::Unexpected::Str(v),
&self,
)),
}
}
fn visit_bytes<E>(self, v: &[u8]) -> Result<Self::Value, E>
where
E: serde::de::Error,
{
match v {
b"left" => Ok(AlignKind::Left),
b"right" => Ok(AlignKind::Right),
b"center" => Ok(AlignKind::Center),
&_ => Err(serde::de::Error::invalid_type(
serde::de::Unexpected::Bytes(v),
&self,
)),
}
}
fn visit_none<E>(self) -> Result<Self::Value, E>
where
E: serde::de::Error,
{
Ok(AlignKind::None)
}
fn visit_unit<E>(self) -> Result<Self::Value, E>
where
E: serde::de::Error,
{
Ok(AlignKind::None)
}
}
#[cfg(feature = "serde")]
impl<'de> serde::de::Deserialize<'de> for AlignKind {
fn deserialize<D>(deserializer: D) -> Result<AlignKind, D::Error>
where
D: serde::de::Deserializer<'de>,
{
deserializer.deserialize_any(AlignKindVisitor)
}
}