spatialaudio / nbsphinx

:ledger: Sphinx source parser for Jupyter notebooks
https://nbsphinx.readthedocs.io/
MIT License
451 stars 130 forks source link

text wrap for tables #649

Open aiqc opened 2 years ago

aiqc commented 2 years ago

Wrapping markdown tables seems like a multi-theme problem with no quick css fixes. Is this something that can be addressed centrally through nbsphinx?

image

mgeier commented 2 years ago

There is already some table-specific CSS:

https://github.com/spatialaudio/nbsphinx/blob/895b8fb2685cb81889a476c692687865a13ee4c6/src/nbsphinx.py#L658-L698

We could of course add more stuff there.

Any suggestions for concrete CSS additions?

aiqc commented 2 years ago

thanks for sharing the css.

Hmm white-space: normal; is already there

white-space: nowrap; must be getting set in themes. Hard to imagine that most themes are breaking this though.

I hesitate to say that white-space: normal !important; is a good idea.

aiqc commented 2 years ago

It seems markdown injects a colgroup based on th length

The widths of the colgroups are overridable: https://stackoverflow.com/a/72577950/5739514

Again, I don't know if it would make sense to change this behavior.

mgeier commented 2 years ago

Hmm white-space: normal; is already there

I just realized that the CSS I mentioned above is only applied to outputs of code cells. You are probably talking about tables within Markdown cells?

It would probably help avoid misunderstandings if you could provide a minimal reproducible example.

aiqc commented 2 years ago

ipynb json for a markdown table with bearing enough content that it should wrap:

{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "c5390647-3257-4049-b381-165f64d92d17",
   "metadata": {},
   "source": [
    "# Markdown Table"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "30aad6c8-ff25-4fb0-836c-0ca7f7f1af20",
   "metadata": {},
   "source": [
    "Col1 | Col2 | Col3 | Col4\n",
    "--- | --- | --- | ---\n",
    "attribute1 | str | Required | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\n",
    "attribute2 | bool | True | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\n",
    "attribute3 | int | None | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\n",
    "attribute4 | float | None | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}

Without overriding whitespace image

Overriding whitespace image