Skip to content
Merged
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
9 changes: 8 additions & 1 deletion quartodoc/renderers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@ def escape(val: str):

def sanitize(val: str, allow_markdown=False, escape_quotes=False):
# sanitize common tokens that break tables
res = val.replace("\n", " ").replace("|", "\\|")
# Note: grid tables support newlines. We preserve them if there are
# double newlines (paragraph breaks, lists), otherwise collapse to spaces
has_double_newline = "\n\n" in val

if has_double_newline:
res = val.replace("|", "\\|")
else:
res = val.replace("\n", " ").replace("|", "\\|")

# sanitize elements that get turned into smart quotes
# this is to avoid defaults that are strings having their
Expand Down
22 changes: 16 additions & 6 deletions quartodoc/renderers/md_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def to_tuple(self, style: Literal["parameters", "attributes", "returns"]):
@dataclass
class SummaryRow:
"""Represents a row in a summary table."""

link: str
description: str

Expand Down Expand Up @@ -280,7 +281,7 @@ def _render_table(
# Standard rendering with all columns
row_tuples = [row.to_tuple(style) for row in rows]

table = tabulate(row_tuples, headers=headers, tablefmt="github")
table = tabulate(row_tuples, headers=headers, tablefmt="grid")
return table

@staticmethod
Expand Down Expand Up @@ -504,21 +505,26 @@ def render(self, el: Union[layout.DocClass, layout.DocModule]):
# TODO: for now, we skip making an attribute table on classes, unless
# they contain an attributes section in the docstring
if (
raw_attrs and not _has_attr_section(el.obj.docstring)
raw_attrs
and not _has_attr_section(el.obj.docstring)
# TODO: what should backwards compat be?
# and not isinstance(el, layout.DocClass)
):
# Collect SummaryRow objects and render as TOC
attr_rows = [self.summarize(attr) for attr in raw_attrs]
_attrs_table = self._render_summary_table(attr_rows, self.table_style_tocs, include_headers=True)
_attrs_table = self._render_summary_table(
attr_rows, self.table_style_tocs, include_headers=True
)
attrs = f"{sub_header} Attributes\n\n{_attrs_table}"
attr_docs.append(attrs)

# classes summary table ----
if raw_classes:
# Collect SummaryRow objects and render as TOC
class_rows = [self.summarize(cls) for cls in raw_classes]
_summary_table = self._render_summary_table(class_rows, self.table_style_tocs, include_headers=True)
_summary_table = self._render_summary_table(
class_rows, self.table_style_tocs, include_headers=True
)
section_name = "Classes"
objs = f"{sub_header} {section_name}\n\n{_summary_table}"
class_docs.append(objs)
Expand All @@ -537,7 +543,9 @@ def render(self, el: Union[layout.DocClass, layout.DocModule]):
if raw_meths:
# Collect SummaryRow objects and render as TOC
meth_rows = [self.summarize(meth) for meth in raw_meths]
_summary_table = self._render_summary_table(meth_rows, self.table_style_tocs, include_headers=True)
_summary_table = self._render_summary_table(
meth_rows, self.table_style_tocs, include_headers=True
)
section_name = (
"Methods" if isinstance(el, layout.DocClass) else "Functions"
)
Expand Down Expand Up @@ -836,7 +844,9 @@ def render(self, el):
# layout.Section, or a row in the table for layout.Page or layout.DocFunction.

def _summary_row(self, link, description):
return SummaryRow(link=link, description=sanitize(description, allow_markdown=True))
return SummaryRow(
link=link, description=sanitize(description, allow_markdown=True)
)

# Summarization methods ---------------------------------------------------

Expand Down
Loading
Loading