Skip to content

Commit 393f625

Browse files
committed
Added fragments to fix height and border
1 parent b33bd80 commit 393f625

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

src/helpers/xml-builder.js

+18-6
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@ const buildHorizontalRuleProperties = (vNode) => {
183183
const horizontalRulePropertiesFragment = fragment({ namespaceAlias: { w: namespaces.w } }).ele('w:pPr');
184184

185185
const modifiedAttributes = modifiedStyleAttributesBuilder(null, vNode, {}, { isParagraph: false });
186-
console.log(modifiedAttributes);
187186
if (modifiedAttributes.lineHeight || modifiedAttributes.beforeSpacing || modifiedAttributes.afterSpacing) {
188187
const spacingFragment = buildSpacing(
189188
modifiedAttributes.lineHeight,
@@ -202,30 +201,41 @@ const buildHorizontalRuleProperties = (vNode) => {
202201
let [borderSize, borderVal, borderColor] = cssBorderParser(border, defaultHorizontalRuleOptions.borderOptions);
203202
if (modifiedAttributes.height) {
204203
const heightValue = parseInt(modifiedAttributes.height, 10);
205-
console.log(heightValue);
206204
borderSize = heightValue;
207205
}
208206
const borderFragment = buildBorder('bottom', borderSize, borderVal, borderColor);
209207
horizontalRulePropertiesFragment.import(borderFragment);
210208

211209
horizontalRulePropertiesFragment.up();
212-
console.log(horizontalRulePropertiesFragment);
213210
return horizontalRulePropertiesFragment;
214211
};
215212

216213
const buildHorizontalRule = (vNode) => {
217214
const horizontalRuleFragment = fragment({ namespaceAlias: { w: namespaces.w } }).ele('w:p');
218-
console.log(vNode);
219215
const propertiesFragment = buildHorizontalRuleProperties(vNode);
220216
horizontalRuleFragment.import(propertiesFragment);
221217

222218
const runFragment = horizontalRuleFragment.ele('w:r');
223-
runFragment.ele('w:rPr');
219+
const runPropertiesFragment = runFragment.ele('w:rPr');
220+
221+
const {
222+
height = defaultHorizontalRuleOptions.height,
223+
width = defaultHorizontalRuleOptions.width,
224+
backgroundColor = defaultHorizontalRuleOptions.backgroundColor,
225+
border = `${defaultHorizontalRuleOptions.borderOptions.size}px ${defaultHorizontalRuleOptions.borderOptions.val} ${defaultHorizontalRuleOptions.borderOptions.color}`
226+
} = vNode.properties.style || {};
227+
228+
const [borderSize, borderVal, borderColor] = cssBorderParser(border, defaultHorizontalRuleOptions.borderOptions);
229+
230+
runPropertiesFragment.ele('w:shd', { 'w:fill': backgroundColor }).up();
231+
runPropertiesFragment.ele('w:bdr', { 'w:val': borderVal, 'w:sz': borderSize, 'w:color': borderColor }).up();
232+
233+
runFragment.ele('w:t', { 'xml:space': 'preserve' }, ' '.repeat(parseInt(width, 10) || 1)).up();
224234
runFragment.up();
225235
horizontalRuleFragment.up();
226236

227237
return horizontalRuleFragment;
228-
};
238+
};
229239

230240
const buildVerticalAlignment = (verticalAlignment) => {
231241
if (verticalAlignment.toLowerCase() === 'middle') {
@@ -781,6 +791,8 @@ const buildFormatting = (htmlTag, options) => {
781791
return buildTextDecoration(options && options.textDecoration ? options.textDecoration : {});
782792
case 'textShadow':
783793
return buildTextShadow();
794+
case 'hr':
795+
return buildHorizontalRule();
784796
}
785797

786798
return null;

0 commit comments

Comments
 (0)