Skip to content

Commit

Permalink
feat: add support for pre tag
Browse files Browse the repository at this point in the history
  • Loading branch information
privateOmega committed Sep 15, 2021
1 parent b7bf5d5 commit c43ed9e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/helpers/render-document-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ function findXMLEquivalent(docxDocumentInstance, vNode, xmlFragment) {
case 'p':
case 'a':
case 'blockquote':
case 'pre':
const paragraphFragment = xmlBuilder.buildParagraph(vNode, {}, docxDocumentInstance);
xmlFragment.import(paragraphFragment);
return;
Expand Down
18 changes: 18 additions & 0 deletions src/helpers/xml-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,18 @@ const fixupColorCode = (colorCodeString) => {
}
};

const buildRunFontFragment = (fontName = 'Times New Roman') => {
const runFontFragment = fragment({
namespaceAlias: { w: namespaces.w },
})
.ele('@w', 'rFonts')
.att('@w', 'ascii', fontName)
.att('@w', 'hAnsi', fontName)
.up();

return runFontFragment;
};

const buildRunStyleFragment = (type = 'Hyperlink') => {
const runStyleFragment = fragment({
namespaceAlias: { w: namespaces.w },
Expand Down Expand Up @@ -300,6 +312,10 @@ const buildRunProperties = (attributes) => {
const hyperlinkStyleFragment = buildRunStyleFragment('Hyperlink');
runPropertiesFragment.import(hyperlinkStyleFragment);
break;
case 'font':
const runFontFragment = buildRunFontFragment('Courier');
runPropertiesFragment.import(runFontFragment);
break;
}
});
}
Expand Down Expand Up @@ -852,6 +868,8 @@ const buildParagraph = (vNode, attributes, docxDocumentInstance) => {
if (isVNode(vNode) && vNode.tagName === 'blockquote') {
modifiedAttributes.indentation = { left: 284 };
modifiedAttributes.textAlign = 'justify';
} else if (isVNode(vNode) && vNode.tagName === 'pre') {
modifiedAttributes.font = 'Courier';
}
const paragraphPropertiesFragment = buildParagraphProperties(modifiedAttributes);
paragraphFragment.import(paragraphPropertiesFragment);
Expand Down

0 comments on commit c43ed9e

Please sign in to comment.