Skip to content

Commit

Permalink
✨ NEW: Nested parse class docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjsewell committed Dec 1, 2021
1 parent 050b659 commit 1af4506
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v0.1.1 (November 2021)

✨ NEW: Nested parse class docstrings

## v0.1.0 (November 2021)

Initial release.
2 changes: 1 addition & 1 deletion docs/example/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


class User(Base):
"""A user."""
"""A ``user``."""

__tablename__ = "dbusers"
__table_args__ = (UniqueConstraint("first_name", "last_name"),)
Expand Down
2 changes: 1 addition & 1 deletion sphinx_sqlalchemy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Sphinx extension for documenting SQLAlchemy ORMs"""
from typing import TYPE_CHECKING

__version__ = "0.1.0"
__version__ = "0.1.1"

if TYPE_CHECKING:
from sphinx.application import Sphinx
Expand Down
7 changes: 6 additions & 1 deletion sphinx_sqlalchemy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import List, Optional, Set

from docutils import nodes
from docutils.statemachine import StringList

# from docutils.parsers.rst import directives
from sphinx.application import Sphinx
Expand Down Expand Up @@ -93,7 +94,11 @@ def add_content(self, mapper: Mapper, definition: nodes.definition) -> None:

# class documentation
if mapper.class_.__doc__:
definition += nodes.paragraph(text=f"{mapper.class_.__doc__}")
self.state.nested_parse(
StringList(mapper.class_.__doc__.splitlines()),
self.content_offset,
definition,
)

# column documentation
if mapper.columns:
Expand Down

0 comments on commit 1af4506

Please sign in to comment.