peter88213 / nv_yw7

yw7 file import/export plugin for novelibre.
GNU General Public License v3.0
0 stars 0 forks source link

Nested bold and italic tags may produce malformed XML #1

Closed JPhB closed 1 month ago

JPhB commented 1 month ago

Application/script

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:

image

To Reproduce Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. See error

Expected behavior A clear and concise description of what you expected to happen.

Execution environment (please complete the following information):

Additional context Add any other context about the problem here.

peter88213 commented 1 month ago

To investigate this, I need more information, such as the _nvyw7 version number. Please update to the latest novelibre and _nvyw7 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.

JPhB commented 1 month ago

I'm using nv 4.9.3 and the nv_yw7 installed version is 4.2.8. Here's the top of my YW7 file. <?xml version="1.0" encoding="utf-8"?>

             7         7.1.2.4         2024-09-18 22:29:14         <![CDATA[]]>                                                                        2024-09-18         0  I also thought the huge column number shown in the error message was strange. yWriter loads the project with no problems. I'm using Windows 7 though. Thanks, Jean
JPhB commented 1 month ago

PS: let me add that pywriter has no problem with that project file.

peter88213 commented 1 month ago

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. _nvyw7 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.

peter88213 commented 1 month ago

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

peter88213 commented 1 month ago

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 = [
                ('&', '&amp;'),
                ('>', '&gt;'),
                ('<', '&lt;'),
                ("'", '&apos;'),
                ('"', '&quot;'),
                ('\n', '</p><p>'),
                ('[i]', '<em>'),
                ('[/i]', '</em>'),
                ('[b]', '<strong>'),
                ('[/b]', '</strong>'),
                ]
            for nv, od in xmlReplacements:
                text = text.replace(nv, od)
JPhB commented 1 month ago

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.

peter88213 commented 1 month ago

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.

peter88213 commented 1 month ago

Alternative solution approaches to fix the bug:

JPhB commented 1 month ago

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.

peter88213 commented 1 month ago

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.

JPhB commented 1 month ago

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).

peter88213 commented 1 month ago

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.

peter88213 commented 1 month ago

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.

JPhB commented 1 month ago

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.

JPhB commented 1 month ago

I tried yWOO. It works very well but language tags are added to some chapter titles and scene contents.

Header 1 titles show in bold, header 2 do not (novelyst shows the proper hierarchical structure).

[There is no Discussion tab on the yWOO Github page]

image

peter88213 commented 1 month ago

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.