Menu ▾ ▴

#69 Allow sidebar directive to have no title

Default
closed-fixed
nobody
None
5
2021-04-03
2020-03-20
No

The sidebar directive currently requires a positional argument (the "title") due to inheriting from the PseudoSection (https://sourceforge.net/p/docutils/code/HEAD/tree/trunk/docutils/docutils/parsers/rst/directives/body.py#l63). I feel there are many use-cases where a user would want to add a sidebar, but not add a title with it. Would it be possible to make the title an optional argument for the sidebar directive?

Related

Feature Requests: #69

Discussion

  • David Goodger

    David Goodger - 2020-03-20

    Can you provide examples of such use cases in the wild?

     
  • Andreas Mueller

    Andreas Mueller - 2020-05-19

    This would be really great to have for a book I'm working on right now.

     
  • Günter Milde

    Günter Milde - 2020-05-20

    I agree that this would be helpful as a generic container for block elements in the margin
    (side-figures, quotes, annotations, admonitions, ...) in cases where no footnote-like reference/label is
    required. (Otherwise, just style footnotes as sidenotes.)

    Real world example: the nicely designed "Kulturgeschichte der Physik" by K. Simonyi
    https://scilogs.spektrum.de/uhura-uraniae/simonyi-kulturgeschichte-der-physik/
    https://openlibrary.org/books/OL24579545M/A_cultural_history_of_physics

    The following patch is a possible implementation of "sidebar title optionalisation":

    --- a/docutils/docutils/parsers/rst/directives/body.py
    +++ b/docutils/docutils/parsers/rst/directives/body.py
    @@ -36,16 +36,20 @@ class BasePseudoSection(Directive):
    raise self.error('The "%s" directive may not be used within '
    'topics or body elements.' % self.name)
    self.assert_has_content()

    • title_text = self.arguments[0]
    • textnodes, messages = self.state.inline_text(title_text, self.lineno)
    • titles = [nodes.title(title_text, '', *textnodes)]
    • Sidebar uses this code.

    • if 'subtitle' in self.options:
    • textnodes, more_messages = self.state.inline_text(
    • self.options['subtitle'], self.lineno)
    • titles.append(nodes.subtitle(self.options['subtitle'], '',
    • *textnodes))
    • messages.extend(more_messages)
    • if self.arguments: # title (in sidebars optional)
    • title_text = self.arguments[0]
    • textnodes, messages = self.state.inline_text(title_text, self.lineno)
    • titles = [nodes.title(title_text, '', *textnodes)]
    • Sidebar uses this code.

    • if 'subtitle' in self.options:
    • textnodes, more_messages = self.state.inline_text(
    • self.options['subtitle'], self.lineno)
    • titles.append(nodes.subtitle(self.options['subtitle'], '',
    • *textnodes))
    • messages.extend(more_messages)
    • else:
    • titles = []
    • messages = []
      text = '\n'.join(self.content)
      node = self.node_class(text, *(titles + messages))
      node['classes'] += self.options.get('class', [])
      @@ -64,6 +68,8 @@ class Sidebar(BasePseudoSection):

      node_class = nodes.sidebar

    • required_arguments = 0

    • optional_arguments = 1
      option_spec = BasePseudoSection.option_spec.copy()
      option_spec['subtitle'] = directives.unchanged_required

    @@ -71,6 +77,10 @@ class Sidebar(BasePseudoSection):
    if isinstance(self.state_machine.node, nodes.sidebar):
    raise self.error('The "%s" directive may not be used within a '
    'sidebar element.' % self.name)

    • if 'subtitle' in self.options and not self.arguments:
    • raise self.error('The "subtitle" option may not be used '
    • 'without a title.')
      +
      return BasePseudoSection.run(self)
     
  • Günter Milde

    Günter Milde - 2020-07-10
    • status: open --> open-fixed
     
  • Günter Milde

    Günter Milde - 2020-07-10

    Solved in r8524.
    Thank you for the suggestion.

     
    • Chris Holdgraf

      Chris Holdgraf - 2020-07-12

      wow, thanks so much! That's really exciting :-)

       
  • Günter Milde

    Günter Milde - 2021-04-03
    • status: open-fixed --> closed-fixed
     
  • Günter Milde

    Günter Milde - 2021-04-03

    Fixed in Docutils 0.17.
    Thank you for the suggestion.

     

Log in to post a comment.