-
Notifications
You must be signed in to change notification settings - Fork 5
Improve docs #1093
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
Improve docs #1093
Changes from all commits
dba2800
d919213
97b4650
e9e28db
bf61d98
d3b443f
6ad6e7b
eef32d3
608c577
9b9fe2b
65dec11
93d410e
68f1246
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| """Sphinx role ``colordot`` for inline colour swatches. | ||
|
|
||
| Renders an inline ``<span class="dg-dot" style="background:<color>;"></span>`` | ||
| so RST tables can show a filled colour circle next to a hex value without | ||
| resorting to raw HTML blocks. | ||
|
|
||
| Usage in .rst files:: | ||
|
|
||
| :colordot:`#c2620a` ``#c2620a`` (``--primary``) | ||
|
|
||
| Register in conf.py:: | ||
|
|
||
| extensions = [..., "colordot"] | ||
| """ | ||
|
|
||
| import html | ||
| from typing import Any | ||
|
|
||
| from docutils import nodes | ||
| from docutils.nodes import Node, system_message | ||
| from sphinx.application import Sphinx | ||
|
|
||
|
|
||
| def colordot_role( # pylint: disable=too-many-arguments,too-many-positional-arguments | ||
| name: str, # pylint: disable=unused-argument | ||
| rawtext: str, # pylint: disable=unused-argument | ||
| text: str, | ||
| lineno: int, # pylint: disable=unused-argument | ||
| inliner: Any, # pylint: disable=unused-argument | ||
| options: dict[str, Any] | None = None, # pylint: disable=unused-argument | ||
| content: list[str] | None = None, # pylint: disable=unused-argument | ||
| ) -> tuple[list[Node], list[system_message]]: | ||
| """Render a filled colour circle as an inline HTML ``<span>``. | ||
|
|
||
| Args: | ||
| name: The role name (``colordot``). | ||
| rawtext: The raw markup including role and argument. | ||
| text: The interpreted text (a CSS colour value, e.g. ``#c2620a``). | ||
| lineno: The line number in the source document. | ||
| inliner: The inliner instance. | ||
| options: Directive options mapping. | ||
| content: The directive content lines. | ||
|
|
||
| Returns: | ||
| A two-tuple of (node list, system message list) as required by Sphinx. | ||
| """ | ||
| color = html.escape(text.strip(), quote=True) | ||
| markup = f'<span class="dg-dot" style="background:{color};"></span>' | ||
| node = nodes.raw("", markup, format="html") | ||
| return [node], [] | ||
|
|
||
|
|
||
| def setup(app: Sphinx) -> dict[str, Any]: | ||
| """Register the ``colordot`` role with Sphinx. | ||
|
|
||
| Args: | ||
| app: The Sphinx application object. | ||
|
|
||
| Returns: | ||
| Extension metadata dictionary. | ||
| """ | ||
| app.add_role("colordot", colordot_role) | ||
| return {"version": "0.1", "parallel_read_safe": True, "parallel_write_safe": True} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| """Sphinx directives ``palette`` and ``swatch`` for design-guide colour palettes. | ||
|
|
||
| Renders design-guide colour palette HTML without raw HTML blocks. | ||
|
|
||
| Usage:: | ||
|
|
||
| .. palette:: | ||
|
|
||
| .. swatch:: #c2620a | ||
| :token: --primary | ||
| :label: Amber Orange | ||
| :usage: CTAs, active borders, diagram start nodes, section pips | ||
|
|
||
| .. palette:: | ||
| :columns: 4 | ||
|
|
||
| .. swatch:: #c2620a | ||
| :token: --dxt-tutorial | ||
| :label: Tutorials | ||
| :usage: Same as ``--primary``; warm amber for learning-oriented pages | ||
|
|
||
| Register in conf.py:: | ||
|
|
||
| extensions = [..., "designguide"] | ||
| """ | ||
|
|
||
| import html | ||
| from typing import Any | ||
|
|
||
| from docutils import nodes | ||
| from docutils.nodes import Node | ||
| from docutils.parsers.rst import Directive, directives | ||
| from sphinx.application import Sphinx | ||
|
|
||
|
|
||
| class SwatchDirective(Directive): | ||
| """Render a single colour swatch card as ``.. swatch:: #hexcolor``.""" | ||
|
|
||
| required_arguments = 1 | ||
| optional_arguments = 0 | ||
| option_spec = { | ||
| "token": directives.unchanged, | ||
| "label": directives.unchanged, | ||
| "usage": directives.unchanged, | ||
| "border": directives.unchanged, | ||
| } | ||
| has_content = False | ||
|
|
||
| def run(self) -> list[Node]: | ||
| """Emit a ``dg-swatch`` HTML block for the given colour. | ||
|
|
||
| Returns: | ||
| A list containing a single raw HTML node. | ||
| """ | ||
| color = html.escape(self.arguments[0].strip(), quote=True) | ||
| token = html.escape(self.options.get("token", "")) | ||
| label = html.escape(self.options.get("label", "")) | ||
| usage = html.escape(self.options.get("usage", "")) | ||
| border = html.escape(self.options.get("border", ""), quote=True) | ||
|
|
||
| color_style = f"background:{color};" | ||
| if border: | ||
| color_style += f" border-bottom:1px solid {border};" | ||
|
Comment on lines
+55
to
+63
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Validate the swatch argument instead of accepting arbitrary strings. Lines 55-63 accept any string even though the directive is documented as 🤖 Prompt for AI Agents |
||
|
|
||
| markup = ( | ||
| f'<div class="dg-swatch">' | ||
| f'<div class="dg-swatch-color" style="{color_style}"></div>' | ||
| f'<div class="dg-swatch-body">' | ||
| f'<div class="dg-swatch-token">{token}</div>' | ||
| f'<div class="dg-swatch-hex">{color}</div>' | ||
| f'<div class="dg-swatch-label">{label}</div>' | ||
| f'<div class="dg-swatch-usage">{usage}</div>' | ||
| f"</div>" | ||
| f"</div>" | ||
| ) | ||
| return [nodes.raw("", markup, format="html")] | ||
|
|
||
|
|
||
| class PaletteDirective(Directive): | ||
| """Render a grid of ``.. swatch::`` directives as ``.. palette::``.""" | ||
|
|
||
| required_arguments = 0 | ||
| optional_arguments = 0 | ||
| option_spec = { | ||
| "columns": directives.positive_int, | ||
| } | ||
| has_content = True | ||
|
|
||
| def run(self) -> list[Node]: | ||
| """Emit a ``dg-palette`` wrapper div containing parsed swatch children. | ||
|
|
||
| Returns: | ||
| A list of nodes: opening div, swatch children, closing div. | ||
| """ | ||
| columns: int | None = self.options.get("columns", None) | ||
|
|
||
| style = "" | ||
| if columns: | ||
| style = f' style="grid-template-columns:repeat({columns},1fr);"' | ||
|
|
||
| open_div = nodes.raw("", f'<div class="dg-palette"{style}>\n', format="html") | ||
|
Comment on lines
+95
to
+101
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Line 99 overwrites the |
||
| close_div = nodes.raw("", "</div>\n", format="html") | ||
|
|
||
| container = nodes.section() | ||
| container.document = self.state.document | ||
| self.state.nested_parse(self.content, self.content_offset, container) | ||
|
|
||
| return [open_div, *container.children, close_div] | ||
|
|
||
|
|
||
| def setup(app: Sphinx) -> dict[str, Any]: | ||
| """Register the ``palette`` and ``swatch`` directives with Sphinx. | ||
|
|
||
| Args: | ||
| app: The Sphinx application object. | ||
|
|
||
| Returns: | ||
| Extension metadata dictionary. | ||
| """ | ||
| app.add_directive("palette", PaletteDirective) | ||
| app.add_directive("swatch", SwatchDirective) | ||
| return {"version": "0.1", "parallel_read_safe": True, "parallel_write_safe": True} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <nav class="sidebar-quicklinks" aria-label="Quick links"> | ||
| <a href="{{ pathto(master_doc) }}" title="Documentation home" aria-label="Documentation home"> | ||
| <i class="fa-solid fa-house" aria-hidden="true"></i> | ||
| </a> | ||
| <a href="https://dfetch-org.github.io/" title="Dfetch website" aria-label="Dfetch website" target="_blank" rel="noopener noreferrer"> | ||
| <i class="fa-solid fa-globe" aria-hidden="true"></i> | ||
| </a> | ||
| <a href="https://github.com/dfetch-org/dfetch" title="Source on GitHub" aria-label="Source on GitHub" target="_blank" rel="noopener noreferrer"> | ||
| <i class="fa-brands fa-github" aria-hidden="true"></i> | ||
| </a> | ||
| </nav> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,13 +13,13 @@ | |
| import os | ||
| import sys | ||
|
|
||
| from dfetch import __version__ | ||
|
|
||
| # Prevent ANSI color codes in command output captured by sphinxcontrib.programoutput. | ||
| # Python 3.13+ argparse emits colors when FORCE_COLOR is set; NO_COLOR suppresses | ||
| # that regardless of FORCE_COLOR, and dfetch's own Rich console respects it too. | ||
| os.environ["NO_COLOR"] = "1" | ||
|
|
||
| from dfetch import __version__ | ||
|
|
||
| # -- General configuration ------------------------------------------------ | ||
|
|
||
| ext_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "_ext")) | ||
|
|
@@ -47,8 +47,15 @@ | |
| "sphinxcontrib.programoutput", | ||
| "sphinx_tabs.tabs", | ||
| "sphinx_autoissues", | ||
| "sphinx_copybutton", | ||
| "colordot", | ||
| "designguide", | ||
| ] | ||
|
|
||
| # Strip shell prompts and Python REPL prompts from copied text | ||
| copybutton_prompt_text = r"\$ |>>> |\.\.\. " | ||
| copybutton_prompt_is_regexp = True | ||
|
|
||
| # Add any paths that contain templates here, relative to this directory. | ||
| templates_path = ["_templates"] | ||
|
|
||
|
|
@@ -123,6 +130,9 @@ | |
| html_extra_path = ["robots.txt"] | ||
|
|
||
| html_css_files = [ | ||
| "fonts/font-awesome/css/fontawesome.min.css", | ||
| "fonts/font-awesome/css/solid.min.css", | ||
| "fonts/font-awesome/css/brands.min.css", | ||
| "css/custom.css", | ||
|
Comment on lines
132
to
136
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Search for Font Awesome regular icon usage in documentation
echo "=== Searching for .far or .fa-regular classes in doc files ==="
rg -n '\bfa-regular\b|\bfar\b' doc/ --type=rst --type=html --type=md
echo ""
echo "=== Checking if regular.css should be in html_css_files ==="
cat doc/static/fonts/font-awesome/css/regular.css | head -20Repository: dfetch-org/dfetch Length of output: 841 Remove the unused The regular Font Awesome CSS file is not loaded in 🤖 Prompt for AI Agents |
||
| ] | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: dfetch-org/dfetch
Length of output: 1934
🏁 Script executed:
cat -n .pre-commit-config.yaml | head -30Repository: dfetch-org/dfetch
Length of output: 1066
Exclusion pattern is overly broad and should target only vendored assets.
The change broadens the exclusion from
^doc/static/uml/styles/plantuml-c4/to the entire^doc/static/tree, which excludes project-authored files likedoc/static/css/custom.cssanddoc/static/js/diataxis.jsfrom whitespace and newline checks.Use a more targeted pattern that excludes only vendored fonts:
This preserves checks on project-authored CSS, JavaScript, and PlantUML diagrams while excluding the vendored font packages (inter, jetbrains-mono, font-awesome).
🧰 Tools
🪛 YAMLlint (1.38.0)
[error] 9-9: too many spaces after hyphen
(hyphens)
🤖 Prompt for AI Agents