Skip to content

Commit

Permalink
adding handler for text-shadow property (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
Swayamshu authored May 11, 2024
1 parent 9302e3e commit 08be315
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
7 changes: 7 additions & 0 deletions example/example-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -1437,6 +1437,13 @@ const htmlString = `<!DOCTYPE html>
</p>
</div>
<div>
<span style="text-shadow: 1px 1px 2px grey;">Add new domain</span> to Google Workspace
<p style="text-shadow: 1px 1px 2px grey;">This text has shadow.<strong> And this has shadow with strong tag.</strong> </p>
<p style="text-shadow:">This text has empty shadow property.</p>
<p style="text-shadow: none">This text has none shadow property.</p>
</div>
<p>Some tr styles cases</p>
<p>Color property only passed to tr</p>
<div align="left">
Expand Down
7 changes: 7 additions & 0 deletions example/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -1437,6 +1437,13 @@ const htmlString = `<!DOCTYPE html>
</p>
</div>
<div>
<span style="text-shadow: 1px 1px 2px grey;">Add new domain</span> to Google Workspace
<p style="text-shadow: 1px 1px 2px grey;">This text has shadow.<strong> And this has shadow with strong tag.</strong> </p>
<p style="text-shadow:">This text has empty shadow property.</p>
<p style="text-shadow: none">This text has none shadow property.</p>
</div>
<p>Some tr styles cases</p>
<p>Color property only passed to tr</p>
<div align="left">
Expand Down
7 changes: 7 additions & 0 deletions example/react-example/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -1434,6 +1434,13 @@ const htmlString = `<!DOCTYPE html>
</p>
</div>
<div>
<span style="text-shadow: 1px 1px 2px grey;">Add new domain</span> to Google Workspace
<p style="text-shadow: 1px 1px 2px grey;">This text has shadow.<strong> And this has shadow with strong tag.</strong> </p>
<p style="text-shadow:">This text has empty shadow property.</p>
<p style="text-shadow: none">This text has none shadow property.</p>
</div>
<p>Some tr styles cases</p>
<p>Color property only passed to tr</p>
<div align="left">
Expand Down
15 changes: 14 additions & 1 deletion src/helpers/xml-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,11 @@ const fixupTextDecorationLine = (line) => {
}
return line;
};
const buildTextShadow = () =>
fragment({ namespaceAlias: { w: namespaces.w } })
.ele('@w', 'shadow')
.att('@w', 'val', true)
.up();

// eslint-disable-next-line consistent-return
const fixupLineHeight = (lineHeight, fontSize) => {
Expand Down Expand Up @@ -667,7 +672,9 @@ const modifiedStyleAttributesBuilder = (docxDocumentInstance, vNode, attributes,
line: 'underline',
};
} else if (vNodeStyleKey === 'text-shadow') {
modifiedAttributes.textShadow = vNodeStyleValue;
if (vNodeStyleValue.trim() !== '' && vNodeStyleValue !== 'none') {
modifiedAttributes.textShadow = vNodeStyleValue;
}
}
}
}
Expand Down Expand Up @@ -729,6 +736,8 @@ const buildFormatting = (htmlTag, options) => {
return buildRunStyleFragment('Hyperlink');
case 'textDecoration':
return buildTextDecoration(options && options.textDecoration ? options.textDecoration : {});
case 'textShadow':
return buildTextShadow();
}

return null;
Expand All @@ -750,6 +759,10 @@ const buildRunProperties = (attributes) => {
if (key === 'textDecoration') {
options.textDecoration = attributes[key];
}

if (key === 'textShadow') {
options.textShadow = attributes[key];
}

const formattingFragment = buildFormatting(key, options);
if (formattingFragment) {
Expand Down

0 comments on commit 08be315

Please sign in to comment.