-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9129622
commit d8aa80a
Showing
7 changed files
with
231 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
use crate::{Serialize, SerializeOptions, TimeDesignation, XmlWriter}; | ||
|
||
#[derive(Default, Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] | ||
pub enum BreakStrength { | ||
None, | ||
ExtraWeak, | ||
Weak, | ||
#[default] | ||
Medium, | ||
Strong, | ||
ExtraStrong | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
pub enum Break { | ||
Strength(BreakStrength), | ||
Time(TimeDesignation) | ||
} | ||
|
||
impl Break { | ||
pub fn new_with_strength(strength: BreakStrength) -> Self { | ||
Break::Strength(strength) | ||
} | ||
|
||
pub fn new_with_time(time: impl Into<TimeDesignation>) -> Self { | ||
Break::Time(time.into()) | ||
} | ||
} | ||
|
||
impl From<BreakStrength> for Break { | ||
fn from(value: BreakStrength) -> Self { | ||
Break::new_with_strength(value) | ||
} | ||
} | ||
|
||
impl<S> From<S> for Break | ||
where | ||
S: Into<TimeDesignation> | ||
{ | ||
fn from(value: S) -> Self { | ||
Break::new_with_time(value) | ||
} | ||
} | ||
|
||
impl Serialize for Break { | ||
fn serialize_xml(&self, writer: &mut XmlWriter<'_>, _: &SerializeOptions) -> crate::Result<()> { | ||
writer.element("break", |writer| match self { | ||
Break::Strength(strength) => writer.attr( | ||
"strength", | ||
match strength { | ||
BreakStrength::None => "none", | ||
BreakStrength::ExtraWeak => "x-weak", | ||
BreakStrength::Weak => "weak", | ||
BreakStrength::Medium => "medium", | ||
BreakStrength::Strong => "strong", | ||
BreakStrength::ExtraStrong => "x-strong" | ||
} | ||
), | ||
Break::Time(time) => writer.attr("time", time.to_string()) | ||
}) | ||
} | ||
} | ||
|
||
pub fn breaks(value: impl Into<Break>) -> Break { | ||
value.into() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
use crate::{Element, Serialize, SerializeOptions, XmlWriter}; | ||
|
||
#[derive(Default, Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] | ||
pub enum EmphasisLevel { | ||
Reduced, | ||
None, | ||
#[default] | ||
Moderate, | ||
Strong | ||
} | ||
|
||
#[derive(Clone, Default, Debug)] | ||
pub struct Emphasis { | ||
level: EmphasisLevel, | ||
pub(crate) children: Vec<Element> | ||
} | ||
|
||
impl Emphasis { | ||
pub fn new<S: Into<Element>, I: IntoIterator<Item = S>>(level: EmphasisLevel, elements: I) -> Self { | ||
Self { | ||
level, | ||
children: elements.into_iter().map(|f| f.into()).collect() | ||
} | ||
} | ||
|
||
pub fn push(&mut self, element: impl Into<Element>) { | ||
self.children.push(element.into()); | ||
} | ||
|
||
pub fn extend<S: Into<Element>, I: IntoIterator<Item = S>>(&mut self, elements: I) { | ||
self.children.extend(elements.into_iter().map(|f| f.into())); | ||
} | ||
|
||
pub fn level(&self) -> &EmphasisLevel { | ||
&self.level | ||
} | ||
|
||
pub fn children(&self) -> &[Element] { | ||
&self.children | ||
} | ||
|
||
pub fn children_mut(&mut self) -> &mut [Element] { | ||
&mut self.children | ||
} | ||
} | ||
|
||
impl Serialize for Emphasis { | ||
fn serialize_xml(&self, writer: &mut XmlWriter<'_>, _: &SerializeOptions) -> crate::Result<()> { | ||
writer.element("emphasis", |writer| { | ||
writer.attr( | ||
"level", | ||
match self.level { | ||
EmphasisLevel::Reduced => "reduced", | ||
EmphasisLevel::None => "none", | ||
EmphasisLevel::Moderate => "moderate", | ||
EmphasisLevel::Strong => "strong" | ||
} | ||
) | ||
}) | ||
} | ||
} | ||
|
||
pub fn emphasis<S: Into<Element>, I: IntoIterator<Item = S>>(level: EmphasisLevel, elements: I) -> Emphasis { | ||
Emphasis::new(level, elements) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use crate::{Serialize, SerializeOptions, XmlWriter}; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct Mark { | ||
name: String | ||
} | ||
|
||
impl Mark { | ||
pub fn new(name: impl ToString) -> Self { | ||
Self { name: name.to_string() } | ||
} | ||
|
||
pub fn name(&self) -> &str { | ||
&self.name | ||
} | ||
} | ||
|
||
impl Serialize for Mark { | ||
fn serialize_xml(&self, writer: &mut XmlWriter<'_>, _: &SerializeOptions) -> crate::Result<()> { | ||
writer.element("mark", |writer| writer.attr("name", &self.name)) | ||
} | ||
} | ||
|
||
pub fn mark(name: impl ToString) -> Mark { | ||
Mark::new(name) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters