Skip to content

Commit

Permalink
Respect instance-specific docs as well
Browse files Browse the repository at this point in the history
  • Loading branch information
vkottler committed Oct 16, 2024
1 parent 3be5ee0 commit a6073d7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
6 changes: 5 additions & 1 deletion tests/io/test_markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ class SampleC(SampleB):
"""A sample class."""

inst = SampleC()
inst.set_markdown(package="tests")
inst.set_markdown(
markdown="instance-specific stuff 1",
config={"markdown": "instance-specific stuff 2"},
package="tests",
)

# print("==========")
# print(inst.markdown)
Expand Down
16 changes: 10 additions & 6 deletions vcorelib/io/markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,15 @@ def class_markdown_parts(

@classmethod
def class_markdown(
cls, _visited: set[str] = None, **kwargs
cls, _visited: set[str] = None, parts: list[str] = None, **kwargs
) -> Optional[str]:
"""Attempt to get markdown for this class."""

result = None

compiled = (linesep + linesep).join(
list(x.rstrip() for x in cls.class_markdown_parts(**kwargs))
(parts or [])
+ list(x.rstrip() for x in cls.class_markdown_parts(**kwargs))
)
if compiled:
result = compiled
Expand All @@ -93,9 +94,12 @@ def set_markdown(

assert not hasattr(self, "markdown")

parts = []
if markdown:
parts.append(markdown)
if config and config.get("markdown"):
parts.append(config["markdown"]) # type: ignore

self.markdown: str = (
markdown # type: ignore
or (None if config is None else config.get("markdown"))
or self.class_markdown(**kwargs)
or default_markdown()
self.class_markdown(parts=parts, **kwargs) or default_markdown()
)

0 comments on commit a6073d7

Please sign in to comment.