@@ -42,6 +42,66 @@ export default class XmlElements {
4242 return this ;
4343 }
4444
45+ createTextBody ( ) : XmlElement {
46+ let txBody = this . element . getElementsByTagName ( 'p:txBody' ) [ 0 ] ;
47+ if ( ! txBody ) {
48+ txBody = this . document . createElement ( 'p:txBody' ) ;
49+ this . element . appendChild ( txBody ) ;
50+ } else {
51+ while ( txBody . firstChild ) {
52+ txBody . removeChild ( txBody . firstChild ) ;
53+ }
54+ }
55+ return txBody ;
56+ }
57+
58+ createBodyProperties ( txBody : XmlElement ) : XmlElement {
59+ const bodyPr = this . document . createElement ( 'a:bodyPr' ) ;
60+ txBody . appendChild ( bodyPr ) ;
61+ return bodyPr ;
62+ }
63+
64+ addBulletList ( list : [ ] ) : void {
65+ const txBody = this . createTextBody ( ) ;
66+ this . createBodyProperties ( txBody ) ;
67+ this . processList ( txBody , list , 0 ) ;
68+ }
69+
70+ processList ( txBody : XmlElement , items : [ ] , level : number ) : void {
71+ items . forEach ( ( item ) => {
72+ if ( Array . isArray ( item ) ) {
73+ this . processList ( txBody , item , level + 1 ) ;
74+ } else {
75+ const p = this . createParagraph ( level ) ;
76+ const r = this . createTextRun ( String ( item ) ) ;
77+ p . appendChild ( r ) ;
78+ txBody . appendChild ( p ) ;
79+ }
80+ } ) ;
81+ }
82+
83+ createParagraph ( level : number ) : XmlElement {
84+ const p = this . document . createElement ( 'a:p' ) ;
85+ const pPr = this . document . createElement ( 'a:pPr' ) ;
86+ if ( level > 0 ) {
87+ pPr . setAttribute ( 'lvl' , String ( level ) ) ;
88+ }
89+ p . appendChild ( pPr ) ;
90+ return p ;
91+ }
92+
93+ createTextRun ( text : string ) : XmlElement {
94+ const r = this . document . createElement ( 'a:r' ) ;
95+ const rPr = this . document . createElement ( 'a:rPr' ) ;
96+ r . appendChild ( rPr ) ;
97+
98+ const t = this . document . createElement ( 'a:t' ) ;
99+ t . textContent = String ( text ) ;
100+
101+ r . appendChild ( t ) ;
102+ return r ;
103+ }
104+
45105 paragraphProps ( ) {
46106 const p = this . element . getElementsByTagName ( 'a:p' ) . item ( 0 ) ;
47107 p . appendChild ( this . document . createElement ( 'a:pPr' ) ) ;
0 commit comments