dzhu / rstfmt

A formatter for reStructuredText
MIT License
71 stars 19 forks source link

Unknown directive type "glossary" #15

Open Hoteryoung opened 3 years ago

Hoteryoung commented 3 years ago

Sphinx supports the directive type "glossary": https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#directive-glossary

But rstfmt reports a traceback about it:

$ rstfmt rstfmt_issue_glossary.rst                                                                                                  3.8.3
:5: (ERROR/3) Unknown directive type "glossary".

.. glossary::

   term_a
      This is term a.

   term_b
      This is term b.

Traceback (most recent call last):
  File "/Users/yanghaote/.pyenv/versions/3.8.3/bin/rstfmt", line 10, in <module>
    sys.exit(main())
  File "/Users/yanghaote/.pyenv/versions/3.8.3/Python.framework/Versions/3.8/lib/python3.8/site-packages/rstfmt/__main__.py", line 46, in main
    doc = rstfmt.parse_string(inp)
  File "/Users/yanghaote/.pyenv/versions/3.8.3/Python.framework/Versions/3.8/lib/python3.8/site-packages/rstfmt/rstfmt.py", line 750, in parse_string
    parser.parse(s, doc)
  File "/Users/yanghaote/.pyenv/versions/3.8.3/Python.framework/Versions/3.8/lib/python3.8/site-packages/docutils/parsers/rst/__init__.py", line 191, in parse
    self.statemachine.run(inputlines, document, inliner=self.inliner)
  File "/Users/yanghaote/.pyenv/versions/3.8.3/Python.framework/Versions/3.8/lib/python3.8/site-packages/docutils/parsers/rst/states.py", line 170, in run
    results = StateMachineWS.run(self, input_lines, input_offset,
  File "/Users/yanghaote/.pyenv/versions/3.8.3/Python.framework/Versions/3.8/lib/python3.8/site-packages/docutils/statemachine.py", line 241, in run
    context, next_state, result = self.check_line(
  File "/Users/yanghaote/.pyenv/versions/3.8.3/Python.framework/Versions/3.8/lib/python3.8/site-packages/docutils/statemachine.py", line 459, in check_line
    return method(match, context, next_state)
  File "/Users/yanghaote/.pyenv/versions/3.8.3/Python.framework/Versions/3.8/lib/python3.8/site-packages/docutils/parsers/rst/states.py", line 3005, in text
    self.section(title.lstrip(), source, style, lineno + 1, messages)
  File "/Users/yanghaote/.pyenv/versions/3.8.3/Python.framework/Versions/3.8/lib/python3.8/site-packages/docutils/parsers/rst/states.py", line 327, in section
    self.new_subsection(title, lineno, messages)
  File "/Users/yanghaote/.pyenv/versions/3.8.3/Python.framework/Versions/3.8/lib/python3.8/site-packages/docutils/parsers/rst/states.py", line 393, in new_subsection
    newabsoffset = self.nested_parse(
  File "/Users/yanghaote/.pyenv/versions/3.8.3/Python.framework/Versions/3.8/lib/python3.8/site-packages/docutils/parsers/rst/states.py", line 281, in nested_parse
    state_machine.run(block, input_offset, memo=self.memo,
  File "/Users/yanghaote/.pyenv/versions/3.8.3/Python.framework/Versions/3.8/lib/python3.8/site-packages/docutils/parsers/rst/states.py", line 196, in run
    results = StateMachineWS.run(self, input_lines, input_offset)
  File "/Users/yanghaote/.pyenv/versions/3.8.3/Python.framework/Versions/3.8/lib/python3.8/site-packages/docutils/statemachine.py", line 241, in run
    context, next_state, result = self.check_line(
  File "/Users/yanghaote/.pyenv/versions/3.8.3/Python.framework/Versions/3.8/lib/python3.8/site-packages/docutils/statemachine.py", line 459, in check_line
    return method(match, context, next_state)
  File "/Users/yanghaote/.pyenv/versions/3.8.3/Python.framework/Versions/3.8/lib/python3.8/site-packages/docutils/parsers/rst/states.py", line 2342, in explicit_markup
    nodelist, blank_finish = self.explicit_construct(match)
  File "/Users/yanghaote/.pyenv/versions/3.8.3/Python.framework/Versions/3.8/lib/python3.8/site-packages/docutils/parsers/rst/states.py", line 2354, in explicit_construct
    return method(self, expmatch)
  File "/Users/yanghaote/.pyenv/versions/3.8.3/Python.framework/Versions/3.8/lib/python3.8/site-packages/docutils/parsers/rst/states.py", line 2099, in directive
    return self.unknown_directive(type_name)
  File "/Users/yanghaote/.pyenv/versions/3.8.3/Python.framework/Versions/3.8/lib/python3.8/site-packages/docutils/parsers/rst/states.py", line 2280, in unknown_directive
    error = self.reporter.error(
  File "/Users/yanghaote/.pyenv/versions/3.8.3/Python.framework/Versions/3.8/lib/python3.8/site-packages/docutils/utils/__init__.py", line 231, in error
    return self.system_message(self.ERROR_LEVEL, *args, **kwargs)
  File "/Users/yanghaote/.pyenv/versions/3.8.3/Python.framework/Versions/3.8/lib/python3.8/site-packages/rstfmt/rstfmt.py", line 274, in system_message
    msg = super().system_message(level, message, *children, **kwargs)
  File "/Users/yanghaote/.pyenv/versions/3.8.3/Python.framework/Versions/3.8/lib/python3.8/site-packages/docutils/utils/__init__.py", line 197, in system_message
    raise SystemMessage(msg, level)
docutils.utils.SystemMessage: :5: (ERROR/3) Unknown directive type "glossary".

.. glossary::

   term_a
      This is term a.

   term_b
      This is term b.

The rstfmt_issue_glossary.rst file looks like:

######
 Test
######

.. glossary::

   term_a
      This is term a.

   term_b
      This is term b.

This is a cross-reference example for :term:`term_a`.
dzhu commented 2 years ago

The latest 0.0.11 release partially fixes this; formatting will work as long as the body uses standard definition list syntax rather than the extended version supported by glossary (which allows multiple terms for one definition and inline markup in terms). See the relevant commit for more information.