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

feat!: initial description-list support; render_header cleanup #325

Merged
merged 14 commits into from
Aug 27, 2024
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
8 changes: 7 additions & 1 deletion docs/_quarto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ website:
format:
html:
theme: cosmo
css: styles.css
css:
- api/_styles-quartodoc.css
- styles.css
toc: true


Expand All @@ -88,7 +90,11 @@ quartodoc:
dir: api
package: quartodoc
render_interlinks: true
renderer:
style: markdown
table_style: description-list
sidebar: "api/_sidebar.yml"
css: "api/_styles-quartodoc.css"
sections:
- title: Preparation Functions
desc: |
Expand Down
11 changes: 8 additions & 3 deletions docs/get-started/overview.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,20 @@ project:

# tell quarto to read the generated sidebar
metadata-files:
- _sidebar.yml
- api/_sidebar.yml

# tell quarto to read the generated styles
format:
css:
- api/_styles-quartodoc.css

quartodoc:
# the name used to import the package you want to create reference docs for
package: quartodoc

# write sidebar data to this file
sidebar: _sidebar.yml
# write sidebar and style data
sidebar: api/_sidebar.yml
css: api/_styles-quartodoc.css

sections:
- title: Some functions
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ classifiers = [
dynamic = ["version"]
requires-python = ">=3.9"
dependencies = [
"black",
"click",
"griffe >= 0.33",
"sphobjinv >= 2.3.1",
Expand Down
26 changes: 26 additions & 0 deletions quartodoc/autosummary.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,8 @@ class Builder:
The output path of the index file, used to list all API functions.
sidebar:
The output path for a sidebar yaml config (by default no config generated).
css:
The output path for the default css styles.
rewrite_all_pages:
Whether to rewrite all rendered doc pages, or only those with changes.
source_dir:
Expand Down Expand Up @@ -486,6 +488,7 @@ def __init__(
renderer: "dict | Renderer | str" = "markdown",
out_index: str = None,
sidebar: "str | None" = None,
css: "str | None" = None,
rewrite_all_pages=False,
source_dir: "str | None" = None,
dynamic: bool | None = None,
Expand All @@ -502,6 +505,7 @@ def __init__(
self.dir = dir
self.title = title
self.sidebar = sidebar
self.css = css
self.parser = parser

self.renderer = Renderer.from_config(renderer)
Expand Down Expand Up @@ -587,6 +591,12 @@ def build(self, filter: str = "*"):
_log.info(f"Writing sidebar yaml to {self.sidebar}")
self.write_sidebar(blueprint)

# css ----

if self.css:
_log.info(f"Writing css styles to {self.css}")
self.write_css()

def write_index(self, blueprint: layout.Layout):
"""Write API index page."""

Expand Down Expand Up @@ -685,6 +695,22 @@ def write_sidebar(self, blueprint: layout.Layout):
d_sidebar = self._generate_sidebar(blueprint)
yaml.dump(d_sidebar, open(self.sidebar, "w"))

def write_css(self):
"""Write default css styles to a file."""
from importlib_resources import files
from importlib_metadata import version

v = version("quartodoc")

note = (
f"/*\nThis file generated automatically by quartodoc version {v}.\n"
"Modifications may be overwritten by quartodoc build. If you want to\n"
"customize styles, create a new .css file to avoid losing changes.\n"
"*/\n\n\n"
)
with open(files("quartodoc.static") / "styles.css") as f:
Path(self.css).write_text(note + f.read())

def _page_to_links(self, el: layout.Page) -> list[str]:
# if el.flatten:
# links = []
Expand Down
3 changes: 3 additions & 0 deletions quartodoc/renderers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ def sanitize(val: str, allow_markdown=False):
# sanitize common tokens that break tables
res = val.replace("\n", " ").replace("|", "\\|")

# sanitize elements that get turned into smart quotes
res = res.replace("'", r"\'").replace('"', r"\"")

# sanitize elements that can get interpreted as markdown links
# or citations
if not allow_markdown:
Expand Down
Loading
Loading