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

Empty space in lists above last indented block #168

Closed
dwu opened this Issue May 16, 2016 · 15 comments

Comments

Projects
None yet
2 participants
@dwu
Contributor

dwu commented May 16, 2016

QOwnNotes is a really impressive piece of software in terms of both features and development speed. Thank's a lot for developing it!

While importing a number of my previous notes in QOwnNotes I noticed a small inconsitency in the markdown rendering behavior.

If the last bullet of a bullet list is indented, there's an additional empty space added above the first line of the indented items.

empty_space

If the last bullet of a bullet list is not indented, the indented items are rendered as expected without the empty space being added.

no_empty_space

@pbek

This comment has been minimized.

Owner

pbek commented May 16, 2016

Thanks a lot for your kind words, @dwu!
Could you please also provide an example text (as text, not image).

@dwu

This comment has been minimized.

Contributor

dwu commented May 16, 2016

Thanks for the quick reply. Here the examples as text.

Empty space:

- Some text (level 1)
    - Some text
    - Some text
- Some text (level 1)
    - Empty space above this line
    - Some text

No empty space:

- Some text (level 1)
    - Some text
    - Some text
- Some text (level 1)
    - No empty space above this line
    - Some text
- Some text (level 1)
@pbek

This comment has been minimized.

Owner

pbek commented May 16, 2016

Sadly the generated HTML block looks the same in both cases, although it gets differently rendered in the preview. I could not get around it by means of modifying HTML or CSS. It seems like an other quirk of the QTextEdit widget.

I will only be able to fix that if we use a full blown browser as preview, but that is currently very inconvenient for a lot of technical reasons... I'll put this issue on my list.
Thanks for reporting.

@pbek pbek added the wontfix label May 16, 2016

@pbek pbek closed this May 16, 2016

@dwu

This comment has been minimized.

Contributor

dwu commented May 16, 2016

I guess you're right. Browsing through the open bugs for QTextEdit I found the following reports, both reported in 2013.

@pbek

This comment has been minimized.

Owner

pbek commented May 16, 2016

Oh well... That's three years ago. :)
Thank you for researching!

@dwu

This comment has been minimized.

Contributor

dwu commented May 16, 2016

As the incorrect rendering is also present in exported PDFs with rendered markdown and I don't expect the bug in QTextWidget getting fixed anytime soon, would you be open for a feature request for exporting a note's generated HTML representation to a file?

This way one could open the generated HTML in another application and convert to PDF from there.

@pbek

This comment has been minimized.

Owner

pbek commented May 16, 2016

I could write a scripting hook where you could alter the generated HTML as soon it gets generated (or do with it what you like).
But maybe you would have to take care about image sources in that HTML if you would want to view that HTML in an other program.

@dwu

This comment has been minimized.

Contributor

dwu commented May 16, 2016

That sounds like an interesting idea. However, I expect that the hook would be called each time the preview is updated. This seems a bit too often for my use case as I'd need the export only for publishing purposes.

Are you planning to allow manually triggering script execution from the UI sometime in the future (for example via a script menu)? In that case, being able to access the current note's HTML preview content would indeed be a nice addition to the scripting API for implementing customized exporters (bundling linked media in HTML exports, link rewriting, etc.).

As a workaround, publishing the note from its Markdown source via pandoc to either HTML or PDF works nicely once the "file://" part of image sources is stripped.

@pbek

This comment has been minimized.

Owner

pbek commented May 16, 2016

export only for publishing purposes

so what would you need? a menu entry to export the raw html that was used in the preview?

allow manually triggering

hm, maybe a special JS function in the QML that would be registered in the menu somehow... there are a few difficulties, but I guess it would work

@dwu

This comment has been minimized.

Contributor

dwu commented May 16, 2016

so what would you need? a menu entry to export the raw html that was used in the preview?

Yes, that would be great.

@pbek

This comment has been minimized.

Owner

pbek commented May 16, 2016

done in the next release:

  • there now is a new menu entry for exporting the HTML of your note preview
@pbek

This comment has been minimized.

Owner

pbek commented May 16, 2016

16.05.13 is now released

@dwu

This comment has been minimized.

Contributor

dwu commented May 17, 2016

After playing a bit with the export feature and skimming through the generated HTML documents I've noticed three issues:

  1. Non-ASCII characters (for example German Umlaute) are not rendered correctly. Adding a <meta charset="utf-8"> header fixes this issue.
  2. The export only works if the note preview is visible. Otherwise changes to the note content are not exported.
  3. The generated HTML looks rather messy. :) In addition the HTML for multi-level lists is not rendered correctly in the browsers I've tried because different indent levels are not generated as nested <ul> elements but rather as siblings with a different value in the -qt-list-indent-attribute. Here's an example

Markdown:

- Some text (level 1)
- Some text (level 1)
    - Empty space above this line
    - Some text

Generated HTML without headers etc.:

<ul style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;"><li style=" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Some text (level 1)</li>
<li style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Some text (level 1) </li></ul>
<ul style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 2;"><li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Empty space above this line</li>
<li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Some text</li></ul>

I've looked at the current implementation of the export feature and the code used to convert from Markdown to HTML. Would it also be an option for you to export the HTML generated by the Markdown converter directly, i.e. skip the note preview completely?

The HTML generated by the Markdown converter looks much cleaner and renders correctly the browsers I've tried. In addition this would solve issue 2 where the note preview has to be visible to get an export of the current note content.

Here's an example of the HTML created with currentNote.toMarkdownHtml(...) for the same Markdown snipped above:

<ul>
<li>Some text (level 1)</li>
<li>Some text (level 1)

<ul>
<li>Empty space above this line</li>
<li>Some text</li>
</ul></li>
</ul>

You can find a quick proof-of-concept implementation here (basically I've only extracted getMaxImageWidth() as a function and changed the HTML creation to currentNote.toMarkdownHtml(notesPath, getMaxImageWidth()): https://github.com/dwu/QOwnNotes/commit/455d1775eaac1d6ea35a8f93bfa7061ab9b8b9d6

Currently user-defined fonts are ignored, also no detailed tests with more complex Markdown documents so far.

@pbek

This comment has been minimized.

Owner

pbek commented May 18, 2016

@dwu your changes are looking good! I think it is safe to add the <meta charset="utf-8"/> to the toMarkdownHtml method directly. If you want to make a pull request from your changes (what I would love) can you please make it to the develop branch, master is just for releases.

@pbek

This comment has been minimized.

Owner

pbek commented May 18, 2016

In version 16.05.15 there now also is:

  • a new scripting hook noteToMarkdownHtmlHook(note, html)
    that is called when the markdown html of a note is generated
    (for Issue #164)
    • it allows you to modify this html
    • this is for example called before by the note preview
    • there is an example call in
      example.qml

...more to play around with ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment