feat: Support level restart reader (#282)
parent
342ad37d4d
commit
40664493b2
|
@ -90,7 +90,7 @@ mod tests {
|
|||
.num_style_link("style1");
|
||||
assert_eq!(
|
||||
serde_json::to_string(&c).unwrap(),
|
||||
r#"{"id":0,"styleLink":null,"numStyleLink":"style1","levels":[{"level":1,"start":1,"format":"decimal","text":"%4.","jc":"left","pstyle":null,"paragraphProperty":{"runProperty":{"sz":null,"szCs":null,"color":null,"highlight":null,"underline":null,"bold":null,"boldCs":null,"italic":null,"italicCs":null,"vanish":null,"spacing":null,"fonts":null,"textBorder":null},"style":null,"numberingProperty":null,"alignment":null,"indent":null,"lineHeight":null,"keepNext":false,"keepLines":false,"pageBreakBefore":false,"windowControl":false,"divId":null},"runProperty":{"sz":null,"szCs":null,"color":null,"highlight":null,"underline":null,"bold":null,"boldCs":null,"italic":null,"italicCs":null,"vanish":null,"spacing":null,"fonts":null,"textBorder":null},"suffix":"tab"}]}"#
|
||||
r#"{"id":0,"styleLink":null,"numStyleLink":"style1","levels":[{"level":1,"start":1,"format":"decimal","text":"%4.","jc":"left","paragraphProperty":{"runProperty":{"sz":null,"szCs":null,"color":null,"highlight":null,"underline":null,"bold":null,"boldCs":null,"italic":null,"italicCs":null,"vanish":null,"spacing":null,"fonts":null,"textBorder":null},"style":null,"numberingProperty":null,"alignment":null,"indent":null,"lineHeight":null,"keepNext":false,"keepLines":false,"pageBreakBefore":false,"windowControl":false,"divId":null},"runProperty":{"sz":null,"szCs":null,"color":null,"highlight":null,"underline":null,"bold":null,"boldCs":null,"italic":null,"italicCs":null,"vanish":null,"spacing":null,"fonts":null,"textBorder":null},"suffix":"tab","pstyle":null,"levelRestart":null}]}"#
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,10 +12,11 @@ pub struct Level {
|
|||
pub format: NumberFormat,
|
||||
pub text: LevelText,
|
||||
pub jc: LevelJc,
|
||||
pub pstyle: Option<String>,
|
||||
pub paragraph_property: ParagraphProperty,
|
||||
pub run_property: RunProperty,
|
||||
pub suffix: LevelSuffixType,
|
||||
pub pstyle: Option<String>,
|
||||
pub level_restart: Option<LevelRestart>,
|
||||
}
|
||||
|
||||
impl Level {
|
||||
|
@ -32,10 +33,11 @@ impl Level {
|
|||
format,
|
||||
text,
|
||||
jc,
|
||||
pstyle: None,
|
||||
paragraph_property: ParagraphProperty::new(),
|
||||
run_property: RunProperty::new(),
|
||||
suffix: LevelSuffixType::Tab,
|
||||
pstyle: None,
|
||||
level_restart: None,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -107,6 +109,11 @@ impl Level {
|
|||
self.run_property = self.run_property.fonts(f);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn level_restart(mut self, v: u32) -> Self {
|
||||
self.level_restart = Some(LevelRestart::new(v));
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl BuildXML for Level {
|
||||
|
@ -118,7 +125,8 @@ impl BuildXML for Level {
|
|||
.add_child(&self.text)
|
||||
.add_child(&self.jc)
|
||||
.add_child(&self.paragraph_property)
|
||||
.add_child(&self.run_property);
|
||||
.add_child(&self.run_property)
|
||||
.add_optional_child(&self.level_restart);
|
||||
|
||||
if self.suffix != LevelSuffixType::Tab {
|
||||
b = b.suffix(&self.suffix.to_string());
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
use serde::{Serialize, Serializer};
|
||||
|
||||
use crate::documents::BuildXML;
|
||||
use crate::xml_builder::*;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct LevelRestart {
|
||||
val: u32,
|
||||
}
|
||||
|
||||
impl LevelRestart {
|
||||
pub fn new(val: impl Into<u32>) -> Self {
|
||||
Self { val: val.into() }
|
||||
}
|
||||
}
|
||||
|
||||
impl BuildXML for LevelRestart {
|
||||
fn build(&self) -> Vec<u8> {
|
||||
let b = XMLBuilder::new();
|
||||
let v = format!("{}", &self.val);
|
||||
b.level_restart(&v).build()
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for LevelRestart {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_u32(self.val)
|
||||
}
|
||||
}
|
|
@ -34,6 +34,7 @@ mod justification;
|
|||
mod level;
|
||||
mod level_jc;
|
||||
mod level_override;
|
||||
mod level_restart;
|
||||
mod level_text;
|
||||
mod mc_fallback;
|
||||
mod name;
|
||||
|
@ -126,6 +127,7 @@ pub use justification::*;
|
|||
pub use level::*;
|
||||
pub use level_jc::*;
|
||||
pub use level_override::*;
|
||||
pub use level_restart::*;
|
||||
pub use level_text::*;
|
||||
pub use mc_fallback::*;
|
||||
pub use name::*;
|
||||
|
|
|
@ -23,6 +23,7 @@ impl ElementReader for Level {
|
|||
let mut special_indent = None;
|
||||
let mut indent_end = None;
|
||||
let mut start_chars = None;
|
||||
let mut level_restart = None;
|
||||
let mut has_indent = false;
|
||||
let mut suffix = LevelSuffixType::Tab;
|
||||
|
||||
|
@ -50,6 +51,11 @@ impl ElementReader for Level {
|
|||
XMLElement::LevelText => {
|
||||
level_text = LevelText::new(attributes[0].value.clone());
|
||||
}
|
||||
XMLElement::LevelRestart => {
|
||||
if let Ok(v) = u32::from_str(&attributes[0].value) {
|
||||
level_restart = Some(LevelRestart::new(v));
|
||||
}
|
||||
}
|
||||
XMLElement::LevelJustification => {
|
||||
jc = LevelJc::new(attributes[0].value.clone());
|
||||
}
|
||||
|
@ -75,6 +81,7 @@ impl ElementReader for Level {
|
|||
if has_indent {
|
||||
l = l.indent(indent_start, special_indent, indent_end, start_chars);
|
||||
}
|
||||
l.level_restart = level_restart;
|
||||
return Ok(l);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -117,6 +117,7 @@ pub enum XMLElement {
|
|||
Suffix,
|
||||
LevelText,
|
||||
LevelJustification,
|
||||
LevelRestart,
|
||||
StyleLink,
|
||||
NumStyleLink,
|
||||
Drawing,
|
||||
|
@ -286,6 +287,7 @@ impl FromStr for XMLElement {
|
|||
"numFmt" => Ok(XMLElement::NumberFormat),
|
||||
"suff" => Ok(XMLElement::Suffix),
|
||||
"lvlText" => Ok(XMLElement::LevelText),
|
||||
"lvlRestart" => Ok(XMLElement::LevelRestart),
|
||||
"lvlJc" => Ok(XMLElement::LevelJustification),
|
||||
"numStyleLink" => Ok(XMLElement::NumStyleLink),
|
||||
"styleLink" => Ok(XMLElement::StyleLink),
|
||||
|
|
|
@ -275,6 +275,7 @@ impl XMLBuilder {
|
|||
closed_with_usize!(start, "w:start");
|
||||
closed_with_str!(number_format, "w:numFmt");
|
||||
closed_with_str!(level_text, "w:lvlText");
|
||||
closed_with_str!(level_restart, "w:lvlRestart");
|
||||
closed_with_str!(level_justification, "w:lvlJc");
|
||||
closed_with_str!(abstract_num_id, "w:abstractNumId");
|
||||
closed!(vanish, "w:vanish");
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -6,9 +6,10 @@ export type LevelJSON = {
|
|||
format: string;
|
||||
text: string;
|
||||
jc: string;
|
||||
pstyle: string | null;
|
||||
suffix: "tab" | "nothing" | "space";
|
||||
paragraphProperty: ParagraphPropertyJSON;
|
||||
pstyle: string | null;
|
||||
levelRestart: number | null;
|
||||
};
|
||||
|
||||
export type AbstractNumberingJSON = {
|
||||
|
|
|
@ -5127,6 +5127,7 @@ Object {
|
|||
"format": "decimal",
|
||||
"jc": "left",
|
||||
"level": 0,
|
||||
"levelRestart": null,
|
||||
"paragraphProperty": Object {
|
||||
"alignment": null,
|
||||
"divId": null,
|
||||
|
@ -5188,6 +5189,7 @@ Object {
|
|||
"format": "aiueoFullWidth",
|
||||
"jc": "left",
|
||||
"level": 1,
|
||||
"levelRestart": null,
|
||||
"paragraphProperty": Object {
|
||||
"alignment": null,
|
||||
"divId": null,
|
||||
|
@ -5249,6 +5251,7 @@ Object {
|
|||
"format": "decimalEnclosedCircle",
|
||||
"jc": "left",
|
||||
"level": 2,
|
||||
"levelRestart": null,
|
||||
"paragraphProperty": Object {
|
||||
"alignment": null,
|
||||
"divId": null,
|
||||
|
@ -5310,6 +5313,7 @@ Object {
|
|||
"format": "decimal",
|
||||
"jc": "left",
|
||||
"level": 3,
|
||||
"levelRestart": null,
|
||||
"paragraphProperty": Object {
|
||||
"alignment": null,
|
||||
"divId": null,
|
||||
|
@ -5371,6 +5375,7 @@ Object {
|
|||
"format": "aiueoFullWidth",
|
||||
"jc": "left",
|
||||
"level": 4,
|
||||
"levelRestart": null,
|
||||
"paragraphProperty": Object {
|
||||
"alignment": null,
|
||||
"divId": null,
|
||||
|
@ -5432,6 +5437,7 @@ Object {
|
|||
"format": "decimalEnclosedCircle",
|
||||
"jc": "left",
|
||||
"level": 5,
|
||||
"levelRestart": null,
|
||||
"paragraphProperty": Object {
|
||||
"alignment": null,
|
||||
"divId": null,
|
||||
|
@ -5493,6 +5499,7 @@ Object {
|
|||
"format": "decimal",
|
||||
"jc": "left",
|
||||
"level": 6,
|
||||
"levelRestart": null,
|
||||
"paragraphProperty": Object {
|
||||
"alignment": null,
|
||||
"divId": null,
|
||||
|
@ -5554,6 +5561,7 @@ Object {
|
|||
"format": "aiueoFullWidth",
|
||||
"jc": "left",
|
||||
"level": 7,
|
||||
"levelRestart": null,
|
||||
"paragraphProperty": Object {
|
||||
"alignment": null,
|
||||
"divId": null,
|
||||
|
@ -5615,6 +5623,7 @@ Object {
|
|||
"format": "decimalEnclosedCircle",
|
||||
"jc": "left",
|
||||
"level": 8,
|
||||
"levelRestart": null,
|
||||
"paragraphProperty": Object {
|
||||
"alignment": null,
|
||||
"divId": null,
|
||||
|
@ -5683,6 +5692,7 @@ Object {
|
|||
"format": "decimal",
|
||||
"jc": "left",
|
||||
"level": 0,
|
||||
"levelRestart": null,
|
||||
"paragraphProperty": Object {
|
||||
"alignment": null,
|
||||
"divId": null,
|
||||
|
@ -5744,6 +5754,7 @@ Object {
|
|||
"format": "aiueoFullWidth",
|
||||
"jc": "left",
|
||||
"level": 1,
|
||||
"levelRestart": null,
|
||||
"paragraphProperty": Object {
|
||||
"alignment": null,
|
||||
"divId": null,
|
||||
|
@ -5805,6 +5816,7 @@ Object {
|
|||
"format": "decimalEnclosedCircle",
|
||||
"jc": "left",
|
||||
"level": 2,
|
||||
"levelRestart": null,
|
||||
"paragraphProperty": Object {
|
||||
"alignment": null,
|
||||
"divId": null,
|
||||
|
@ -5866,6 +5878,7 @@ Object {
|
|||
"format": "decimal",
|
||||
"jc": "left",
|
||||
"level": 3,
|
||||
"levelRestart": null,
|
||||
"paragraphProperty": Object {
|
||||
"alignment": null,
|
||||
"divId": null,
|
||||
|
@ -5927,6 +5940,7 @@ Object {
|
|||
"format": "aiueoFullWidth",
|
||||
"jc": "left",
|
||||
"level": 4,
|
||||
"levelRestart": null,
|
||||
"paragraphProperty": Object {
|
||||
"alignment": null,
|
||||
"divId": null,
|
||||
|
@ -5988,6 +6002,7 @@ Object {
|
|||
"format": "decimalEnclosedCircle",
|
||||
"jc": "left",
|
||||
"level": 5,
|
||||
"levelRestart": null,
|
||||
"paragraphProperty": Object {
|
||||
"alignment": null,
|
||||
"divId": null,
|
||||
|
@ -6049,6 +6064,7 @@ Object {
|
|||
"format": "decimal",
|
||||
"jc": "left",
|
||||
"level": 6,
|
||||
"levelRestart": null,
|
||||
"paragraphProperty": Object {
|
||||
"alignment": null,
|
||||
"divId": null,
|
||||
|
@ -6110,6 +6126,7 @@ Object {
|
|||
"format": "aiueoFullWidth",
|
||||
"jc": "left",
|
||||
"level": 7,
|
||||
"levelRestart": null,
|
||||
"paragraphProperty": Object {
|
||||
"alignment": null,
|
||||
"divId": null,
|
||||
|
@ -6171,6 +6188,7 @@ Object {
|
|||
"format": "decimalEnclosedCircle",
|
||||
"jc": "left",
|
||||
"level": 8,
|
||||
"levelRestart": null,
|
||||
"paragraphProperty": Object {
|
||||
"alignment": null,
|
||||
"divId": null,
|
||||
|
@ -6239,6 +6257,7 @@ Object {
|
|||
"format": "decimal",
|
||||
"jc": "left",
|
||||
"level": 0,
|
||||
"levelRestart": null,
|
||||
"paragraphProperty": Object {
|
||||
"alignment": null,
|
||||
"divId": null,
|
||||
|
@ -6300,6 +6319,7 @@ Object {
|
|||
"format": "aiueoFullWidth",
|
||||
"jc": "left",
|
||||
"level": 1,
|
||||
"levelRestart": null,
|
||||
"paragraphProperty": Object {
|
||||
"alignment": null,
|
||||
"divId": null,
|
||||
|
@ -6361,6 +6381,7 @@ Object {
|
|||
"format": "decimalEnclosedCircle",
|
||||
"jc": "left",
|
||||
"level": 2,
|
||||
"levelRestart": null,
|
||||
"paragraphProperty": Object {
|
||||
"alignment": null,
|
||||
"divId": null,
|
||||
|
@ -6422,6 +6443,7 @@ Object {
|
|||
"format": "decimal",
|
||||
"jc": "left",
|
||||
"level": 3,
|
||||
"levelRestart": null,
|
||||
"paragraphProperty": Object {
|
||||
"alignment": null,
|
||||
"divId": null,
|
||||
|
@ -6483,6 +6505,7 @@ Object {
|
|||
"format": "aiueoFullWidth",
|
||||
"jc": "left",
|
||||
"level": 4,
|
||||
"levelRestart": null,
|
||||
"paragraphProperty": Object {
|
||||
"alignment": null,
|
||||
"divId": null,
|
||||
|
@ -6544,6 +6567,7 @@ Object {
|
|||
"format": "decimalEnclosedCircle",
|
||||
"jc": "left",
|
||||
"level": 5,
|
||||
"levelRestart": null,
|
||||
"paragraphProperty": Object {
|
||||
"alignment": null,
|
||||
"divId": null,
|
||||
|
@ -6605,6 +6629,7 @@ Object {
|
|||
"format": "decimal",
|
||||
"jc": "left",
|
||||
"level": 6,
|
||||
"levelRestart": null,
|
||||
"paragraphProperty": Object {
|
||||
"alignment": null,
|
||||
"divId": null,
|
||||
|
@ -6666,6 +6691,7 @@ Object {
|
|||
"format": "aiueoFullWidth",
|
||||
"jc": "left",
|
||||
"level": 7,
|
||||
"levelRestart": null,
|
||||
"paragraphProperty": Object {
|
||||
"alignment": null,
|
||||
"divId": null,
|
||||
|
@ -6727,6 +6753,7 @@ Object {
|
|||
"format": "decimalEnclosedCircle",
|
||||
"jc": "left",
|
||||
"level": 8,
|
||||
"levelRestart": null,
|
||||
"paragraphProperty": Object {
|
||||
"alignment": null,
|
||||
"divId": null,
|
||||
|
@ -6810,6 +6837,7 @@ Object {
|
|||
"format": "decimal",
|
||||
"jc": "left",
|
||||
"level": 0,
|
||||
"levelRestart": null,
|
||||
"paragraphProperty": Object {
|
||||
"alignment": null,
|
||||
"divId": null,
|
||||
|
@ -9263,6 +9291,7 @@ Object {
|
|||
"format": "decimal",
|
||||
"jc": "left",
|
||||
"level": 0,
|
||||
"levelRestart": null,
|
||||
"paragraphProperty": Object {
|
||||
"alignment": null,
|
||||
"divId": null,
|
||||
|
@ -9324,6 +9353,7 @@ Object {
|
|||
"format": "decimal",
|
||||
"jc": "left",
|
||||
"level": 1,
|
||||
"levelRestart": null,
|
||||
"paragraphProperty": Object {
|
||||
"alignment": null,
|
||||
"divId": null,
|
||||
|
@ -9385,6 +9415,7 @@ Object {
|
|||
"format": "decimalEnclosedCircle",
|
||||
"jc": "left",
|
||||
"level": 2,
|
||||
"levelRestart": null,
|
||||
"paragraphProperty": Object {
|
||||
"alignment": null,
|
||||
"divId": null,
|
||||
|
@ -9446,6 +9477,7 @@ Object {
|
|||
"format": "decimal",
|
||||
"jc": "left",
|
||||
"level": 3,
|
||||
"levelRestart": null,
|
||||
"paragraphProperty": Object {
|
||||
"alignment": null,
|
||||
"divId": null,
|
||||
|
@ -9507,6 +9539,7 @@ Object {
|
|||
"format": "decimal",
|
||||
"jc": "left",
|
||||
"level": 4,
|
||||
"levelRestart": null,
|
||||
"paragraphProperty": Object {
|
||||
"alignment": null,
|
||||
"divId": null,
|
||||
|
@ -9568,6 +9601,7 @@ Object {
|
|||
"format": "decimalEnclosedCircle",
|
||||
"jc": "left",
|
||||
"level": 5,
|
||||
"levelRestart": null,
|
||||
"paragraphProperty": Object {
|
||||
"alignment": null,
|
||||
"divId": null,
|
||||
|
@ -9629,6 +9663,7 @@ Object {
|
|||
"format": "decimal",
|
||||
"jc": "left",
|
||||
"level": 6,
|
||||
"levelRestart": null,
|
||||
"paragraphProperty": Object {
|
||||
"alignment": null,
|
||||
"divId": null,
|
||||
|
@ -9690,6 +9725,7 @@ Object {
|
|||
"format": "decimal",
|
||||
"jc": "left",
|
||||
"level": 7,
|
||||
"levelRestart": null,
|
||||
"paragraphProperty": Object {
|
||||
"alignment": null,
|
||||
"divId": null,
|
||||
|
@ -9751,6 +9787,7 @@ Object {
|
|||
"format": "decimalEnclosedCircle",
|
||||
"jc": "left",
|
||||
"level": 8,
|
||||
"levelRestart": null,
|
||||
"paragraphProperty": Object {
|
||||
"alignment": null,
|
||||
"divId": null,
|
||||
|
@ -9819,6 +9856,7 @@ Object {
|
|||
"format": "decimal",
|
||||
"jc": "left",
|
||||
"level": 0,
|
||||
"levelRestart": null,
|
||||
"paragraphProperty": Object {
|
||||
"alignment": null,
|
||||
"divId": null,
|
||||
|
@ -9880,6 +9918,7 @@ Object {
|
|||
"format": "decimal",
|
||||
"jc": "left",
|
||||
"level": 1,
|
||||
"levelRestart": null,
|
||||
"paragraphProperty": Object {
|
||||
"alignment": null,
|
||||
"divId": null,
|
||||
|
@ -9931,6 +9970,7 @@ Object {
|
|||
"format": "decimal",
|
||||
"jc": "left",
|
||||
"level": 2,
|
||||
"levelRestart": null,
|
||||
"paragraphProperty": Object {
|
||||
"alignment": null,
|
||||
"divId": null,
|
||||
|
@ -9982,6 +10022,7 @@ Object {
|
|||
"format": "decimal",
|
||||
"jc": "left",
|
||||
"level": 3,
|
||||
"levelRestart": null,
|
||||
"paragraphProperty": Object {
|
||||
"alignment": null,
|
||||
"divId": null,
|
||||
|
@ -10033,6 +10074,7 @@ Object {
|
|||
"format": "decimal",
|
||||
"jc": "left",
|
||||
"level": 4,
|
||||
"levelRestart": null,
|
||||
"paragraphProperty": Object {
|
||||
"alignment": null,
|
||||
"divId": null,
|
||||
|
@ -10084,6 +10126,7 @@ Object {
|
|||
"format": "decimal",
|
||||
"jc": "left",
|
||||
"level": 5,
|
||||
"levelRestart": null,
|
||||
"paragraphProperty": Object {
|
||||
"alignment": null,
|
||||
"divId": null,
|
||||
|
@ -10135,6 +10178,7 @@ Object {
|
|||
"format": "decimal",
|
||||
"jc": "left",
|
||||
"level": 6,
|
||||
"levelRestart": null,
|
||||
"paragraphProperty": Object {
|
||||
"alignment": null,
|
||||
"divId": null,
|
||||
|
@ -10186,6 +10230,7 @@ Object {
|
|||
"format": "decimal",
|
||||
"jc": "left",
|
||||
"level": 7,
|
||||
"levelRestart": null,
|
||||
"paragraphProperty": Object {
|
||||
"alignment": null,
|
||||
"divId": null,
|
||||
|
@ -10237,6 +10282,7 @@ Object {
|
|||
"format": "decimal",
|
||||
"jc": "left",
|
||||
"level": 8,
|
||||
"levelRestart": null,
|
||||
"paragraphProperty": Object {
|
||||
"alignment": null,
|
||||
"divId": null,
|
||||
|
|
Loading…
Reference in New Issue