docx icon indicating copy to clipboard operation
docx copied to clipboard

Cannot set doNotExpandShiftReturn in Settings

Open DRG-Support opened this issue 2 years ago • 1 comments

Discussed in https://github.com/dolanmiu/docx/discussions/1033

Originally posted by bkmalan July 8, 2021 Hi, First of all, Thanks to the contributors for maintaining this great library.

Now coming to my concern, I'm using JUSTIFIED as my alignment type but few paragraphs' last line doesn't cover the entire width so it is justified in this manner. Screenshot from 2021-07-08 14-11-45

But I don't want the last line to be justified as much as the previous lines. I went through the documentation and found this line this.doc.Settings.addCompatibility().doNotExpandShiftReturn(); but when I try to use this it says addCompatibility is not a function.

Kindly help me with this.

Thanks


I have just been through the code and as far as I can tell there is no way to make this setting. It looks like only the compatibility mode setting can be made which is a number.

Code exists in docx/src/file/settings/compatibility.ts which defines the interface ( ICompatibilityOptions ) and class ( Compatibility ) where the property doNotExpandShiftReturn (boolean) can be set. The file docx/src/file/settings/settings.ts imports the Compatibility class but only pushes a version property. I think the ISettingsOptions interface needs to be extended here to add the doNotExpandShiftReturn property too?

Also reference pull request #280 where the original code was added

thanks Marcus

DRG-Support avatar Aug 31 '21 13:08 DRG-Support

Until this fixed I've used the following workaround:

import { Document, XmlComponent, OnOffElement } from 'docx';

const doc = new Document({ ... });
doc.Settings.addChildElement(new DoNotExpandShiftReturn());

class DoNotExpandShiftReturn extends XmlComponent {
  constructor() {
    super('w:compat');
    this.root.push(new OnOffElement('w:doNotExpandShiftReturn', true));
  }
}

vitalets avatar Oct 17 '21 19:10 vitalets

Will be added in https://github.com/dolanmiu/docx/pull/1749

All other compabitility options also will be added

dolanmiu avatar Oct 29 '22 14:10 dolanmiu