Skip to content

Commit 4739a4e

Browse files
authored
Merge pull request #325 from machow/feat-description-lists
feat!: initial description-list support; render_header cleanup
2 parents 92b86af + 9005913 commit 4739a4e

File tree

9 files changed

+473
-104
lines changed

9 files changed

+473
-104
lines changed

docs/_quarto.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ website:
7979
format:
8080
html:
8181
theme: cosmo
82-
css: styles.css
82+
css:
83+
- api/_styles-quartodoc.css
84+
- styles.css
8385
toc: true
8486

8587

@@ -88,7 +90,11 @@ quartodoc:
8890
dir: api
8991
package: quartodoc
9092
render_interlinks: true
93+
renderer:
94+
style: markdown
95+
table_style: description-list
9196
sidebar: "api/_sidebar.yml"
97+
css: "api/_styles-quartodoc.css"
9298
sections:
9399
- title: Preparation Functions
94100
desc: |

docs/get-started/overview.qmd

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,20 @@ project:
7777

7878
# tell quarto to read the generated sidebar
7979
metadata-files:
80-
- _sidebar.yml
80+
- api/_sidebar.yml
8181

82+
# tell quarto to read the generated styles
83+
format:
84+
css:
85+
- api/_styles-quartodoc.css
8286

8387
quartodoc:
8488
# the name used to import the package you want to create reference docs for
8589
package: quartodoc
8690

87-
# write sidebar data to this file
88-
sidebar: _sidebar.yml
91+
# write sidebar and style data
92+
sidebar: api/_sidebar.yml
93+
css: api/_styles-quartodoc.css
8994

9095
sections:
9196
- title: Some functions

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ classifiers = [
3131
dynamic = ["version"]
3232
requires-python = ">=3.9"
3333
dependencies = [
34+
"black",
3435
"click",
3536
"griffe >= 0.33",
3637
"sphobjinv >= 2.3.1",

quartodoc/autosummary.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,8 @@ class Builder:
427427
The output path of the index file, used to list all API functions.
428428
sidebar:
429429
The output path for a sidebar yaml config (by default no config generated).
430+
css:
431+
The output path for the default css styles.
430432
rewrite_all_pages:
431433
Whether to rewrite all rendered doc pages, or only those with changes.
432434
source_dir:
@@ -486,6 +488,7 @@ def __init__(
486488
renderer: "dict | Renderer | str" = "markdown",
487489
out_index: str = None,
488490
sidebar: "str | None" = None,
491+
css: "str | None" = None,
489492
rewrite_all_pages=False,
490493
source_dir: "str | None" = None,
491494
dynamic: bool | None = None,
@@ -502,6 +505,7 @@ def __init__(
502505
self.dir = dir
503506
self.title = title
504507
self.sidebar = sidebar
508+
self.css = css
505509
self.parser = parser
506510

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

594+
# css ----
595+
596+
if self.css:
597+
_log.info(f"Writing css styles to {self.css}")
598+
self.write_css()
599+
590600
def write_index(self, blueprint: layout.Layout):
591601
"""Write API index page."""
592602

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

698+
def write_css(self):
699+
"""Write default css styles to a file."""
700+
from importlib_resources import files
701+
from importlib_metadata import version
702+
703+
v = version("quartodoc")
704+
705+
note = (
706+
f"/*\nThis file generated automatically by quartodoc version {v}.\n"
707+
"Modifications may be overwritten by quartodoc build. If you want to\n"
708+
"customize styles, create a new .css file to avoid losing changes.\n"
709+
"*/\n\n\n"
710+
)
711+
with open(files("quartodoc.static") / "styles.css") as f:
712+
Path(self.css).write_text(note + f.read())
713+
688714
def _page_to_links(self, el: layout.Page) -> list[str]:
689715
# if el.flatten:
690716
# links = []

quartodoc/renderers/base.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ def sanitize(val: str, allow_markdown=False):
1717
# sanitize common tokens that break tables
1818
res = val.replace("\n", " ").replace("|", "\\|")
1919

20+
# sanitize elements that get turned into smart quotes
21+
res = res.replace("'", r"\'").replace('"', r"\"")
22+
2023
# sanitize elements that can get interpreted as markdown links
2124
# or citations
2225
if not allow_markdown:

0 commit comments

Comments
 (0)