fsr-de / myHPI

Django/Wagtail page serving myhpi.de
https://myhpi.de
11 stars 11 forks source link

List of abbreviations rendered to pages ending with a table #458

Closed lukasrad02 closed 5 months ago

lukasrad02 commented 6 months ago

When a page ends with a table, the list of abbreviations is visible on the rendered page as markdown.

Steps to reproduce

  1. Create an abbreviation explanation for the abbreviation "demo" (Wagtail Admin → Settings → Abbreviation Explanations)
  2. Create a new information page or minutes page
  3. Add the following body text as markdown:
demo

| test | test |
|------|------|
| test | test |

Expected result

The rendered page ends with the table. When hovering the "demo" text, the explanation is shown in a tooltip.

Actual result

The rendered page ends with *[demo]: explanation of demo below the table and no explanation for "demo" is shown on hover.

Workarounds and further information

Trailing spaces or newlines following the table don't matter, but adding any other content behind the table fixes the issue.

The table rendering differs depending on whether it is the last element or not. In the first case, it is using the full page with,. while in the latter case, it only as wide as its contents:

A table without any following text in the markdown, using full page width

A table with some following text in the markdown, not using full page width

It seems like we're using https://pypi.org/project/Markdown/ to transform the markdown to HTML (however, I could not find this or any other markdown compiler in the pyproject, did I miss something?). The python library refers to https://daringfireball.net/projects/markdown/syntax for a list of supported markdown features. This feature list neither includes tables nor abbreviations. Do we have some custom code for this I just did not find?

jeriox commented 5 months ago

We are using https://github.com/torchbox/wagtail-markdown which in turn actually uses the Markdown compiler that you linked to. Abbreviations are a built-in extension as documented in https://python-markdown.github.io/extensions/abbreviations/

The way this works is by appending all of the abbreviations to the body of the page. The markdown renderer will then take the whole thing and place the abbreviations in the generated HTML. If the block cannot be parsed correctly, they will be left as-is and thats why you see them in the raw form at the end of the page. In my experience this only happens if the markdown is invalid. When looking at https://python-markdown.github.io/extensions/tables/ I guess that your example uses three vertical separators whereas the docs only use one in the middle

lukasrad02 commented 5 months ago

In my experience this only happens if the markdown is invalid. When looking at https://python-markdown.github.io/extensions/tables/ I guess that your example uses three vertical separators whereas the docs only use one in the middle

Same issue when using the example from the docs (copied as-is):

First Header  | Second Header
------------- | -------------
Content Cell  | Content Cell
Content Cell  | Content Cell

Screenshot of the rendered markdown from above. Abbreviations are printed bewlow the table which is not expected.

Aside from that, column separators at the outside (as in my first example) should be valid to, as the python docs refer to https://michelf.ca/projects/php-markdown/extra/#table for the syntax and this page states:

If you wish, you can add a leading and tailing pipe to each line of the table. Use the form that you like. As an illustration, this will give the same result as above:

| First Header  | Second Header |
| ------------- | ------------- |
| Content Cell  | Content Cell  |
| Content Cell  | Content Cell  |

(This markdown code does not work either)

jeriox commented 5 months ago

Interesting. Then I'm currently out of ideas and someone needs to debug this properly