2019-11-07 09:08:59 +02:00
|
|
|
use super::{Run, RunProperty, Text};
|
|
|
|
use crate::documents::BuildXML;
|
|
|
|
use crate::xml_builder::*;
|
|
|
|
|
2019-11-07 11:45:03 +02:00
|
|
|
#[derive(Debug)]
|
2019-11-07 09:08:59 +02:00
|
|
|
pub struct Paragraph {
|
|
|
|
runs: Vec<Run>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for Paragraph {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self { runs: Vec::new() }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Paragraph {
|
|
|
|
pub fn new() -> Paragraph {
|
|
|
|
Default::default()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn add_run(mut self, run: Run) -> Paragraph {
|
|
|
|
self.runs.push(run);
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl BuildXML for Paragraph {
|
|
|
|
fn build(&self) -> Vec<u8> {
|
2019-11-07 10:31:04 +02:00
|
|
|
XMLBuilder::new()
|
|
|
|
.open_paragraph()
|
|
|
|
.add_children(&self.runs)
|
|
|
|
.close()
|
|
|
|
.build()
|
2019-11-07 09:08:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
|
|
|
|
use super::*;
|
|
|
|
#[cfg(test)]
|
|
|
|
use pretty_assertions::assert_eq;
|
|
|
|
use std::str;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_paragraph() {
|
|
|
|
let b = Paragraph::new().add_run(Run::new("Hello")).build();
|
|
|
|
assert_eq!(
|
|
|
|
str::from_utf8(&b).unwrap(),
|
|
|
|
r#"<w:p><w:r><w:rPr /><w:t>Hello</w:t></w:r></w:p>"#
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|