-
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 1 commit
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 |
---|---|---|
|
@@ -958,7 +958,14 @@ def depart_seealso(self, node: Element) -> None: | |
def visit_rubric(self, node: Element) -> None: | ||
if len(node) == 1 and node.astext() in ('Footnotes', _('Footnotes')): | ||
raise nodes.SkipNode | ||
self.body.append(r'\subsubsection*{') | ||
tag = { | ||
1: 'section', | ||
2: 'subsection', | ||
3: 'subsubsection', | ||
4: 'paragraph', | ||
5: 'subparagraph', | ||
}.get(node.get('level', 0), 'subsubsection') | ||
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 also an assert here because people are not meant to inject a level deeper than what should be allowed. And possibly add a warning to indicate that a level outside 0-5 (and not 0-6!) is not allowed. Actually, if someone uses level 6, then it's fine in HTML but in LaTeX you would have a subsubsection which may bigger than a subpargraph. So for level 6, it should 'subparagraph' (I'm not sure if the document class has a subparagraph, maybe you should check all levels + non-levels in tests) 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 now uses the "correct" logic, using the a warning for unsupported level values has also been added |
||
self.body.append(rf'\{tag}*{{') | ||
self.context.append('}' + CR) | ||
self.in_title = 1 | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,7 @@ test-markup-rubric | |
|
||
.. rubric:: This is | ||
a multiline rubric | ||
|
||
.. rubric:: A rubric with a heading level | ||
: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: my-class |
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.
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Say
node['level'] = 9
, the warning would be emitted onvisit_
with no opening tag, but the closing</h9>
tag would still be added. This isn't possible using the directive but we should guard against it (and test appropriately).