1
- use docx_rs:: { RunProperty , Style } ;
1
+ use docx_rs:: { ParagraphProperty , RunProperty , Style } ;
2
2
3
3
fn analyze_run_properties ( run_properties : & RunProperty ) -> Vec < String > {
4
4
let mut accumulator: Vec < String > = vec ! [ ] ;
@@ -15,12 +15,12 @@ fn analyze_run_properties(run_properties: &RunProperty) -> Vec<String> {
15
15
accumulator. push ( "text-decoration: underline" . to_owned ( ) ) ;
16
16
} ;
17
17
18
- if run_properties. sz . is_some ( ) {
19
- accumulator. push ( format ! (
20
- "font-size: {}px" ,
21
- run_properties. sz. as_ref( ) . unwrap( ) . val
22
- ) ) ;
23
- } ;
18
+ // if run_properties.sz.is_some() {
19
+ // accumulator.push(format!(
20
+ // "font-size: {}px",
21
+ // run_properties.sz.as_ref().unwrap().val
22
+ // ));
23
+ // };
24
24
25
25
if run_properties. strike . is_some ( ) {
26
26
accumulator. push ( "text-decoration: line-through" . to_owned ( ) ) ;
@@ -30,13 +30,37 @@ fn analyze_run_properties(run_properties: &RunProperty) -> Vec<String> {
30
30
accumulator. push ( "visibility: hidden" . to_owned ( ) ) ;
31
31
} ;
32
32
33
+ if let Some ( color) = & run_properties. color . as_ref ( ) {
34
+ let value = & color. val ;
35
+ if value. len ( ) . eq ( & 6 ) || value. len ( ) . eq ( & 8 ) {
36
+ if let Ok ( _) = u32:: from_str_radix ( & value, 16 ) {
37
+ accumulator. push ( format ! ( "color: #{}" , value) ) ;
38
+ } else {
39
+ accumulator. push ( format ! ( "color: {}" , value) ) ;
40
+ }
41
+ } else {
42
+ accumulator. push ( format ! ( "color: {}" , value) ) ;
43
+ }
44
+ }
45
+
46
+ accumulator
47
+ }
48
+
49
+ pub fn analyze_paragraph_properties ( properties : & ParagraphProperty ) -> Vec < String > {
50
+ let mut accumulator: Vec < String > = vec ! [ ] ;
51
+
52
+ if let Some ( alignment) = & properties. alignment . as_ref ( ) {
53
+ accumulator. push ( format ! ( "text-align: {}" , alignment. val) ) ;
54
+ } ;
55
+
33
56
accumulator
34
57
}
35
58
36
59
pub fn analyze_style ( style : & Style ) -> Vec < String > {
37
60
let mut accumulator: Vec < String > = vec ! [ ] ;
38
61
39
62
accumulator. append ( & mut analyze_run_properties ( & style. run_property ) ) ;
63
+ accumulator. append ( & mut analyze_paragraph_properties ( & style. paragraph_property ) ) ;
40
64
41
65
return accumulator;
42
66
}
0 commit comments