Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: move description list render logic into quartodoc #1725

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/build-docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ jobs:
- name: Install dependencies
run: |
make ci-install-docs
pip install git+https://github.com/machow/quartodoc.git@main

- name: Run quartodoc
run: |
Expand Down
2 changes: 2 additions & 0 deletions docs/_quartodoc-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ quartodoc:
renderer:
style: _renderer.py
show_signature_annotations: false
table_style: description-list
sections:
- title: Page containers
desc: Create a user interface page container.
Expand Down Expand Up @@ -357,3 +358,4 @@ quartodoc:
contents:
- name: experimental.ui.card_image
dynamic: false

1 change: 1 addition & 0 deletions docs/_quartodoc-express.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ quartodoc:
renderer:
style: _renderer.py
show_signature_annotations: false
table_style: description-list
sections:
- title: Input components
desc: Gather user input.
Expand Down
37 changes: 8 additions & 29 deletions docs/_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from quartodoc import MdRenderer
from quartodoc.pandoc.blocks import DefinitionList
from quartodoc.renderers.base import convert_rst_link_to_md, sanitize
from quartodoc.renderers.md_renderer import ParamRow

# from quartodoc.ast import preview

Expand Down Expand Up @@ -101,12 +102,12 @@ def render_annotation(self, el: str):
# TODO-future; Can be removed once we use quartodoc 0.3.5
# Related: https://github.com/machow/quartodoc/pull/205
@dispatch
def render(self, el: DocstringAttribute):
row = [
sanitize(el.name),
self.render_annotation(el.annotation),
sanitize(el.description or "", allow_markdown=True),
]
def render(self, el: DocstringAttribute) -> ParamRow:
row = ParamRow(
el.name,
el.description or "",
annotation=self.render_annotation(el.annotation),
)
return row

@dispatch
Expand Down Expand Up @@ -170,28 +171,6 @@ def summarize(self, obj: Union[Object, Alias]) -> str:

return ""

# Consolidate the parameter type info into a single column
@dispatch
def render(self, el: DocstringParameter):
param = f'<span class="parameter-name">{el.name}</span>'
annotation = self.render_annotation(el.annotation)
if annotation:
param = f'{param}<span class="parameter-annotation-sep">:</span> <span class="parameter-annotation">{annotation}</span>'
if el.default:
param = f'{param} <span class="parameter-default-sep">=</span> <span class="parameter-default">{el.default}</span>'

# Wrap everything in a code block to allow for links
param = "<code>" + param + "</code>"

return (param, el.description)

@dispatch
def render(self, el: DocstringSectionParameters):
rows = list(map(self.render, el.value))
# rows is a list of tuples of (<parameter>, <description>)

return str(DefinitionList(rows))

@dispatch
def signature(self, el: Function, source: Optional[Alias] = None):
if el.name == "__call__":
Expand Down Expand Up @@ -279,7 +258,7 @@ def read_file(file: str | Path, root_dir: str | Path | None = None) -> FileConte


def check_if_missing_expected_example(el, converted):
if re.search(r"(^|\n)#{2,6} Examples\n", converted):
if re.search(r"(^|\n)#{2,6} Examples", converted):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quartodoc adds class names to the sections now, so we had to remove the newline from the regex.

# Manually added examples are fine
return

Expand Down
Loading