-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
[rst] Add level
option to rubric
directive
#12506
Changes from all commits
50c997d
7236ad3
82eb25c
0b7bf1e
1177e5b
4432186
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -373,8 +373,18 @@ units as well as normal text. | |
|
||
.. rst:directive:: .. rubric:: title | ||
|
||
This directive creates a paragraph heading that is not used to create a | ||
table of contents node. | ||
A rubric is like an informal heading that doesn't correspond to the document's structure, | ||
i.e. it does not create a table of contents node. | ||
|
||
.. rst:directive:option:: level: n | ||
:type: number from 1 to 6 | ||
Comment on lines
+379
to
+380
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think |
||
|
||
.. versionadded:: 7.4 | ||
|
||
Use this option to specify the heading level of the rubric. | ||
In this case the rubric will be rendered as ``<h1>`` to ``<h6>`` for HTML output, | ||
or as the corresponding non-numbered sectioning command for LaTeX | ||
(see :confval:`latex_toplevel_sectioning`). | ||
|
||
.. note:: | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -509,6 +509,30 @@ def depart_title(self, node: Element) -> None: | |
|
||
super().depart_title(node) | ||
|
||
# overwritten | ||
def visit_rubric(self, node: Element) -> None: | ||
if "level" in node: | ||
level = node["level"] | ||
if level in (1, 2, 3, 4, 5, 6): | ||
self.body.append(self.starttag(node, f'h{level}', '', CLASS='rubric')) | ||
else: | ||
logger.warning( | ||
__('unsupported rubric heading level: %s'), | ||
level, | ||
type='html', | ||
location=node | ||
) | ||
super().visit_rubric(node) | ||
else: | ||
super().visit_rubric(node) | ||
|
||
# overwritten | ||
def depart_rubric(self, node: Element) -> None: | ||
if level := node.get("level"): | ||
self.body.append(f'</h{level}>\n') | ||
else: | ||
Comment on lines
+531
to
+533
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add an assert on the allowed level (to avoid people injecting invalid attributes). And make sure that it's also of type int. The level should not be at most 6 since otherwise it's not a valid HTML tag. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a warning for unsupported level values has been added There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Say |
||
super().depart_rubric(node) | ||
|
||
# overwritten | ||
def visit_literal_block(self, node: Element) -> None: | ||
if node.rawsource != node.astext(): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
latex_documents = [ | ||
('index', 'test.tex', 'The basic Sphinx documentation for testing', 'Sphinx', 'report') | ||
] | ||
latex_toplevel_sectioning = 'section' |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,35 @@ test-markup-rubric | |
|
||
.. rubric:: This is | ||
a multiline rubric | ||
|
||
.. rubric:: A rubric with a class | ||
:class: myclass | ||
|
||
.. rubric:: A rubric with a heading level 1 | ||
:level: 1 | ||
:class: myclass | ||
|
||
.. rubric:: A rubric with a heading level 2 | ||
:level: 2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check levels 1 to 6 and invalid levels as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
:class: myclass | ||
|
||
.. rubric:: A rubric with a heading level 3 | ||
:level: 3 | ||
:class: myclass | ||
|
||
.. rubric:: A rubric with a heading level 4 | ||
:level: 4 | ||
:class: myclass | ||
|
||
.. rubric:: A rubric with a heading level 5 | ||
:level: 5 | ||
:class: myclass | ||
|
||
.. rubric:: A rubric with a heading level 6 | ||
:level: 6 | ||
:class: myclass | ||
|
||
.. rubric:: A rubric with a heading level 7 | ||
:level: 7 | ||
:class: myclass | ||
Comment on lines
+36
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This only tests that the directive is rejecting numbers outwith 1-6, we need to test the writers independently. |
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should go at the end (chronological ordering)