Skip to content

Commit a039e52

Browse files
authored
Add docutils 0.18 citation/footnote support using CSS grid (readthedocs#1381)
* Add docutils 0.18 citation/footnote support using CSS grid This is a fix for readthedocs#1322 that continues our pattern for HTML5 support using CSS grids, introduced for support for docutils < 0.17 HTML5 support. * Add lots of backreferences to a footnote * Drop brackets from footnote/citation links The brackets seem to be another docutils addition. * Tune grid display for Sphinx 4 and 5 Backrefs have a new styling that drops a lot of punctuation * Bump dependency on docutils to < 0.19 * Small tweak to footnote backrefs row span We don't want to use too large a value here, as some browsers might make explicit rows for us. We can't target -1 because the row count is implicit. * Revert some new styling and use nonbreaking backrefs for now * Downgrade tox * Use before pseudo class to break up backrefs consistently
1 parent 510c620 commit a039e52

File tree

5 files changed

+76
-14
lines changed

5 files changed

+76
-14
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ commands:
1414
default: "17,18,20,21,22,23,24,30,31,32,33,34,35,40,41,42,43,44,45,50,51,52,latest"
1515
steps:
1616
- checkout
17-
- run: pip install --user tox
17+
- run: pip install --user tox~=3.27
1818
- run: tox -e "<<parameters.version>>-sphinx{<<parameters.sphinx-version>>}"
1919
run-build:
2020
description: "Ensure built assets are up to date"

docs/demo/demo.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@ text (generated by processing errors; this one is intentional).
2727
Also with ``sphinx.ext.autodoc``, which I use in the demo, I can link to :class:`test_py_module.test.Foo`.
2828
It will link you right to my code documentation for it.
2929

30-
The default role for interpreted text is `Title Reference`. Here are some explicit interpreted text roles:
30+
The default role for [1]_ interpreted text is `Title Reference`. Here are some explicit interpreted text roles:
3131
a PEP reference (:PEP:`287`); an RFC reference (:RFC:`2822`); a :sub:`subscript`; a :sup:`superscript`;
3232
and explicit roles for :emphasis:`standard` :strong:`inline` :literal:`markup`.
3333

3434
GUI labels are a useful way to indicate that :guilabel:`Some action` is to be taken by the user.
3535
The GUI label should not run over ``line-height`` so as not to :guilabel:`interfere` with text from adjacent lines.
3636

37-
Key-bindings indicate that the read is to press a button on the keyboard or mouse,
37+
Key-bindings indicate that [1]_ the read is to press a button on the keyboard or mouse,
3838
for example :kbd:`MMB` and :kbd:`Shift-MMB`. Another useful markup to indicate a user action
39-
is to use ``menuselection`` this can be used to show short and long menus in software.
39+
is to use ``menuselection`` this [1]_ can [1]_ be [1]_ used [1]_ to [1]_ show [1]_ short [1]_ and long menus in software.
4040
For example, and ``menuselection`` can be seen here that breaks is too long to fit on this line.
4141
:menuselection:`My --> Software --> Some menu --> Some sub menu 1 --> sub menu 2`.
4242

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ packages = sphinx_rtd_theme
4545
python_requires = >=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*
4646
install_requires =
4747
sphinx >=1.6,<6
48-
docutils <0.18
48+
docutils <0.19
4949
tests_require =
5050
pytest
5151

sphinx_rtd_theme/static/css/theme.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/sass/_theme_rst.sass

Lines changed: 70 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,8 @@
281281
top: -0.4em
282282
line-height: 0
283283
font-size: 90%
284+
> span.fn-bracket
285+
display: none
284286

285287
// Horizontal lists have multiple columns; use full width
286288
.hlist
@@ -296,8 +298,9 @@
296298
display: none !important
297299

298300
// The html4 writer outputs the citation and footnotes as a table, and the
299-
// html5 writer outputs these as a definition list. We will use the fairly
300-
// well supported css `grid` attribute to make these back into a table
301+
// html5 writer outputs these as a definition list (docutils < 0.18) or an
302+
// aside/div (docutils 0.18+). We will use the fairly well supported css
303+
// `grid` attributes to make these back into a table
301304
// HTML4 writer
302305
html.writer-html4 &
303306
table.docutils.citation, table.docutils.footnote
@@ -313,13 +316,51 @@
313316
vertical-align: top
314317
// HTML5 writer
315318
html.writer-html5 &
319+
// docutils < 0.18 grid layout. Some spacing is the dl/dt/dd margins
316320
dl.footnote, dl.citation, dl.field-list
317321
display: grid
318-
grid-template-columns: max-content auto
322+
grid-template-columns: auto minmax(80%, 95%)
323+
> dt
324+
display: inline-grid
325+
grid-template-columns: max-content auto
326+
// docutils => 0.18 grid layout
327+
aside.footnote, aside.citation, div.citation
328+
display: grid
329+
// Two any width columns for label and backrefs, a noop column to expand
330+
// to fill the width allocated to the first two columns, and then the
331+
// content column for the paragraphs.
332+
grid-template-columns: auto auto minmax(0.65rem, auto) minmax(40%, 95%)
333+
& > span.label
334+
grid-column-start: 1
335+
grid-column-end: 2
336+
& > span.backrefs
337+
grid-column-start: 2
338+
grid-column-end: 3
339+
grid-row-start: 1
340+
grid-row-end: 3
341+
& > p
342+
grid-column-start: 4
343+
grid-column-end: 5
344+
345+
// Shared backrefs styling for docutils versions
346+
@mixin footnote-backrefs
347+
text-align: left
348+
font-style: italic
349+
margin-left: .65rem
350+
word-break: break-word
351+
word-spacing: -0.1rem
352+
max-width: 5rem
353+
354+
> a
355+
&:not(:first-child)::before
356+
content: " "
357+
word-break: keep-all
358+
359+
// docutils < 0.18 html5 writer styling
360+
dl.footnote, dl.citation, dl.field-list,
361+
margin-bottom: $base-line-height
319362
> dt
320363
padding-left: 1rem
321-
&:after
322-
content: ":"
323364
> dt, > dd
324365
margin-bottom: 0rem
325366
dl.footnote, dl.citation
@@ -330,24 +371,45 @@
330371
word-break: break-all
331372
font-weight: normal
332373
> span.brackets
333-
margin-right: 0.5rem
334374
&:before
335375
content: "["
336376
&:after
337377
content: "]"
338378
> span.fn-backref
339-
font-style: italic
379+
@include footnote-backrefs
340380
> dd
341381
margin: 0rem 0rem 0.5rem 0rem
342382
line-height: 1.2rem
343383
p
344384
font-size: 0.9rem
385+
386+
// docutils => 0.18 html5 writer styling
387+
aside.footnote, aside.citation, div.citation
388+
padding-left: 1rem
389+
padding-right: 1rem
390+
font-size: 0.9rem
391+
line-height: 1.2rem
392+
p
393+
font-size: 0.9rem
394+
line-height: 1.2rem
395+
margin-bottom: $base-line-height / 2
396+
span.backrefs
397+
@include footnote-backrefs
398+
span.label
399+
line-height: 1.2rem
400+
aside.footnote-list, aside.citation-list, div.citation-list
401+
margin-bottom: $base-line-height
402+
345403
dl.option-list
346404
kbd
347405
font-size: 0.9rem
348406
// Both
349407
html.writer-html4 & table.docutils.citation, table.docutils.footnote,
350-
html.writer-html5 & dl.footnote, dl.citation
408+
html.writer-html5 & dl.footnote,
409+
html.writer-html5 & dl.citation,
410+
html.writer-html5 & aside.footnote,
411+
html.writer-html5 & aside.footnote-list aside.footnote,
412+
html.writer-html5 & div.citation-list > div.citation
351413
color: $text-medium
352414
code
353415
color: $gray

0 commit comments

Comments
 (0)