Skip to content
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

Wiki: Headlines are assigned invalid id attributes #5967

Open
suspectpart opened this issue Feb 29, 2024 · 1 comment
Open

Wiki: Headlines are assigned invalid id attributes #5967

suspectpart opened this issue Feb 29, 2024 · 1 comment
Labels

Comments

@suspectpart
Copy link

suspectpart commented Feb 29, 2024

If a wiki markdown file is rendered as an HTML page, the view seahub/wiki/views.py cares about translating the markdown to HTML. All headlines are collected and an outline of clickable navigation items is rendered to the right.

The corresponding <h2> or <h3> elements are assigned id attributes prefixed with user-content- and suffixed with the headline itself, so e.g. a markdown headline of

## How to install

will yield HTML like

<h2 data-slate-node="element" id="user-content-How to install">...</h2>

Regarding the global id attribute, the HTML 5 specification states:

When specified on HTML elements, the id attribute value must be unique amongst all the IDs in the element's tree and must contain at least one character. The value must not contain any ASCII whitespace.

So there are three restrictions for id attributes marked as must and must not, resp.:

  • id must have at least one character (implicitly true in our case due to the user-content- prefix)
  • id must not contain any whitespace (!)
  • id must be unique (!)

The second constraint is violated for headlines containing spaces, as can also be seen with w3c validation:

grafik

Firefox and Chromium seem to be gracefully ignoring it, I have no other browsers for testing.

The third constraint (uniqueness) is violated: If we have the same headline twice, it generates the same id twice, breaking the navigation:

grafik

This breaks the navigation as the duplicate outline items will always jump to the last item with the duplicate id.

Maybe there needs to be some kind of sluggify step that

  • strips leading and trailing whitespace
  • removes characters like emojis
  • replaces all whitespace between words with hyphens
  • adds a running counter (ensuring uniqueness)

So our headline

How to install?

gets sluggified to

user-content-how-to-install-7

?

@freeplant freeplant added the bug label Mar 1, 2024
@freeplant
Copy link
Member

Thanks for reporting the issue. We will solve the problem when we re-work on the Wiki module in this year.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants