-
-
Notifications
You must be signed in to change notification settings - Fork 125
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
odt export: "Text body" paragraph style is misspelled. #948
Comments
Hmm, in my version of LibreOffice it is called "Text Body" in the GUI but I see now that if I write an I'm happy to take a PR on this if you could correct it and test that it behaves as you expect on your end. The relevant code is in the function |
In the meantime, I cloned the source, installed the missing modules (is lxml really needed? what's wrong with Python3 standard xml.etree?), fixed it locally at line 814 and tested it. This works fine: Unforunately, my Eclipse PyDev PEP8 Auto-formatter removed all your variable alignment, so i guess you would't want a pull request. Just for information, the odf xml tag is like By the way, Happy New Year! |
The primary feature of lxml that is used is the "pretty print" feature. The standard Python XML package didn't do that until recently, and indented XML is essential if the novelWriter projects are to be tracked and diffed with git etc. I'm not sure if lxml and internal package are identical with all the messy stuff I do in the toodt class either. As for autopep, I don't use it. It is far too brutal for most of the code I work on on a daily basis because most people care little for linting. I use flake8 instead, which suggests changes instead. As for the last point about the style names, those are LibreOffice quirks, aren't they? I never understood what the point of the numbers were, so I saw no point in adding them either. LibreOffice changes them anyway if you save the document again from LibreOffice. It adds a lot of new XML too. I mostly followed the Open Document standard as closely as I could manage. Edit: Just to clarify, changing to |
Aha, now I get it. It's not an issue changing this. I've queued this up for the next beta release anyway, which I was planning on doing today but got stuck on some old Fortran code instead. Also, happy new year to you as well :) |
I see. That's okay, but because I try to avoid dependencies to third-party libs, I myself included a small 'xml pretty printer' snippet by Frederik Lundh, which does the trick perfectly well.
This applies to OpenOffice as well. I wrote some scripts for yWriter that generate ODT and ODS, but I went the easy route of template-based generation instead of dealing with all the intricacies of the XML format. I just copied bits and pieces from an existing document and nothing could go wrong. |
I made a PR #949 that should fix the style names. Could you possibly test it before I merge it? Anyway, I know it's fairly simple to write this for XML. I've written the reverse code myself for the previous job. It's on my todo list, but not high priority. lxml is a good library and is almost always installed on Linux PCs. I agree with the minimal dependency approach though. I've dropped a number of dependencies in novelWriter since I started. I even had a spell check implementation based on difflib a while back, but having to distribute dictionaries was annoying. I wrote my own pretty printer for JSON, which will only indent up to a given level. It wastes a lot less space than the default one, and is still diff-friendly. novelWriter/novelwriter/common.py Lines 399 to 443 in 79657a9
|
Well, I checked out the Your JSON processor looks very impressive. Hobby programmer that I am, I used the following standard method instead: |
Thanks for testing it. I did not see duplicate styles in my tree actually, which is why I couldn't reproduce the mentioned issue. Anyway, I'll merge this for 1.6 and do the release tomorrow or when I have the time. As for the JSON indent, yes, the internal library has it, but it lacks the "indent up to level X" feature that I wanted. I'm considering contributing it to the Python library, but the use case may be too narrow for inclusion. On the subject of pretty printing XML, Python added it in 3.9. Since I have to support at least 3.7 and 3.8 for some time still, I have considered just coping it over. If so, I can drop lxml. The code is here: https://github.com/python/cpython/blob/863729e9c6f599286f98ec37c8716e982c4ca9dd/Lib/xml/etree/ElementTree.py#L1165 |
Thank you for fixing so fast.
That's good news. However, myXubuntu distro still comes with Python 3.8. And since I distribute plain Python scripts, I'm keen to make them run with the lowest Python version possible. |
A little off-topic, but I just had an idea about limiting indentation to a certain level: First format it with the standard method, and then delete the excess leading blanks line by line. |
novelWriter works with 3.6 still, and I don't plan to drop that support until I have to. |
Just an update on lxml vs Python xml that we discussed here. I just tested in a branch to drop lxml by copying over the indent function from the Python 3.9 source to work for older versions. That was all fine. However, I quickly found out that another difference between the two implementations is how they handle namespaces. The core XML for novelWriter doesn't use it, so no problem there, but they are all over the place in the ODT writer class. I think lxml handles them a lot better too. The changes that needed to be done to the ODT writer were too great that I thought it was worth the effort, so I think I'll keep lxml for now. It was worth a quick try anyway. |
That's interesting. Well, one thing leads to another. If I understand correctly, with the |
I wrote the ToOdt class to replace the Qt ODT writer which was used before. The Qt implementation is very basic and is missing a lot of things. It doesn't even write text headers. I also wanted to control the formatting of text paragraphs vs metadata, and control page header/footer formatting. |
I see. However, as a user I would rely on the superior formatting capabilities of OpenOffice anyway, so a simple document with an emphasis on clean structuring and the strict application of pargraph/character styles is enough for me in my programs. My yWriter-to-ODT exporter enters e.g. author and title values as metadata, so a header, as generated by novelWriter export, can be added by page style at any time. Of course, this requires that the users know how to handle Open/LibreOffice. One thing that is not so easy to do afterwards is the different formatting of the first paragraph after a heading or blank line (text body) and the following paragraphs (first line indent). The document generator takes care of that for me. |
Please be aware that style identifiers in Open/LibreOffice are case sensitive. In exported odt documents, a "Text Body" style is assigned to the normal text paragraphs. LibreOffice 7 recognizes this as a custom paragraph style. The built-in text body style, which is also translated into other languages, is called, correctly written, "Text body". This is important when assigning templates to documents.
I suggest you to correct this in the toodt module.
Apart from that, I find novelWriter quite appealing. The installation under Xubuntu was without problems.
The text was updated successfully, but these errors were encountered: