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

The HTML5 writer should render hlist nodes with CSS columns #10754

Open
Screwtapello opened this issue Aug 5, 2022 · 1 comment
Open

The HTML5 writer should render hlist nodes with CSS columns #10754

Screwtapello opened this issue Aug 5, 2022 · 1 comment
Labels
builder:html type:enhancement enhance or introduce a new feature

Comments

@Screwtapello
Copy link

Currently, Sphinx includes the hlist directive which produces a bulleted list split into multiple columns. Internally, it splits the list up into as many equal-sized pieces as there are columns. The HTML5 writer renders this by constructing a one-row table with a list in each column:

def visit_hlist(self, node: Element) -> None:
self.body.append('<table class="hlist"><tr>')
def depart_hlist(self, node: Element) -> None:
self.body.append('</tr></table>\n')
def visit_hlistcol(self, node: Element) -> None:
self.body.append('<td>')
def depart_hlistcol(self, node: Element) -> None:
self.body.append('</td>')

The problem with this approach is that it only checks that each column has the same number of items. If some items are a little long and get wrapped across two lines at some zoom levels (or with some fonts, or on some platforms) the whole list can look quite messy. In addition, there's probably accessibility issues (screen readers, etc.) when one list is presented as four separate lists.

But browsers already have a solution to this problem, in the form of the column-count CSS property. Instead of a complex structure of table and lists, Sphinx could just change the typical bulleted-list output from <ul> to <ul style="column-count: 3"> (or whatever the value of the :columns: option is). The Sphinx code would be simpler since it doesn't have to slice up the list, it would be more accessible since a single list in the source would be a single list in the HTML, and it would be robust in the face of runtime layout because the runtime layout engine is doing the work.

@Screwtapello Screwtapello added the type:enhancement enhance or introduce a new feature label Aug 5, 2022
@AA-Turner AA-Turner added this to the some future version milestone Sep 29, 2022
@eudoxos
Copy link

eudoxos commented May 14, 2024

Besides the advantages you mentioned: a few simple CSS rules would make the hlist adaptive in terms of the number of columns (i.e. less columns on narrower screens).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
builder:html type:enhancement enhance or introduce a new feature
Projects
None yet
Development

No branches or pull requests

4 participants