@@ -42,6 +42,98 @@ 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+ // Method to create bodyPr element
59+ createBodyProperties ( txBody : XmlElement ) : XmlElement {
60+ const bodyPr = this . document . createElement ( 'a:bodyPr' ) ;
61+ txBody . appendChild ( bodyPr ) ;
62+ return bodyPr ;
63+ }
64+
65+ // Method to create lstStyle element
66+ createListStyle ( txBody : XmlElement ) : XmlElement {
67+ const lstStyle = this . document . createElement ( 'a:lstStyle' ) ;
68+
69+ // Loop through levels (assuming 3 levels here)
70+ for ( let level = 1 ; level <= 3 ; level ++ ) {
71+ const lvlpPr = this . document . createElement ( `a:lvl${ level } pPr` ) ;
72+
73+ // Set bullet font
74+ const buFont = this . document . createElement ( 'a:buFont' ) ;
75+ buFont . setAttribute ( 'typeface' , 'Arial' ) ;
76+ lvlpPr . appendChild ( buFont ) ;
77+
78+ // Set bullet character (you can use different characters for each level)
79+ const buChar = this . document . createElement ( 'a:buChar' ) ;
80+ buChar . setAttribute ( 'char' , '•' ) ;
81+ lvlpPr . appendChild ( buChar ) ;
82+
83+ lstStyle . appendChild ( lvlpPr ) ;
84+ }
85+
86+ txBody . appendChild ( lstStyle ) ;
87+ return lstStyle ;
88+ }
89+
90+ // Method to process the bullet list
91+ addBulletList ( list : [ ] ) : void {
92+ const txBody = this . createTextBody ( ) ;
93+ this . createBodyProperties ( txBody ) ;
94+ this . createListStyle ( txBody ) ;
95+ this . processList ( txBody , list , 0 ) ;
96+ }
97+
98+ // Recursive method to create paragraphs and text runs for each list item
99+ processList ( txBody : XmlElement , items : [ ] , level : number ) : void {
100+ items . forEach ( ( item ) => {
101+ if ( Array . isArray ( item ) ) {
102+ this . processList ( txBody , item , level + 1 ) ;
103+ } else {
104+ const p = this . createParagraph ( level ) ;
105+ const r = this . createTextRun ( String ( item ) ) ;
106+ p . appendChild ( r ) ;
107+ txBody . appendChild ( p ) ;
108+ }
109+ } ) ;
110+ }
111+
112+ // Method to create a paragraph element
113+ createParagraph ( level : number ) : XmlElement {
114+ const p = this . document . createElement ( 'a:p' ) ;
115+ const pPr = this . document . createElement ( 'a:pPr' ) ;
116+ if ( level > 0 ) {
117+ pPr . setAttribute ( 'lvl' , String ( level ) ) ;
118+ }
119+ p . appendChild ( pPr ) ;
120+ return p ;
121+ }
122+
123+ // Method to create a text run element
124+ createTextRun ( text : string ) : XmlElement {
125+ const r = this . document . createElement ( 'a:r' ) ;
126+ const rPr = this . document . createElement ( 'a:rPr' ) ;
127+ r . appendChild ( rPr ) ;
128+
129+ const t = this . document . createElement ( 'a:t' ) ;
130+ const textNode = this . document . createTextNode ( text ) ;
131+ t . appendChild ( textNode ) ;
132+
133+ r . appendChild ( t ) ;
134+ return r ;
135+ }
136+
45137 paragraphProps ( ) {
46138 const p = this . element . getElementsByTagName ( 'a:p' ) . item ( 0 ) ;
47139 p . appendChild ( this . document . createElement ( 'a:pPr' ) ) ;
0 commit comments