Nested bold and italic tags may produce malformed XML
Closed this issue · 17 comments
Application/script
- Version [e.g. v0.1.0]
Describe the bug
When I tried creating a new Novelibre project (4.9.3, Windows 7) from a YW7 file, I got a mismatched tag error:
To Reproduce
Steps to reproduce the behavior:
- Go to '...'
- Click on '....'
- See error
Expected behavior
A clear and concise description of what you expected to happen.
Execution environment (please complete the following information):
- Python Version [e.g. 3.6]
- OS: [e.g. Windows 10]
Additional context
Add any other context about the problem here.
To investigate this, I need more information, such as the nv_yw7 version number. Please update to the latest novelibre and nv_yw7 version and see whether the problem persists.
If so, I need a minimal example yw7 file with which I can reproduce the error.
In fact, there have been some xml incompatibilities with yw7 files that have led to several updates recently. On the other hand, the error message in your screenshot says "line1, column 11316", which is very strange. This looks like your yw7 is not broken down into lines.
Can you load your yw7 file into a text editor and look about that? Is yWriter loading this project file without problems?
Actually, the file's beginning should look like this:
<?xml version="1.0" encoding="utf-8"?>
<YWRITER7>
<PROJECT>
<Ver>7</Ver>
<SavedWith>7.1.2.4</SavedWith>
<SavedOn>2024-09-19 16:27:50</SavedOn>
As you can see, the first line has 38 columns here.
PS: let me add that pywriter has no problem with that project file.
While I was trying to reproduce the error, I came across another bug that only occurs in connection with novelibre's predecessor application. So the latest nv_yw7 release ist version 4.2.10 now.
Which pywriter application do you mean? You know, pywriter is the name of my Python library for yw7 processing. nv_yw7 is based on pyWriter, but needed a lot of adaptions to the novelibre data model.
Have you looked into your project directory? Is there possibly a .novx file? If so, the error message might not refer to the yw7 file, but to the novx file already generated from the yw7. From version 4.9.1 to version 4.9.5, I made some modifications on the novx file processing, so there's a chance that the latest novelibre version might work for you.
If not, I need some yw7 file that causes the error for you to reproduce it.
Thanks for your help.
Thanks for the file. I just deleted your comment with the attachment to protect your project from becoming public.
I can reproduce the error now. It is caused by nesting bold and italics in a way that works with yWriter, but produces malformed XML when converted to the novx format. Since novelyst uses the original yWriter markup, this causes no error there.
I will look into this the next days; for now you can edit your yw7 file with a text editor and delete the [i]
and [/i]
tags.
Thanks for your support,
Peter
This is the yw7 code that causes the conversion error:
<SceneContent><![CDATA[[b][i]text[/b][/i]]]></SceneContent>
It is being converted to malformed XML due to the all too simple replacement method in Yw7File._convert_to_novx():
xmlReplacements = [
('&', '&'),
('>', '>'),
('<', '<'),
("'", '''),
('"', '"'),
('\n', '</p><p>'),
('[i]', '<em>'),
('[/i]', '</em>'),
('[b]', '<strong>'),
('[/b]', '</strong>'),
]
for nv, od in xmlReplacements:
text = text.replace(nv, od)
Things work now. Thanks. I copied headers form an .rtf file where they are bold italic, but that formatting doesn't show in yW.
novelibre looks very much like novelyst, but the left panel is much wider.
I installed the Matrix plugin but it doesn't show in Tools.
If a newly installed plugin doesn't show up in the user interface, you may want to take a look at the plugin manager.
F1
should then open the help page.
The latest nv_matrix plugin requires novelibre version 4.11.
Alternative solution approaches to fix the bug:
- Use regular expressions.
- Implement a SAX parser for post-processing the XML code created using the replacement method.
Updated my version and got the Matrix working (and the updater!).
It looks nice.
I was looking for an editor plugin but I guess I'd have to install LibreOffice or OpenOffice Writer.
In the meantime, I wrote a fix for the bold/italics nesting problem. I guess, it needs some testing before I can release it.
By the way, your yw7 file contains text passages with different encodings, so that a lot of non-ASCII characters are lost. This also applies to yWriter. I suspect, this is due to copying/pasting from RTF?
novelibre is meant to be used in connection with LibreOffice or OpenOffice Writer, see the online documentation.
For general feedback or questions, you can start a thread in the novelibre "discussions" section to keep this thread on topic.
Yes, it was a quick and dirty import from an .rtf file with headings. When I tried importing using Import and Split, the text (in Courier Prime font) came up all in italics and instead of apostrophes and accents I got question marks. So I ended up doing it by hand, creating scenes with headings, and pasting content for some of them.
The main reason I use yWriter is the Storyboard, even though it has problems (I raised 2 yWriter issues on the Google group but they were not answered).
Be aware, novelibre is not a yWriter replacement; its basic concept and workflow are quite different. novelibre is meant for LibreOffice power users, since most of the layout and formatting is to be done in LibreOffice (or OpenOffice), and you should be familiar with its concept of document templates and style sheets.
yWriter, in contrast, is self-contained as a writing tool, and optimized for a workflow with LaTeX and epub output.
At this time, yWriter seems to be undergoing a revision process, mainly to enable themes, and not all functions are running smoothly again. It must be acknowledged that Simon not only develops yWriter, but also writes and publishes novels.
There is also a theme switcher plugin for novelibre, but it is very limited and I would only recommend it as a fallback for Linux users.
Yes, it was a quick and dirty import from an .rtf file with headings. When I tried importing using Import and Split, the text (in Courier Prime font) came up all in italics and instead of apostrophes and accents I got question marks. So I ended up doing it by hand, creating scenes with headings, and pasting content for some of them.
yWriter's RTF import seems to have problems with special characters, depending on the application that saved the file. You can try to load your RTF file into LibreOffice, convert it into the ODT format, and then generate a yWriter project using either the yw-cnv extension or the yW2OO standalone converter. Be sure to read the docs before.
Points taken, even though just about every issues appears to get several answers.
I don't really care about Themes. The only reason I wanted to change the default is that when you have many scenes you can't see the vertical slider.
Well, I noticed that the issue tracker was not activated in the yW2OO repository, sorry.
Now I opened an issue there to keep this thread on topic.