#[derive(Debug)]
pub enum AlignHorizontal {
Auto,
Left,
Right,
Center,
}
impl Default for AlignHorizontal {
fn default() -> Self {
AlignHorizontal::Auto
}
}
#[derive(Clone, Debug)]
pub enum Heading {
None,
H1,
H2,
H3,
H4,
H5,
}
impl Default for Heading {
fn default() -> Self {
Heading::None
}
}
impl From<u8> for Heading {
#[inline]
fn from(n: u8) -> Self {
match n {
0 => Heading::None,
1 => Heading::H1,
2 => Heading::H2,
3 => Heading::H3,
4 => Heading::H4,
_ => Heading::H5,
}
}
}
impl Heading {
#[inline]
pub fn to_int(&self) -> u8 {
match *self {
Heading::None => 0,
Heading::H1 => 1,
Heading::H2 => 2,
Heading::H3 => 3,
Heading::H4 => 4,
Heading::H5 => 5,
}
}
}
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub enum IndentLevel {
None,
I1,
I2,
I3,
I4,
I5,
}
impl Default for IndentLevel {
fn default() -> Self {
IndentLevel::None
}
}
impl From<u8> for IndentLevel {
#[inline]
fn from(n: u8) -> Self {
match n {
0 => IndentLevel::None,
1 => IndentLevel::I1,
2 => IndentLevel::I2,
3 => IndentLevel::I3,
4 => IndentLevel::I4,
_ => IndentLevel::I5,
}
}
}
impl IndentLevel {
#[inline]
pub fn to_int(&self) -> u8 {
match *self {
IndentLevel::None => 0,
IndentLevel::I1 => 1,
IndentLevel::I2 => 2,
IndentLevel::I3 => 3,
IndentLevel::I4 => 4,
IndentLevel::I5 => 5,
}
}
}
#[derive(Clone, Debug)]
pub enum Listing {
None,
Ordered(u8, IndentLevel),
Unordered(IndentLevel),
}
impl Default for Listing {
fn default() -> Self {
Listing::None
}
}
#[derive(Debug)]
pub enum Mark {
CodeBlock(String, Option<String>),
Image(String, String, StyleImage),
NewLine,
Transition(usize, Vec<Mark>),
TransitionEnd,
Page(Vec<Mark>),
Separator(SeparatorDir),
Text(String, StyleText),
}
#[derive(Debug)]
pub enum SeparatorDir {
Horizontal,
Vertical,
}
#[derive(Debug, Default)]
pub struct StyleImage {
pub align_h: AlignHorizontal,
pub hyperlink: String,
pub width: Option<f32>,
pub height: Option<f32>,
}
impl StyleImage {
#[inline]
pub fn new() -> Self {
Default::default()
}
#[inline]
pub fn with_align_h(mut self, align_h: AlignHorizontal) -> Self {
self.align_h = align_h;
self
}
#[inline]
pub fn with_height(mut self, height: f32) -> Self {
self.height = Some(height);
self
}
#[inline]
pub fn with_hyperlink(mut self, hyperlink: String) -> Self {
self.hyperlink = hyperlink;
self
}
#[inline]
pub fn with_width(mut self, width: f32) -> Self {
self.width = Some(width);
self
}
}
#[derive(Debug, Default)]
pub struct StyleText {
pub bold: bool,
pub code: bool,
pub heading: Heading,
pub hyperlink: String,
pub italics: bool,
pub listing: Listing,
pub quote: bool,
pub small: bool,
pub strikethrough: bool,
pub underline: bool,
}
impl Clone for StyleText {
fn clone(&self) -> Self {
StyleText {
bold: self.bold,
code: self.code,
heading: self.heading.clone(),
hyperlink: self.hyperlink.clone(),
italics: self.italics,
listing: self.listing.clone(),
quote: self.quote,
small: self.small,
strikethrough: self.strikethrough,
underline: self.underline,
}
}
}
impl StyleText {
#[inline]
pub fn new() -> Self {
Default::default()
}
#[inline]
pub fn with_bold(mut self) -> Self {
self.bold = true;
self
}
#[inline]
pub fn with_code(mut self) -> Self {
self.code = true;
self
}
#[inline]
pub fn with_heading(mut self, heading: Heading) -> Self {
self.heading = heading;
self
}
#[inline]
pub fn with_hyperlink(mut self, hyperlink: String) -> Self {
self.hyperlink = hyperlink;
self
}
#[inline]
pub fn with_italics(mut self) -> Self {
self.italics = true;
self
}
#[inline]
pub fn with_listing(mut self, listing: Listing) -> Self {
self.listing = listing;
self
}
#[inline]
pub fn with_quote(mut self) -> Self {
self.quote = true;
self
}
#[inline]
pub fn with_small(mut self) -> Self {
self.small = true;
self
}
#[inline]
pub fn with_strikethrough(mut self) -> Self {
self.strikethrough = true;
self
}
#[inline]
pub fn with_underline(mut self) -> Self {
self.underline = true;
self
}
}