markstory / sphinxcontrib-phpdomain

A PHP domain for sphinx. Allows you to annotate PHP objects in your sphinx docs.
Other
19 stars 15 forks source link

Native directive params support #55

Open mvorisek opened 1 year ago

mvorisek commented 1 year ago

I am migrating sphinx docs from .rst to .md.

Rst file:

.. php:method:: add($object, $region = 'Content')

    Bla bla

    :param $object: Xxx

Md/MyST file:

:::{php:method} add($object, $region = 'Content')
:param $region: Xxx

Bla Bla

:param $object: Xxx
:::

Currently the output looks like: image

Notice, the native MyST param is missing/ignored and the 2nd param not parsed [1]/formated. I think the problem is sphinxcontrib-phpdomain extension tries to parse the params from rst text directly instead of supporting directive/AST params directly.

[1] MyST spec https://myst-parser.readthedocs.io/en/latest/syntax/roles-and-directives.html#parameterizing-directive - directives are parsed at the directive start only

I would expect sphinxcontrib-phpdomain extension to honor natively parsed directive parameters.

Sphinx build log:

C:\Users\Administrator\Desktop\md\docs\view.md:46: WARNING: 'php:method': Unknown option keys: ['param $region']
    (allowed: ['module', 'nocontentsentry', 'noindex', 'noindexentry']) [myst.directive_parse]

To reproduce this issue, edit any rst sphinx project like:

conf.py:

 extensions = [
     'sphinx.ext.autodoc',
     'sphinx.ext.intersphinx',
     'sphinx.ext.todo',
     'sphinx.ext.coverage',
     'sphinxcontrib.phpdomain',
+    'myst_parser',
 ]

+myst_enable_extensions = ['colon_fence']

requirements.txt

 sphinx<5
 sphinx-rtd-theme
 sphinxcontrib-phpdomain
+myst-parser
mvorisek commented 1 year ago

It seems the types are defined in https://github.com/markstory/sphinxcontrib-phpdomain/blob/0.11.1/sphinxcontrib/phpdomain.py#L124 but not registered for other parsers like in this example: https://gist.github.com/shimizukawa/4498647#file-conf-py-L33

https://pydoc.dev/sphinx/latest/sphinx.directives.ObjectDescription.html?private=1#doc_field_types doc_field_types is not documented much

here is docs for field: https://pydoc.dev/sphinx/latest/sphinx.util.docfields.Field.html?private=1, code: https://github.com/sphinx-doc/sphinx/blob/v5.3.0/sphinx/util/docfields.py

markstory commented 1 year ago

I have no context on alternative parsers for sphinx, and won't be able to support them well. You'd need to submit a pull request with some form of regression tests in order to get support for this use case added.

mvorisek commented 1 year ago

For classes I would also expect attributes like "extends", "implements", ex:

:::{php:class} Car
:extends: ObjectModel
:implements: JsonSerializable
:implements: Iterator

Car class that can be serialized to JSON and iterated.
:::