Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Numbering issue (instance feature, level text) #851

Closed
anti-the-social opened this issue Mar 23, 2021 · 3 comments · Fixed by #852
Closed

Numbering issue (instance feature, level text) #851

anti-the-social opened this issue Mar 23, 2021 · 3 comments · Fixed by #852

Comments

@anti-the-social
Copy link
Contributor

anti-the-social commented Mar 23, 2021

Thank you for the great efforts on improving docx library! It is great.
I think I found some bug into the recent feature with numbering.
The following code:

  1. doesn't follow the style of numbering %1.%2.%3 anymore (works on 5.5.0)
  2. instance: 1 does restart numbering but ones we try to follow instance: 0 again it would still continue numbering from instance 1

image

const fs = require('fs');
const { Document, Packer, Paragraph, PageNumberFormat} = require('docx');

const doc = new Document({
  numbering:{
    config:[{
      reference: 'ref1',
      levels: [
        {
          level: 0,
          format: PageNumberFormat.DECIMAL,
          text: '%1',
        },
        {
          level: 1,
          format: PageNumberFormat.DECIMAL,
          text: '%1.%2',
        },
        {
          level: 2,
          format: PageNumberFormat.DECIMAL,
          text: '%1.%2.%3',
        },
      ],
    }]
  },
  sections: [{
    children: [
      new Paragraph({
        text: "REF1 - inst:0 - lvl:0",
        numbering : {
          reference: 'ref1',
          instance: 0,
          level: 0,
        }
      }),
      new Paragraph({
        text: "REF1 - inst:0 - lvl:0",
        numbering : {
          reference: 'ref1',
          instance: 0,
          level: 0,
        }
      }),
      new Paragraph({
        text: "REF1 - inst:0 - lvl:1",
        numbering : {
          reference: 'ref1',
          instance: 0,
          level: 1,
        }
      }),
      new Paragraph({
        text: "REF1 - inst:0 - lvl:2",
        numbering : {
          reference: 'ref1',
          instance: 0,
          level: 2,
        }
      }),
      new Paragraph({
        text: "REF1 - inst:1 - lvl:0",
        numbering : {
          reference: 'ref1',
          instance: 1,
          level: 0,
        }
      }),
      new Paragraph({
        text: "REF1 - inst:0 - lvl:0",
        numbering : {
          reference: 'ref1',
          instance: 0,
          level: 0,
        }
      }),
      new Paragraph({
        text: "REF1 - inst:0 - lvl:0",
        numbering :{
          reference: 'ref1',
          instance: 0,
          level: 0,
        }
      }),
      new Paragraph({
        text: "Random text",
      }),
    ],
  }]
});

// Used to export the file into a .docx file
Packer.toBuffer(doc).then((buffer) => {
    fs.writeFileSync("numbering.docx", buffer);
});

and here is the 5.5.0 code to check that formatting %1.%2.%3 works

const { Document, Packer, Paragraph, PageNumberFormat} = require('docx');

const doc = new Document({
  numbering:{
    config:[{
      reference: 'ref1',
      levels: [
        {
          level: 0,
          format: PageNumberFormat.DECIMAL,
          text: '%1',
        },
        {
          level: 1,
          format: PageNumberFormat.DECIMAL,
          text: '%1.%2',
        },
        {
          level: 2,
          format: PageNumberFormat.DECIMAL,
          text: '%1.%2.%3',
        },
      ],
    }]
  }
});
doc.addSection({
  children: [
    new Paragraph({
      text: "REF1 - lvl:0",
      numbering : {
        reference: 'ref1',
        level: 0,
      }
    }),
    new Paragraph({
      text: "REF1 - lvl:1",
      numbering : {
        reference: 'ref1',
        level: 1,
      }
    }),
    new Paragraph({
      text: "REF1  - lvl:2",
      numbering : {
        reference: 'ref1',
        level: 2,
      }
    }),
    new Paragraph({
      text: "REF1 - lvl:0",
      numbering : {
        reference: 'ref1',
        level: 0,
      }
    }),
    new Paragraph({
      text: "REF1 - lvl:0",
      numbering : {
        reference: 'ref1',
        level: 0,
      }
    }),
    new Paragraph({
      text: "REF1 - lvl:0",
      numbering :{
        reference: 'ref1',
        level: 0,
      }
    }),
    new Paragraph({
      text: "Random text",
    }),
  ],
})

// Used to export the file into a .docx file
Packer.toBuffer(doc).then((buffer) => {
    fs.writeFileSync("numbering.docx", buffer);
});```
@dolanmiu
Copy link
Owner

dolanmiu commented Mar 23, 2021

Thank you for your kind words!

  1. I will take a look

  2. It was not possible to restart numbering in 5.5.0 so i believe this is an unfair comparison.
    Try using instance: 0 throughout

@anti-the-social
Copy link
Contributor Author

  1. Thank you!
  2. I didn't mean to compare 5.5.0 to 6.0.1 in terms of restart of the numbering. Just a separate matter. I should've open separate issue for that... Just was testing on how instance affects on numbering and was a little surprised that ones you change instance to something else, you cannot continue list of the previous instance. I would say it is rather intuitive if you can.
    image
const fs = require('fs');
const { Document, Packer, Paragraph, PageNumberFormat} = require('docx');

const doc = new Document({
  numbering:{
    config:[
      {
        reference: 'ref1',
        levels: [
          {
            level: 0,
            format: PageNumberFormat.DECIMAL,
            text: '%1',
          }
        ],
      }
  ]
  },
  sections: [{
    children: [
      new Paragraph({
        text: "REF1 - inst:0 - lvl:0",
        numbering : {
          reference: 'ref1',
          instance: 0,
          level: 0,
        }
      }),
      new Paragraph({
        text: "REF1 - inst:0 - lvl:0",
        numbering : {
          reference: 'ref1',
          instance: 0,
          level: 0,
        }
      }),
      new Paragraph({
        text: "REF1 - inst:0 - lvl:0",
        numbering : {
          reference: 'ref1',
          instance: 0,
          level: 0,
        }
      }),
      new Paragraph({
        text: "REF1 - inst:1 - lvl:0",
        numbering : {
          reference: 'ref1',
          instance: 1,
          level: 0,
        }
      }),
      new Paragraph({
        text: "REF1 - inst:1 - lvl:0",
        numbering : {
          reference: 'ref1',
          instance: 1,
          level: 0,
        }
      }),
      new Paragraph({
        text: "REF1 - inst:0 - lvl:0",
        numbering : {
          reference: 'ref1',
          instance: 0,
          level: 0,
        }
      }),
      new Paragraph({
        text: "REF1 - inst:0 - lvl:0",
        numbering : {
          reference: 'ref1',
          instance: 0,
          level: 0,
        }
      })
    ],
  }]
});

// Used to export the file into a .docx file
Packer.toBuffer(doc).then((buffer) => {
    fs.writeFileSync("numbering.docx", buffer);
});

@dolanmiu
Copy link
Owner

dolanmiu commented Mar 24, 2021

Found out the problem, will be fixed with:

#852

And regarding the intuitiveness of the numbering, it's not actually officially in the spec, different Word Processors will interpret it differently

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants