Guidedog 手册 1.0.0-beta.16
语言
本页内容
Guidedog / 文档 1.0.0-beta.16

域

域是一组指令和角色,用来描述并交叉引用某种编程语言或某个领域中的对象。

Guidedog 内置实现了标准的 Sphinx 域:

  • 标准域(std):命令行选项、环境变量、术语和界面标签等通用对象。
  • Python 域(py):Python 模块、类、函数、方法、属性、特性(property)和异常。
  • C 域(c):函数、类型、结构体、联合体、枚举、枚举值、变量和宏。
  • C++ 域(cpp):类、概念、模板、命名空间、方法和表达式。
  • JavaScript 域(js):函数、方法、类和属性。
  • Odin 域(odin):原生 Odin 包、过程、结构体、联合体和枚举,见 为 Odin 生成文档。
  • Rust 域(rust):Rust 的 crate、模块、函数、结构体、枚举、trait、impl 和宏(见下文 Rust 域)。

设置主域

在 conf.toml 中用 primary_domain 设置默认域,默认为 "py"。启用后可省略域前缀,例如用 .. function:: 代替 .. py:function::,用 :func:`name` 代替 :py:func:`name`。

在单个文档内切换当前域:

.. default-domain:: c

标准域

标准域描述命令行工具、环境变量和文档交叉引用。

指令

.. program:: mytool

.. option:: -c <config>, --config <config>

   Path to the configuration file.

.. envvar:: GUIDEDOG_THEME

   Specifies the default theme stylesheet.

角色

  • :doc:`path`:按相对路径链接到项目文档。
  • :ref:`label`:链接到显式目标标签 .. _label:。
  • :term:`term`:链接到 glossary 中定义的术语。
  • :option:`--config`:链接到 option 中描述的命令行选项。
  • :envvar:`VARIABLE`:链接到 envvar 中描述的环境变量。
  • :command:`name`:标记系统命令名。
  • :file:`path`:标记文件或目录路径,可包含 {variable} 占位符。
  • :kbd:`Ctrl+C`:标记键盘按键。
  • :menuselection:`File --> Save As`:表示菜单操作顺序。
  • :guilabel:`Submit`:表示按钮或界面元素。
  • :pep:`8`:链接到 Python 改进提案。
  • :rfc:`7231`:链接到 IETF RFC 文档。

Python 域

Python 域描述 Python 接口和签名。

指令

.. py:module:: pipeline.reader
   :synopsis: Document reading and normalization.

.. py:class:: DocumentReader(source_path: str, encoding: str = "utf-8")

   Base class for document readers.

   .. py:method:: parse(content: bytes) -> Document

      Parses raw bytes into a document tree.

      :param content: Raw source content bytes.
      :return: Parsed document tree instance.
      :raises ValueError: If the source format is unrecognized.

   .. py:attribute:: encoding
      :type: str

      The character encoding used for text decoding.

支持的指令包括:py:module、py:currentmodule、py:function、py:data、py:class、py:method、py:staticmethod、py:classmethod、py:attribute、py:property、py:exception、py:decorator 和 py:type。

角色

  • :py:func:`name`:链接到 Python 函数。
  • :py:class:`name`:链接到 Python 类。
  • :py:meth:`name`:链接到 Python 类方法或实例方法。
  • :py:attr:`name`:链接到 Python 属性。
  • :py:data:`name`:链接到 Python 模块级数据。
  • :py:exc:`name`:链接到 Python 异常类。
  • :py:mod:`name`:链接到 Python 模块。

C 域

C 域描述 C 语言库和头文件。

指令

.. c:namespace:: gd

.. c:struct:: Workspace

   Reusable conversion state; its buffers are kept between conversions.

   .. c:member:: size_t capacity

      Total byte size of the output buffer.

.. c:function:: int gd_convert(Workspace *ws, const char *input, char *output, size_t out_len)

   Converts source text into HTML.

   :param ws: Pointer to the initialized workspace.
   :param input: Null-terminated input string.
   :param output: Destination buffer.
   :param out_len: Size of destination buffer.
   :returns: 0 on success, or an error code.

角色

  • :c:func:`name`:链接到 C 函数。
  • :c:member:`name`:链接到 C 结构体或联合体的成员。
  • :c:data:`name` / :c:var:`name`:链接到 C 变量。
  • :c:type:`name`:链接到 C 的 typedef 或类型。
  • :c:struct:`name`:链接到 C 结构体。
  • :c:union:`name`:链接到 C 联合体。
  • :c:enum:`name`:链接到 C 枚举。
  • :c:macro:`name`:链接到 C 预处理器宏。

C++ 域

C++ 域支持现代 C++ 构造、概念、命名空间和作用域。

指令

.. cpp:namespace:: guidedog

.. cpp:concept:: template<typename T> Reader

   Specifies requirements for document reader types.

.. cpp:class:: template<typename Allocator> Builder

   Constructs AST document nodes.

   .. cpp:function:: NodeId add_text(std::string_view text)

      Appends text to the active node.

角色

  • :cpp:class:`name`:链接到 C++ 类或结构体。
  • :cpp:func:`name`:链接到 C++ 函数或方法。
  • :cpp:member:`name` / :cpp:var:`name`:链接到成员或变量。
  • :cpp:type:`name`:链接到 C++ 类型别名或 typedef。
  • :cpp:concept:`name`:链接到 C++20 概念。
  • :cpp:enum:`name`:链接到 C++ 枚举。

JavaScript 域

JavaScript 域描述浏览器脚本、库和 Node.js 模块。

指令

.. js:module:: theme

.. js:class:: ThemeController(options)

   Manages color themes and local storage persistence.

   .. js:method:: toggleTheme()

      Toggles between light and dark modes.

角色

  • :js:func:`name`:链接到 JavaScript 函数。
  • :js:meth:`name`:链接到 JavaScript 方法。
  • :js:class:`name`:链接到 JavaScript 类。
  • :js:data:`name`:链接到 JavaScript 变量。
  • :js:attr:`name`:链接到 JavaScript 对象属性。
  • :js:mod:`name`:链接到 JavaScript 模块。

Rust 域

Rust 域按照 rustdoc 的呈现方式描述 crate。每个指令都接受 Rust 原样写法的声明,写在一行内,包括可见性和限定符。目标是用 :: 连接的完整路径,以 crate 名开头。

指令

.. rust:module:: my_crate::geometry
   :synopsis: Points and shapes.

.. rust:struct:: pub struct Point<T = f32>

   A point in the plane.

   .. rust:field:: pub x: T

      The horizontal coordinate.

   .. rust:impl:: impl<T: Copy> Point<T>

      .. rust:method:: pub fn new(x: T, y: T) -> Self

         Makes a point.

.. rust:enum:: pub enum Shape

   .. rust:variant:: Circle(f32)

.. rust:trait:: pub trait Draw: Clone + Send

   .. rust:method:: fn draw(&self) -> u8
      :provided:

指令包括:rust:crate、rust:module、rust:function、rust:method、rust:struct、rust:enum、rust:variant、rust:union、rust:trait、rust:impl、rust:type、rust:const、rust:static、rust:macro、rust:field、rust:associatedtype、rust:associatedconst 和 rust:use。选项包括 :visibility:、:cfg:、:unsafe:、:async:、:const:、:provided:、:attributes:、:deprecated:、:for:、:trait:、:target: 和 :noindex:。impl 本身从不是目标,它的成员归属于对应的类型。

Guidedog 也可以直接从 crate 的源码生成这些页面,无需编译。参见 为代码库生成文档,以及 配置参考 中的 rust_autoapi_crates。

角色

  • :rust:mod:`path`:链接到 crate 或模块。
  • :rust:fn:`path`:链接到函数或方法。
  • :rust:struct:`path`、:rust:enum:`path`、:rust:union:`path`、:rust:trait:`path`:链接到相应的类型。
  • :rust:variant:`path`、:rust:field:`path`:链接到变体或字段。
  • :rust:type:`path`、:rust:const:`path`、:rust:static:`path`、:rust:macro:`path`:链接到类型别名和关联类型、常量、静态项以及宏。
  • :rust:any:`path`:链接到以上任意一种,或者通过清单链接到其他项目(std::vec::Vec)。无法解析的目标显示为代码。

交叉引用约定

域中的交叉引用支持以下几种修饰符:

  • 隐藏前缀:在目标前加 ~,只显示名称的最后一部分。例如 :py:func:`~pipeline.reader.DocumentReader.parse` 显示为 parse()。
  • 当前作用域:相对引用先在当前模块或命名空间中查找,再进行全局查找。
  • 精确匹配:在目标前加 .,从当前模块或所属对象开始查找。

Rust 域使用 :: 路径,遵循同样的约定::rust:struct:`~my_crate::geometry::Point` 显示为 Point。