dragotin / kraft

Kraft helps to handle your daily quotes and invoices in your small business.
http://volle-kraft-voraus.de
GNU General Public License v2.0
56 stars 18 forks source link

Bug/Feature request: Field editor is allergic to HTML markups #184

Closed noseshimself closed 1 year ago

noseshimself commented 1 year ago

I found a really strange quirk:

As soon as a field (e.g. preText) is starting with valid HTML markup like

<B>This is the first line</B>
This is the second line.
And another line.

opening the document again will get that contents rendered as HTML (without getting access to the mark up). Adding HTML tags on any other line will have no effect. Checking the contents of the database shows that the contents of the fields did not change at all.

As the CSS of the displayed fields seems not to contain white-space: pre-line; line breaks are lost and have to be replaced by
tags (which will "vanish" after saving the changes.

Now the best part of it: If text is added to the beginning of the field all markups are removed and the text is looking like before (minus the HTML tags) (and checking the database shows that all the HTML tags are gone).

I would really like to keep my input the way it was and to be able to modify it; it is working quite well in printed documents.

(For the record: I would still prefer MarkDown. 8-) )

dragotin commented 1 year ago

Looked into this and fixed a couple of things.

Now the state is:

I expect this to be fixed for now, until work happens on #152

noseshimself commented 1 year ago

Great work!

  • You can use html tags in pretext, posttext and the item descriptions.

Working perfectly. And even working in catalogs. Although I don't think you expected it, look at this:

image

It does not work when inserting item templates into documents:

image

and will lose all formatting as soon as it has been transferred:

image

  • They are not rendered in the document previews in Kraft, but in the PDF.

(It's also the reason why I was asking for Markdown -- either write your stuff in a Markdown editor or live with its textual representation.)

  • html tags only work with Weasyprint.

I expected that much; I'm still strongly in favour of making weasyprint the default.

  • You need to enable the html tags in the template file setting {% with 0 as enableHtmlInTexts %} to the value 1.

... in the default gtmpl (template)...

btw. Line 95 to 99 might not be exactly what you want

    {% if enableHtmlInTexts %}
      {{ doc.preText|safe|linebreaks }}
    {% else %}    
      {{ doc.preTextHtml|safe }}
    {% endif %}

I guess you meant {{ doc.preText|linebreaks }}

I have to admit that using the linebreaks filter is a great idea compared to me having to fix that with white-space: pre-line; in my CSS-

  • Expect changes in the CSS of the template needed.

Expect to change the templates themselves, too.

  • Expect funny wrong renderings.

only if you mess up your HTML

I expect this to be fixed for now, until work happens on #152

Tried and tested.

noseshimself commented 1 year ago

ok, that was not correct. As soon as the catalog item is reopened the same thing that happened to document items before will happen here:

image

It's probably necessary to copy the changes to the code for catalogs, too.

dragotin commented 1 year ago

Catalogs should now also be fixed with the commit above.

noseshimself commented 1 year ago

Catalogs are working as expected.