numpydoc icon indicating copy to clipboard operation
numpydoc copied to clipboard

WIP: Try wrapping section content in html classes

Open jnothman opened this issue 8 years ago • 2 comments

Trying to make sections stylable (i.e. putting them in HTML elements with specified classes, like numpydoc-section and numpydoc-{parameters,attributes,...}) turns out to be quite hard:

  • wrapping section headings breaks parsing of field lists, so we focus on section content (even though tooltips and link anchors on section headings would be really useful IMO)
  • using .. rst-class:: works sometimes, but labels every paragraph in an unstructured section, and does not wrap autosummary tables
  • wrapping in .. container:: (the right way to do it) adds the class container to the HTML div (this is hard-wired into docutils), which interacts with bootstrap.css
  • wrapping in .. raw:: html \n\n <div class="...."> sometimes works, sometimes doesn't. It seems that docutils sometimes closes the opened <div> automatically before the following content (this happens for definition lists, but not for an autosummary table). Looks like a bug, but I've not yet understood where it's coming from.
  • there might be a doctree-level solution, but I imagine in some cases it would involve a container node, raising the same issue as above.

This PR uses rst-class to add a class to parameter listings, as a proof of concept. Better would be to use .. container:: or equivalent (I've tried creating my own directive, but copying the existing container class doesn't help because all the writing logic is hardwired in docutils), but we need to work out a way to disable default .container styling from bootstrap, which in scipy central's theme sets width: 80%.

I thought this would be more straightforward. I'm not convinced anything in reST is straightforward.

Related: #88

jnothman avatar Nov 15 '17 08:11 jnothman

wrapping in .. container:: (the right way to do it) adds the class container to the HTML div (this is hard-wired into docutils), which interacts with bootstrap.css

I wonder if those of us who use sphinx-bootstrap-theme should heed this advice:

https://sourceforge.net/p/docutils/bugs/267/#6d70

In particular, we could build into sphinx-bootstrap-theme CSS the necessary overrides to undo the docutils.container "damage" to the Boostrap container class.

Then this PR would be much simpler, right?

larsoner avatar Apr 02 '19 14:04 larsoner

... oh wait, the problem is that we would have to undo all bootstrap-related stuff to make the "container" class that gets added be a no-op in this situation. Never mind :(

larsoner avatar Apr 02 '19 14:04 larsoner