@@ -12,7 +12,6 @@ import { cloneDeep } from 'lodash';
12
12
import imageToBase64 from 'image-to-base64' ;
13
13
import sizeOf from 'image-size' ;
14
14
import { getMimeType } from '../utils/image'
15
-
16
15
import namespaces from '../namespaces' ;
17
16
import {
18
17
rgbToHex ,
@@ -55,7 +54,8 @@ import {
55
54
imageType ,
56
55
internalRelationship ,
57
56
defaultTableBorderOptions ,
58
- defaultTableBorderAttributeOptions
57
+ defaultTableBorderAttributeOptions ,
58
+ defaultHorizontalRuleOptions ,
59
59
} from '../constants' ;
60
60
import { vNodeHasChildren } from '../utils/vnode' ;
61
61
import { isValidUrl } from '../utils/url' ;
@@ -179,22 +179,44 @@ const buildTableRowHeight = (tableRowHeight) =>
179
179
. att ( '@w' , 'hRule' , 'atLeast' )
180
180
. up ( ) ;
181
181
182
- const buildHorizontalRule = ( ) => {
183
- const hrFragment = fragment ( { namespaceAlias : { w : namespaces . w } } ) . ele ( '@w' , 'p' ) ;
184
- const pPr = hrFragment . ele ( '@w' , 'pPr' ) ;
185
- const pBdr = pPr . ele ( '@w' , 'pBdr' ) ;
186
- pBdr . ele ( '@w' , 'bottom' , {
187
- 'w:val' : 'single' ,
188
- 'w:sz' : '24' ,
189
- 'w:space' : '1' ,
190
- 'w:color' : '000000'
182
+ const buildHorizontalRule = ( element , styles = { } ) => {
183
+ // Parse inline styles from the element
184
+ const inlineStyles = ( styleString => {
185
+ const styles = { } ;
186
+ if ( styleString ) {
187
+ styleString . split ( ";" ) . forEach ( style => {
188
+ const [ key , value ] = style . split ( ":" ) . map ( s => s . trim ( ) ) ;
189
+ if ( key && value ) {
190
+ styles [ key ] = value ;
191
+ }
192
+ } ) ;
193
+ }
194
+ return styles ;
195
+ } ) ( element && typeof element . getAttribute === 'function' ? element . getAttribute ( "style" ) : "" ) ;
196
+
197
+ // Merge inline styles with default styles and additional styles
198
+ const mergedStyles = { ...defaultHorizontalRuleOptions , ...styles , ...inlineStyles } ;
199
+
200
+ // Use the imported fragment directly
201
+ const hrFragment = fragment ( { namespaceAlias : { w : namespaces . w } } ) . ele ( "@w" , "p" ) ;
202
+ const pPr = hrFragment . ele ( "@w" , "pPr" ) ;
203
+ const pBdr = pPr . ele ( "@w" , "pBdr" ) ;
204
+
205
+ // Define the bottom border properties
206
+ pBdr . ele ( "@w" , "bottom" , {
207
+ "w:val" : mergedStyles . val || 'single' ,
208
+ "w:sz" : mergedStyles . sz || '4' ,
209
+ "w:space" : mergedStyles . space || '1' ,
210
+ "w:color" : mergedStyles . color || 'auto'
191
211
} ) ;
212
+
192
213
pBdr . up ( ) ;
193
214
pPr . up ( ) ;
194
215
hrFragment . up ( ) ;
195
- return hrFragment ;
196
- } ;
197
216
217
+ return hrFragment ;
218
+ } ;
219
+
198
220
const buildVerticalAlignment = ( verticalAlignment ) => {
199
221
if ( verticalAlignment . toLowerCase ( ) === 'middle' ) {
200
222
verticalAlignment = 'center' ;
0 commit comments