christopher-ramirez / secretary

Take the power of Jinja2 templates to OpenOffice and LibreOffice.
Other
190 stars 48 forks source link

Wrong additional line breaks in markdown #50

Closed j123b567 closed 6 years ago

j123b567 commented 6 years ago

Markdown filter converts the text into pure html so there is no need to play with line breaks. Only one exception should be preformated text.

The implementation of node_to_string() and _node_to_str() is wrong, because it replaces all \n\n with new empty paragraph.

This is big problem for lists, because it adds unavoidable new lines around the list.

Lorem ipsum dolor sit amet, consectetuer adipiscing elit.

* list item 1
* list item 2

This should generate

<text:p text:style-name="Standard">Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</text:p>
<text:list xml:id="list290974027745800426">
<text:list-item><text:p>list item 1</text:p></text:list-item>
<text:list-item><text:p>list item 2</text:p></text:list-item>
</text:list>

but current output is

<text:p text:style-name="Standard">Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</text:p>
<text:p text:style-name="Standard"/>
<text:list xml:id="list290974027745800426"><text:line-break/>
<text:list-item><text:p>list item 1</text:p></text:list-item><text:line-break/>
<text:list-item><text:p>list item 2</text:p></text:list-item><text:line-break/>
</text:list><text:line-break/>

Main problem is unwanted <text:p text:style-name="Standard"/> before the list and <text:line-break/> after the list. Other line breaks are silently ignored.

It can be solved just by removing the replace functions .replace('\n\n', '<text:p text:style-name="Standard"/>' and .replace('\n', '<text:line-break/>') but this change breaks preformated texts. Problem is in condition node.getAttribute('text:style-name') == 'Preformatted_20_Text' that is never true, because it is evaluated only on parent element and not on all its childs.

I would like to provide PR, but I don't know, which version is the future of the project. Development branch is broken and completely different, but seems to be the future. Or should I still post PRs against master branch?

christopher-ramirez commented 6 years ago

Hello! Thanks for you comments

Any PR is welcome. You may patch to current version and then I transfer those to the development branch.

j123b567 commented 6 years ago

There is still something strange for me. In the commit aecd401c6e5e693263c38fadd15f4f465f8431c8 solving issue #47, the solution is completely against my ideas, because it adds .replace('\n', '<text:line-break/>') that I would like to remove. Removing this still solves #47 for python 2.7 and 3.4.