-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Adding low-level support for numbering styles. #582
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
base: master
Are you sure you want to change the base?
Conversation
…part. Discussing resolution to issues 25 and 122.
I cannot understand your meaning,can you give some example? |
@LilyDreamZhao there's a good example on StackOverflow of the kind of problem that my PR addresses. Basically, the |
@jlovegren0 Do you know if scanny has reviewed this or plans on merging this PR? |
I haven't had any contact with him about it. I think he hasn't had time
for the project lately, and my PR would take a bit of study to decide on
merging it. Hopefully it gets some attention in the future.
…On Thu, Mar 26, 2020 at 12:15:23PM -0700, nitinkhosla79 wrote:
@jlovegren0 Do you know if scanny has reviewed this or plans on merging this PR?
@scanny
--
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub:
#582 (comment)
--
Jesse Lovegren
|
@scanny Can you advise on this PR and what all is needed? We can help with testing/regression tests and if anything else is needed, please advise. |
@jlovegren0 Do you have a working example to try? Can you please comment on the observation by @Clorel ? |
the example comes from the last post on this topic : https://stackoverflow.com/questions/23446268 |
@Clorel Great to hear! Are you saying that you are able use this API (in this PR and) made further edits to make it work? Would you be able to describe those or add here if @jlovegren0 is ok with that? |
sorry, not this API, the default API from python docx, with the example function "list_number" from : #25. |
@Clorel We tried that and that is not working for us. Infact, if the document is opened in libreoffice it shows nested list correctly but in word, it shows in 1 sequence. What change did you make there? |
"manage in low level API the abstractNum/Numbering index with a constant hash index" |
@nitinkhosla79 thanks for following up on this. I ran the code from the SE
post and indeed the document renders properly in LibreOffice, but not in
MS Word. I should add that Google Docs also renders it properly. I don't
know whether that means (a) my solution is slightly off, but LibreOffice
and Google docs are more forgiving; or (b) MS Word departs from ISO 29500
in some way and my solution is correct w/r/t the standrd. My branch has
notes at /docs/dev/analysis/features/numbering.rst that I made at the time
I made the PR (I didn't have a Word license at the time). I'm interested in
a work-around if @Clorel has found one for MS Word.
…On Sat, Mar 28, 2020 at 3:12 PM nitinkhosla79 ***@***.***> wrote:
"manage in low level API the abstractNum/Numbering index with a constant
hash index"
@Clorel <https://github.com/Clorel> Constant hash index - can you
elaborate a bit or share a code snipped for same?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#582 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADFNSQMLHS3XTICAJ57WYILRJZKZ7ANCNFSM4GHUFOXQ>
.
--
Jesse Lovegren
|
@jlovegren0 can you check section 17.9(in particular 17.9.10) in latest iso 29500 version - latest release in Feb 2020. |
`def set_numbering(doc, par, prev=None, num_fmt_style='none', level=0, suffix_text='%1)', int_start=None):
and the xml content embedded : |
@jlovegren0 Did you get a chance to review that section or if it gave you any clues on whether something is missing for level/restart conditions? |
@nitinkhosla79 I'll have a chance to review it in a few hours. Thanks for
the lead.
…On Sun, Mar 29, 2020 at 6:27 PM nitinkhosla79 ***@***.***> wrote:
@jlovegren0 <https://github.com/jlovegren0> Did you get a chance to
review that section or if it gave you any clues on whether something is
missing for level/restart conditions?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#582 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADFNSQLZXSOZNQ4IY2X374DRJ7KOZANCNFSM4GHUFOXQ>
.
--
Jesse Lovegren
|
@nitinkhosla79 I think you are referring to Microsoft's publication
MS-OI29500 which lists areas where the Word UA departs from normative ISO
29500 sections. The portion referring to 17.9.10 concerns numbering restart
elements. It is not relevant to the issue we are seeing with the example
code from the SE question. The issue is that Word is treating the
`abstractNum` definition created with python-docx as though its
`multiLevelType` was `singleLevel`. It faithfully applies the number format
for level one, but ignores subsequent levels.
I looked at XML for a multilevel list definition generated by Word. I can't
find any clear discrepancies other than Word defining some optional
elements (tmpl, nsid, tabs and indents). I don't have any ideas about why
the behavior is off.
…On Sun, Mar 29, 2020 at 6:34 PM Jesse Lovegren ***@***.***> wrote:
@nitinkhosla79 I'll have a chance to review it in a few hours. Thanks for
the lead.
On Sun, Mar 29, 2020 at 6:27 PM nitinkhosla79 ***@***.***>
wrote:
> @jlovegren0 <https://github.com/jlovegren0> Did you get a chance to
> review that section or if it gave you any clues on whether something is
> missing for level/restart conditions?
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <#582 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/ADFNSQLZXSOZNQ4IY2X374DRJ7KOZANCNFSM4GHUFOXQ>
> .
>
--
Jesse Lovegren
--
Jesse Lovegren
|
@Clorel I work with @nitinkhosla79 on the python-docx stuff. we are trying your script and observe that this works correctly for nested numbering however, when using bullets (completely or partly) the nesting does not work. (the list shows up as single indent level list not nested) have you faced this issue? |
@jlovegren0 (like the above comment) did you face any issue with bulleting or nested/hybridnested numbering+bulleting? |
@jlovegren0 Can you point out on why list_number(by @Clorel ) is working? Is it because his abstractnum definition has "multileveltype" defined as "multilevel"? |
@jlovegren0 I thought of sending a script that is more clear about the data and its levels being set. please find attached concerned files that demostrate the same numbering.xml for the above:
|
@komawar I think the issue is that MS Word is not strictly adhering to the standard. It says the following about
So the default restarting behavior is obtained by simply omitting the element. In theory this is also possible by specifying a level higher than the current level. So you have "99," which should be valid. However, Word departs from this portion of the normative standard, according to [MS-OI29500]
However, I tried entering "6" but still did not get predicatble behvior (LibreOffice seems to handle the issue fine). Anyways, the surest way to get default restart behvaior is to not specify
|
@jlovegren0 thanks a ton for this analysis! Word seems a bit convoluted, but this explanation gives great clarity on the divergence |
@jlovegren0 hi again, we are trying to use custom style definitions that have color, font, txtFmt, ind, hanging, values. however, restarts, start and hanging aren't what's expected. so, I was trying to create new abstractnumId and new numId associated with them (which are then tied back to styles). However, to get back all of the style information to new abstract num ID is quite complex. We have to manually get these values and copy them to the new abstract num ID definition for example: right now I'm using
Would be really great if:
Also, if I have to get all the level for an existing abstract numId, can I simply use:
Can you point us in the right direction for this? |
@komawar I think what needs to be done is to elaborate the definitions in
I'll try to add other methods as time permits. Just let me know what would be most useful. |
@jlovegren0 I am trying to look into the styles API on python-docx and the best way to get style appears to be
How do we get this |
@komawar
Then
Note that there are numerous paragraph styles based on "Normal," so it's not possible to get a unique style by its |
@komawar One other thing to note when working with paragraph styles is that the |
@jlovegren0 thank you for the awesome tips! |
Hello @jlovegren0 and @komawar, @nitinkhosla79 and all contributing to the MS Word numbering nightmare. I do really appreciate all time you spend to solve these issues. I already read this page conversation and want to say "Thank you all!". I am working on a project and I need to generate several documents based on one template (a simple docx) and restart numbering for each new document (only for "Heading 1" and "Heading 2"). Can you please give some simple guide (python sample) to achieve that? Thank you again. |
Hi @jlovegren0 and @komawar , Would you please showing me how to run your current nested list example. I am running on the version 0.8.10 and it has this issue. |
@trannhutle the nested list example only works if you install the branch
that the pull request discussed in this thread is based on. As far as I
can tell the developer has abandoned this project.
…On Sat, Nov 14, 2020 at 05:11:37AM -0800, trannhutle wrote:
Hi @jlovegren0 and @komawar ,
Would you please showing me how to run your current nested list example. I am running on the version 0.8.10 and it has this issue. `AttributeError: 'CT_Numbering' object has no attribute 'abstractNum_lst'`. Would you mind showing me how to fix it. Thank you so much!

--
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub:
#582 (comment)
|
What's the current state here? We have just come across this issue and it seems like this has become stale? |
Seconded. @jlovegren0 @scanny -- do we have any updates here? |
I had identified a resolution in my PR, though without any higher-level API
changes. I have not been involved with any development efforts since 2020.
…On Fri, Dec 2, 2022, 2:09 PM Sean Bailey ***@***.***> wrote:
What's the current state here? We have just come across this issue and it
seems like this has become stale?
Seconded.
@jlovegren0 <https://github.com/jlovegren0> @scanny
<https://github.com/scanny> -- do we have any updates here?
—
Reply to this email directly, view it on GitHub
<#582 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADFNSQJHXNMGHOF7ZV3SCX3WLJJRDANCNFSM4GHUFOXQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Hi @jlovegren0 , @komawar Thank you for your work on this. I have been working through the code snippets mentioned above. I have been hitting my head against the wall with restarting level 0 numbered list. Do you have a python code snippet that would achieve something like this:
Paragraph or heading section
Any help with this would be GREATLY appreciated. |
Hi @Ridhaa25,
To use this method you need to create an instance of this class with the normal Paragraph (here p) and call the method.
Hope that will help you. |
Hi @msbike Thanks so much for this. This is exactly what I was looking for. Much appreciated |
Thank you for
Thank you! This is what saved me. |
@msbike This snippet causes the numbering to reset to 1 on every element...Am I missing something? |
@bmoore27 There is some library code by @madphysicist described here and with code here that handles the grisly details of list-numbering. It might be worth looking at and perhaps using via his |
Recent plug of the library code that shows a simple usecase:
https://stackoverflow.com/q/77194722/2988730
…On Mon, Oct 2, 2023, 16:24 Steve Canny ***@***.***> wrote:
@bmoore27 <https://github.com/bmoore27> There is some library code by
@madphysicist <https://github.com/madphysicist> described here
<https://haggis.readthedocs.io/en/latest/api.html#haggis.files.docx.list_number>
and with code here
<https://gitlab.com/madphysicist/haggis/-/blob/master/src/haggis/files/docx.py?ref_type=heads#L486>
that handles the grisly details of list-numbering. It might be worth
looking at and perhaps using via his haggis library or just vendoring
into your own code.
—
Reply to this email directly, view it on GitHub
<#582 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABDHGMQBEP5OAPKGQHM4EQTX5MWH7AVCNFSM4GHUFOX2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCNZUGM3TQOBSGUYA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
thanks |
Please consider implementing Ridhaa25's solution to the restart numbering problem. It being an actual feature in word leads me to believe that this would be the fitting place to implement it rather than all of us users' codebases. |
Yes this should be implemented. It is foundation functionality.
…On Thu, Jan 25, 2024, 1:58 PM Baylor Maloney ***@***.***> wrote:
Please consider implementing Ridhaa25's solution to the restart numbering
problem. It being an actual feature in word leads me to believe that this
would be the fitting place to implement it rather than all of us users'
codebases.
—
Reply to this email directly, view it on GitHub
<#582 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AA76IIBYHWBXHHHYV6PLB6LYQLIPZAVCNFSM4GHUFOX2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOJRGEYDMNBZGM3A>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
please, add this function |
Agreed - why is this not being incorporated? I found it to be highly useful.
…On Wed, Feb 7, 2024, 10:56 AM Blezz-tech ***@***.***> wrote:
please, add this function
—
Reply to this email directly, view it on GitHub
<#582 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AA76IID34VZIK53VJLBIHFLYSPE7HAVCNFSM4GHUFOX2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOJTGI3DONRZGM4Q>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
This PR addresses the issue with numbering styles identified on StackOverflow and issues #25 and #122 .
My proposal does not add API support for these issues, but it makes it easier to handle work-arounds for users who are familiar with the numbering system from ISO 29500.
Basically, I just define the following types in the
oxml
submodule:CT_NumPicBullet
CT_AbstractNum
CT_LongHexNumber
ST_LongHexNumber
CT_MultiLevelType
ST_MultiLevelType
CT_Lvl
CT_NumFmt
ST_NumberFormat
CT_LevelSuffix
ST_LevelSuffix
CT_LevelText
CT_LvlLegacy
CT_Num
Once these are defined, and the appropriate declarations are added to
oxml.__init__
so that the parser can recognize them, a user can use the methods exposed by thexmlchemy
submodule.The maintainer has commented in the past that that lag on creating support for numbering is that the standard itself is very byzantine (I agree 100%) and there are some tough design choices for crafting the API. My PR is basically setting up some very low-level support so that more capable developers can look into addressing this within the API.
I have no experience with Open Source projects so I will need help from other community members for qa/qc and testing of the code. However, I have added a detailed write-up to the documentation (contributor guide, numbering section). I'll also be posting a solution to the SE question.