API Reference¶
This section provides detailed API documentation for typsphinx.
Builders¶
Typst builder for Sphinx.
This module implements the TypstBuilder class, which is responsible for building Typst output from Sphinx documentation.
- class typsphinx.builder.TypstBuilder(app, env)[ソース]¶
ベースクラス:
BuilderBuilder class for Typst output format.
This builder converts Sphinx documentation to Typst markup files (.typ), which can then be compiled to PDF using the Typst compiler.
- パラメータ:
app (Sphinx)
env (BuildEnvironment)
- name: str = 'typst'¶
The builder's name. This is the value used to select builders on the command line.
- format: str = 'typst'¶
The builder's output format, or '' if no document output is produced. This is commonly the file extension, e.g. "html", though any string value is accepted. The builder's format string can be used by various components such as
SphinxPostTransformor extensions to determine their compatibility with the builder.
- out_suffix = '.typ'¶
- allow_parallel: bool = True¶
Whether it is safe to make parallel
write_doc()calls.
- init()[ソース]¶
Initialize the builder.
This method is called once at the beginning of the build process.
- 戻り値の型:
- get_outdated_docs()[ソース]¶
Return an iterator of document names that need to be rebuilt.
For now, we rebuild all documents on every build.
- prepare_writing(docnames)[ソース]¶
Prepare for writing the documents.
This method is called before writing begins. Writes the template file to the output directory for master documents to import.
- write(build_docnames, updated_docnames, method='update')[ソース]¶
Override write() to preserve toctree nodes.
By default, Sphinx's Builder.write() calls env.get_and_resolve_doctree() which expands toctree nodes into compact_paragraph with links. For Typst, we need the original toctree nodes to generate #include() directives.
This method uses env.get_doctree() instead to preserve toctree nodes.
- post_process_images(doctree)[ソース]¶
Post-process images in the document tree.
Collects all image nodes from the document tree and tracks them in self.images dictionary for later copying to the output directory.
- パラメータ:
doctree (
document) -- Document tree to process- 戻り値の型:
- write_doc(docname, doctree)[ソース]¶
Write a document.
This method is called for each document that needs to be written.
Requirement 13.1: 各 reStructuredText ファイルに対応する独立した .typ ファイルを生成する
Requirement 13.12: ソースディレクトリ構造を保持して出力する
- copy_image_files()[ソース]¶
Copy image files to the output directory.
Iterates through all tracked images and copies them from the source directory to the output directory, preserving relative paths.
- 戻り値の型:
- copy_template_assets()[ソース]¶
Copy template-associated assets to the output directory.
When using custom Typst templates via typst_template configuration, this method copies assets (fonts, images, logos, etc.) referenced by the template to the output directory.
Behavior: - If typst_template_assets is configured, copies only specified files/directories - If typst_template_assets is None (default), automatically copies entire template directory - If typst_template_assets is empty list, disables automatic copying - Skips .typ files to avoid duplicating template file (already handled by _write_template_file)
This follows the same pattern as copy_image_files() from Issue #38.
- 戻り値の型:
- class typsphinx.builder.TypstPDFBuilder(app, env)[ソース]¶
ベースクラス:
TypstBuilderBuilder class for generating PDF output directly from Typst.
This builder extends TypstBuilder to compile generated .typ files to PDF using the typst-py package.
Requirement 9.3: TypstPDFBuilder extends TypstBuilder Requirement 9.4: Generate PDF from Typst markup
- パラメータ:
app (Sphinx)
env (BuildEnvironment)
- name: str = 'typstpdf'¶
The builder's name. This is the value used to select builders on the command line.
- format: str = 'pdf'¶
The builder's output format, or '' if no document output is produced. This is commonly the file extension, e.g. "html", though any string value is accepted. The builder's format string can be used by various components such as
SphinxPostTransformor extensions to determine their compatibility with the builder.
- out_suffix = '.pdf'¶
- write_doc(docname, doctree)[ソース]¶
Write a document as both .typ and .pdf.
Override to generate .typ file (not .pdf) during the write phase. The .pdf will be generated in finish() by compiling the .typ file.
- finish()[ソース]¶
Finish the build process by compiling Typst files to PDF.
After the parent TypstBuilder has generated .typ files, this method compiles them to PDF using typst-py.
Only master documents (defined in typst_documents) are compiled to PDF. Included documents are not compiled individually.
Requirement 9.2: Execute Typst compilation within Python Requirement 9.4: Generate PDF from Typst markup
- 戻り値の型:
PDF generation utilities using typst-py.
This module provides functionality for generating PDFs from Typst markup using the typst Python package (Requirement 9).
- exception typsphinx.pdf.TypstCompilationError(message, typst_error=None, source_location=None)[ソース]¶
ベースクラス:
ExceptionException raised when Typst compilation fails.
This exception provides detailed information about compilation errors, including the original error from typst-py and contextual information.
- message¶
Human-readable error message
- typst_error¶
Original error from typst compiler
- source_location¶
Location information if available
Requirement 10.3: Error detection and handling Requirement 10.4: Error message parsing and user display
- typsphinx.pdf.check_typst_available()[ソース]¶
Check if typst package is available.
- 例外:
ImportError -- If typst package is not installed
- 戻り値の型:
None
Requirement 9.1: Typst compiler functionality as dependency Requirement 9.7: Automatic availability of Typst compiler
- 戻り値の型:
- typsphinx.pdf.get_typst_version()[ソース]¶
Get the version of the typst package.
- 戻り値の型:
- 戻り値:
Version string (e.g., "0.13.7")
Requirement 9.7: Version information for Typst compiler
- typsphinx.pdf.compile_typst_to_pdf(typst_content, root_dir=None)[ソース]¶
Compile Typst content to PDF bytes.
- パラメータ:
- 戻り値の型:
- 戻り値:
PDF content as bytes
- 例外:
ImportError -- If typst package not available
TypstCompilationError -- If compilation fails
Requirement 9.2: Execute Typst compilation within Python environment Requirement 9.4: Generate PDF from Typst markup Requirement 10.3: Error detection and handling
Writer and Translator¶
Typst writer for docutils.
This module implements the TypstWriter class, which converts docutils document trees to Typst markup.
- class typsphinx.writer.TypstWriter(builder)[ソース]¶
ベースクラス:
WriterWriter class for Typst output format.
This writer converts docutils document trees to Typst markup files.
- パラメータ:
builder (Any)
- supported = ('typst',)¶
Formats this writer supports.
- translate()[ソース]¶
Translate the document tree to Typst markup.
This method creates a TypstTranslator and visits the document tree, then wraps the output with a template using TemplateEngine.
For master documents (defined in typst_documents), the full template is applied. For included documents, only the body content is output.
- 戻り値の型:
Typst translator for docutils nodes.
This module implements the TypstTranslator class, which translates docutils nodes to Typst markup.
- class typsphinx.translator.TypstTranslator(document, builder)[ソース]¶
ベースクラス:
SphinxTranslatorTranslator class that converts docutils nodes to Typst markup.
This translator visits nodes in the document tree and generates corresponding Typst markup.
- パラメータ:
document (document)
builder (Any)
- visit_document(node)[ソース]¶
Visit a document node.
Generates opening code block wrapper for unified code mode.
- パラメータ:
node (
document) -- The document node- 戻り値の型:
- depart_document(node)[ソース]¶
Depart a document node.
Generates closing code block wrapper for unified code mode.
- パラメータ:
node (
document) -- The document node- 戻り値の型:
- visit_title(node)[ソース]¶
Visit a title node.
Generates heading() function call with level parameter. Child text nodes will be wrapped in text() automatically.
- パラメータ:
node (
title) -- The title node- 戻り値の型:
- depart_title(node)[ソース]¶
Depart a title node.
Closes heading() function call.
- パラメータ:
node (
title) -- The title node- 戻り値の型:
- visit_subtitle(node)[ソース]¶
Visit a subtitle node.
Generates emph() function for subtitle (no # prefix in code mode). Child text nodes will be wrapped in text() automatically.
- パラメータ:
node (
subtitle) -- The subtitle node- 戻り値の型:
- depart_subtitle(node)[ソース]¶
Depart a subtitle node.
Closes emph() function.
- パラメータ:
node (
subtitle) -- The subtitle node- 戻り値の型:
- visit_compound(node)[ソース]¶
Visit a compound node.
Compound nodes are containers that group related content. They are often used to wrap toctree directives.
- パラメータ:
node (
compound) -- The compound node- 戻り値の型:
- depart_compound(node)[ソース]¶
Depart a compound node.
- パラメータ:
node (
compound) -- The compound node- 戻り値の型:
- visit_container(node)[ソース]¶
Visit a container node.
Handle Sphinx-generated containers, particularly literal-block-wrapper for captioned code blocks (Issue #20).
- パラメータ:
node (
container) -- The container node- 戻り値の型:
- depart_container(node)[ソース]¶
Depart a container node.
- パラメータ:
node (
container) -- The container node- 戻り値の型:
- visit_paragraph(node)[ソース]¶
Visit a paragraph node.
Wraps paragraph content in par() function for unified code mode. Code mode doesn't auto-recognize paragraph breaks from blank lines.
Exception: Inside list items, paragraphs are not wrapped in par() to avoid syntax like "- par(text(...))" which is invalid.
- パラメータ:
node (
paragraph) -- The paragraph node- 戻り値の型:
- depart_paragraph(node)[ソース]¶
Depart a paragraph node.
Closes par({}) function and adds spacing.
- パラメータ:
node (
paragraph) -- The paragraph node- 戻り値の型:
- visit_comment(node)[ソース]¶
Visit a comment node.
Comments are skipped entirely in Typst output as they are meant for source-level documentation only.
- パラメータ:
node (
comment) -- The comment node- 例外:
nodes.SkipNode -- Always raised to skip the comment
- 戻り値の型:
- depart_comment(node)[ソース]¶
Depart a comment node.
- パラメータ:
node (
comment) -- The comment node- 戻り値の型:
注釈
This method is not called when SkipNode is raised in visit_comment.
- visit_raw(node)[ソース]¶
Visit a raw node.
Pass through content if format is 'typst', otherwise skip.
- パラメータ:
node (
raw) -- The raw node- 例外:
nodes.SkipNode -- When format is not 'typst'
- 戻り値の型:
- depart_raw(node)[ソース]¶
Depart a raw node.
- パラメータ:
node (
raw) -- The raw node- 戻り値の型:
注釈
This method is not called when SkipNode is raised in visit_raw.
- visit_Text(node)[ソース]¶
Visit a text node.
Wraps text in text() function for unified code mode. Uses string escaping (not markup escaping).
Exception: Inside literal blocks, text is output directly without text() wrapping to preserve code content.
- パラメータ:
node (
Text) -- The text node- 戻り値の型:
- visit_emphasis(node)[ソース]¶
Visit an emphasis (italic) node.
Generates emph() function call. Child text nodes will be wrapped in text() automatically.
- パラメータ:
node (
emphasis) -- The emphasis node- 戻り値の型:
- depart_emphasis(node)[ソース]¶
Depart an emphasis (italic) node.
Closes emph({}) function call.
- パラメータ:
node (
emphasis) -- The emphasis node- 戻り値の型:
- visit_strong(node)[ソース]¶
Visit a strong (bold) node.
Generates strong() function call. Child text nodes will be wrapped in text() automatically.
- パラメータ:
node (
strong) -- The strong node- 戻り値の型:
- depart_strong(node)[ソース]¶
Depart a strong (bold) node.
Closes strong({}) function call.
- パラメータ:
node (
strong) -- The strong node- 戻り値の型:
- visit_literal(node)[ソース]¶
Visit a literal (inline code) node.
Generates raw() function call with backtick raw string. Uses backticks to avoid escaping issues.
- パラメータ:
node (
literal) -- The literal node- 戻り値の型:
- depart_literal(node)[ソース]¶
Depart a literal (inline code) node.
This is not called when SkipNode is raised in visit_literal.
- パラメータ:
node (
literal) -- The literal node- 戻り値の型:
- visit_subscript(node)[ソース]¶
Visit a subscript node.
Generates sub() function call. Child text nodes will be wrapped in text() automatically.
- パラメータ:
node (
subscript) -- The subscript node- 戻り値の型:
- depart_subscript(node)[ソース]¶
Depart a subscript node.
Closes sub() function call.
- パラメータ:
node (
subscript) -- The subscript node- 戻り値の型:
- visit_superscript(node)[ソース]¶
Visit a superscript node.
Generates super() function call. Child text nodes will be wrapped in text() automatically.
- パラメータ:
node (
superscript) -- The superscript node- 戻り値の型:
- depart_superscript(node)[ソース]¶
Depart a superscript node.
Closes super() function call.
- パラメータ:
node (
superscript) -- The superscript node- 戻り値の型:
- visit_bullet_list(node)[ソース]¶
Visit a bullet list node.
Outputs list( and prepares for stream-based item rendering.
- パラメータ:
node (
bullet_list) -- The bullet list node- 戻り値の型:
- depart_bullet_list(node)[ソース]¶
Depart a bullet list node.
Closes the list() function.
- パラメータ:
node (
bullet_list) -- The bullet list node- 戻り値の型:
- visit_enumerated_list(node)[ソース]¶
Visit an enumerated (numbered) list node.
Outputs enum( and prepares for stream-based item rendering.
- パラメータ:
node (
enumerated_list) -- The enumerated list node- 戻り値の型:
- depart_enumerated_list(node)[ソース]¶
Depart an enumerated (numbered) list node.
Closes the enum() function.
- パラメータ:
node (
enumerated_list) -- The enumerated list node- 戻り値の型:
- visit_list_item(node)[ソース]¶
Visit a list item node.
Adds comma separator if not first item, then prepares for item content.
- パラメータ:
node (
list_item) -- The list item node- 戻り値の型:
- depart_list_item(node)[ソース]¶
Depart a list item node.
Close the { } block wrapper and mark that we're no longer in a list item.
- パラメータ:
node (
list_item) -- The list item node- 戻り値の型:
- visit_literal_block(node)[ソース]¶
Visit a literal block (code block) node.
Implements Task 4.2.2: codly forced usage with #codly-range() for highlighted lines Design 3.5: All code blocks use codly, with #codly-range() for highlights Requirements 7.3, 7.4: Support line numbers and highlighted lines Issue #20: Support :linenos:, :caption:, and :name: options Issue #31: Support :lineno-start: and :dedent: options
- パラメータ:
node (
literal_block) -- The literal block node- 戻り値の型:
- depart_literal_block(node)[ソース]¶
Depart a literal block (code block) node.
Issue #20: Handle closing figure bracket and labels.
- パラメータ:
node (
literal_block) -- The literal block node- 戻り値の型:
- visit_definition_list(node)[ソース]¶
Visit a definition list node.
Collects all term-definition pairs and generates terms() function in unified code mode.
- パラメータ:
node (
definition_list) -- The definition list node- 戻り値の型:
- depart_definition_list(node)[ソース]¶
Depart a definition list node.
Generates terms() function with all collected term-definition pairs.
- パラメータ:
node (
definition_list) -- The definition list node- 戻り値の型:
- visit_definition_list_item(node)[ソース]¶
Visit a definition list item node.
- パラメータ:
node (
definition_list_item) -- The definition list item node- 戻り値の型:
- depart_definition_list_item(node)[ソース]¶
Depart a definition list item node.
- パラメータ:
node (
definition_list_item) -- The definition list item node- 戻り値の型:
- visit_term(node)[ソース]¶
Visit a term (definition list term) node.
Starts buffering term content.
- パラメータ:
node (
term) -- The term node- 戻り値の型:
- depart_term(node)[ソース]¶
Depart a term (definition list term) node.
Saves buffered term content.
- パラメータ:
node (
term) -- The term node- 戻り値の型:
- visit_definition(node)[ソース]¶
Visit a definition (definition list definition) node.
Starts buffering definition content.
- パラメータ:
node (
definition) -- The definition node- 戻り値の型:
- depart_definition(node)[ソース]¶
Depart a definition (definition list definition) node.
Saves buffered definition content and pairs it with the term.
- パラメータ:
node (
definition) -- The definition node- 戻り値の型:
- visit_figure(node)[ソース]¶
Visit a figure node.
Generates figure() function call (no # prefix in code mode).
- パラメータ:
node (
figure) -- The figure node- 戻り値の型:
- visit_caption(node)[ソース]¶
Visit a caption node.
Handles captions for both figures and code blocks (Issue #20).
- パラメータ:
node (
caption) -- The caption node- 戻り値の型:
- visit_tgroup(node)[ソース]¶
Visit a tgroup (table group) node.
- パラメータ:
node (
tgroup) -- The tgroup node- 戻り値の型:
- depart_tgroup(node)[ソース]¶
Depart a tgroup (table group) node.
- パラメータ:
node (
tgroup) -- The tgroup node- 戻り値の型:
- visit_colspec(node)[ソース]¶
Visit a colspec (column specification) node.
- パラメータ:
node (
colspec) -- The colspec node- 戻り値の型:
- depart_colspec(node)[ソース]¶
Depart a colspec (column specification) node.
- パラメータ:
node (
colspec) -- The colspec node- 戻り値の型:
- visit_thead(node)[ソース]¶
Visit a thead (table header) node.
- パラメータ:
node (
thead) -- The thead node- 戻り値の型:
- depart_thead(node)[ソース]¶
Depart a thead (table header) node.
- パラメータ:
node (
thead) -- The thead node- 戻り値の型:
- visit_tbody(node)[ソース]¶
Visit a tbody (table body) node.
- パラメータ:
node (
tbody) -- The tbody node- 戻り値の型:
- depart_tbody(node)[ソース]¶
Depart a tbody (table body) node.
- パラメータ:
node (
tbody) -- The tbody node- 戻り値の型:
- visit_entry(node)[ソース]¶
Visit an entry (table cell) node.
- パラメータ:
node (
entry) -- The entry node- 戻り値の型:
- depart_entry(node)[ソース]¶
Depart an entry (table cell) node.
- パラメータ:
node (
entry) -- The entry node- 戻り値の型:
- visit_block_quote(node)[ソース]¶
Visit a block quote node.
Generates quote() function call (no # prefix in code mode).
- パラメータ:
node (
block_quote) -- The block quote node- 戻り値の型:
- depart_block_quote(node)[ソース]¶
Depart a block quote node.
- パラメータ:
node (
block_quote) -- The block quote node- 戻り値の型:
- visit_attribution(node)[ソース]¶
Visit an attribution node (quote attribution).
- パラメータ:
node (
attribution) -- The attribution node- 戻り値の型:
- depart_attribution(node)[ソース]¶
Depart an attribution node.
- パラメータ:
node (
attribution) -- The attribution node- 戻り値の型:
- visit_image(node)[ソース]¶
Visit an image node.
Generates image() function call (no # prefix in code mode). Adjusts image paths for nested documents (Issue #69).
- パラメータ:
node (
image) -- The image node- 戻り値の型:
- visit_target(node)[ソース]¶
Visit a target node (label definition).
- パラメータ:
node (
target) -- The target node- 戻り値の型:
- visit_pending_xref(node)[ソース]¶
Visit a pending_xref node (Sphinx cross-reference).
- パラメータ:
node (
Node) -- The pending_xref node- 戻り値の型:
- depart_pending_xref(node)[ソース]¶
Depart a pending_xref node.
- パラメータ:
node (
Node) -- The pending_xref node- 戻り値の型:
- visit_toctree(node)[ソース]¶
Visit a toctree node (Sphinx table of contents tree).
Requirement 13: Multi-document integration and toctree processing - Generate #include() for each entry - Apply #set heading(offset: 1) to lower heading levels - Issue #5: Fix relative paths for nested toctrees
Calculate relative paths from current document
Issue #7: Simplify toctree output with single content block - Generate single #[...] block containing all includes - Apply #set heading(offset: 1) once per toctree
- パラメータ:
node (
Node) -- The toctree node- 戻り値の型:
メモ
This method generates Typst #include() directives for each toctree entry within a single content block #[...] to apply heading offset without displaying the block delimiters in the output. This simplifies the generated Typst code and improves readability.
- visit_reference(node)[ソース]¶
Visit a reference node (link).
Generates link() function call (no # prefix in code mode).
- パラメータ:
node (
reference) -- The reference node- 戻り値の型:
- depart_reference(node)[ソース]¶
Depart a reference node.
- パラメータ:
node (
reference) -- The reference node- 戻り値の型:
- unknown_visit(node)[ソース]¶
Handle unknown nodes during visit.
- パラメータ:
node (
Node) -- The unknown node- 戻り値の型:
- unknown_departure(node)[ソース]¶
Handle unknown nodes during departure.
- パラメータ:
node (
Node) -- The unknown node- 戻り値の型:
- visit_math(node)[ソース]¶
Visit an inline math node.
Implements Task 6.2: LaTeX math conversion (mitex) Implements Task 6.3: Labeled equations Implements Task 6.4: Typst native math support Implements Task 6.5: Math fallback functionality Requirement 4.3: Inline math should use #mi(...) format (LaTeX) Requirement 4.9: Fallback when typst_use_mitex=False Requirement 5.2: Inline math should use $...$ format (Typst native) Requirement 4.7: Labeled equations should generate <eq:label> format Design 3.3: Support both mitex and Typst native math
- パラメータ:
node (
math) -- The inline math node- 戻り値の型:
- depart_math(node)[ソース]¶
Depart an inline math node.
- パラメータ:
node (
math) -- The inline math node- 戻り値の型:
- visit_math_block(node)[ソース]¶
Visit a block math node.
Implements Task 6.2: LaTeX math conversion (mitex) Implements Task 6.3: Labeled equations Implements Task 6.4: Typst native math support Implements Task 6.5: Math fallback functionality Requirement 4.2: Block math should use #mitex(...) format (LaTeX) Requirement 4.9: Fallback when typst_use_mitex=False Requirement 5.2: Block math should use $ ... $ format (Typst native) Requirement 4.7: Labeled equations should generate <eq:label> format Design 3.3: Support both mitex and Typst native math
- パラメータ:
node (
math_block) -- The block math node- 戻り値の型:
- depart_math_block(node)[ソース]¶
Depart a block math node.
- パラメータ:
node (
math_block) -- The block math node- 戻り値の型:
- visit_warning(node)[ソース]¶
Visit a warning admonition (converts to #warning[]).
- 戻り値の型:
- パラメータ:
node (warning)
- visit_important(node)[ソース]¶
Visit an important admonition (converts to #warning(title: "Important")[]).
- 戻り値の型:
- パラメータ:
node (important)
- visit_caution(node)[ソース]¶
Visit a caution admonition (converts to #warning[]).
- 戻り値の型:
- パラメータ:
node (caution)
- visit_inline(node)[ソース]¶
Visit an inline node.
Inline nodes are generic containers for inline content. They are often used for cross-references with specific CSS classes.
Task 7.4: Handle inline nodes, especially those with 'xref' class Requirement 3.1: Cross-references and links
- 戻り値の型:
- パラメータ:
node (inline)
- visit_index(node)[ソース]¶
Visit an index node.
Index entries are skipped in Typst/PDF output as we don't generate indices.
- visit_desc(node)[ソース]¶
Visit a desc node (API description container).
Desc nodes contain API descriptions (classes, functions, methods, etc.).
- visit_desc_signature(node)[ソース]¶
Visit a desc_signature node (API element signature).
Signatures are rendered in bold using strong({}) wrapper.
- 戻り値の型:
- パラメータ:
node (desc_signature)
- depart_desc_signature(node)[ソース]¶
Depart a desc_signature node.
- 戻り値の型:
- パラメータ:
node (desc_signature)
- visit_desc_content(node)[ソース]¶
Visit a desc_content node (API description content).
- 戻り値の型:
- パラメータ:
node (desc_content)
- depart_desc_content(node)[ソース]¶
Depart a desc_content node.
- 戻り値の型:
- パラメータ:
node (desc_content)
- visit_desc_annotation(node)[ソース]¶
Visit a desc_annotation node (type annotations like 'class', 'async', etc.).
- 戻り値の型:
- パラメータ:
node (desc_annotation)
- depart_desc_annotation(node)[ソース]¶
Depart a desc_annotation node.
Space after annotation is handled by desc_sig_space node.
- 戻り値の型:
- パラメータ:
node (desc_annotation)
- visit_desc_addname(node)[ソース]¶
Visit a desc_addname node (module name prefix).
- 戻り値の型:
- パラメータ:
node (desc_addname)
- depart_desc_addname(node)[ソース]¶
Depart a desc_addname node.
- 戻り値の型:
- パラメータ:
node (desc_addname)
- visit_desc_parameterlist(node)[ソース]¶
Visit a desc_parameterlist node (parameter list container).
Parameters are concatenated with + inside text parentheses.
- 戻り値の型:
- パラメータ:
node (desc_parameterlist)
- depart_desc_parameterlist(node)[ソース]¶
Depart a desc_parameterlist node.
- 戻り値の型:
- パラメータ:
node (desc_parameterlist)
- visit_desc_parameter(node)[ソース]¶
Visit a desc_parameter node (individual parameter).
- 戻り値の型:
- パラメータ:
node (desc_parameter)
- depart_desc_parameter(node)[ソース]¶
Depart a desc_parameter node.
Add comma + space between parameters if not last.
- 戻り値の型:
- パラメータ:
node (desc_parameter)
- visit_field_list(node)[ソース]¶
Visit a field_list node (structured fields like Parameters, Returns).
- 戻り値の型:
- パラメータ:
node (field_list)
- depart_field_list(node)[ソース]¶
Depart a field_list node.
Add spacing after field lists.
- 戻り値の型:
- パラメータ:
node (field_list)
- visit_field(node)[ソース]¶
Visit a field node (individual field in a field list).
- 戻り値の型:
- パラメータ:
node (field)
- visit_field_name(node)[ソース]¶
Visit a field_name node (field name like 'Parameters', 'Returns').
Field names are rendered in bold with a colon (no # prefix in code mode).
- 戻り値の型:
- パラメータ:
node (field_name)
- visit_field_body(node)[ソース]¶
Visit a field_body node (field content).
- 戻り値の型:
- パラメータ:
node (field_body)
- depart_field_body(node)[ソース]¶
Depart a field_body node.
Add newline after field body.
- 戻り値の型:
- パラメータ:
node (field_body)
- visit_rubric(node)[ソース]¶
Visit a rubric node (section subheading).
Rubrics are rendered as subsection headings using strong({}) wrapper.
- 戻り値の型:
- パラメータ:
node (rubric)
- visit_title_reference(node)[ソース]¶
Visit a title_reference node (reference to a title).
Title references are rendered in emphasis using emph({}) wrapper.
- 戻り値の型:
- パラメータ:
node (title_reference)
- depart_title_reference(node)[ソース]¶
Depart a title_reference node.
- 戻り値の型:
- パラメータ:
node (title_reference)
- visit_desc_sig_keyword(node)[ソース]¶
Visit a desc_sig_keyword node (keywords in signatures like 'class', 'def').
- 戻り値の型:
- パラメータ:
node (desc_sig_keyword)
- depart_desc_sig_keyword(node)[ソース]¶
Depart a desc_sig_keyword node.
- 戻り値の型:
- パラメータ:
node (desc_sig_keyword)
- visit_desc_sig_space(node)[ソース]¶
Visit a desc_sig_space node (whitespace in signatures).
- 戻り値の型:
- パラメータ:
node (desc_sig_space)
- depart_desc_sig_space(node)[ソース]¶
Depart a desc_sig_space node.
- 戻り値の型:
- パラメータ:
node (desc_sig_space)
- visit_desc_sig_name(node)[ソース]¶
Visit a desc_sig_name node (names in signatures).
- 戻り値の型:
- パラメータ:
node (desc_sig_name)
- depart_desc_sig_name(node)[ソース]¶
Depart a desc_sig_name node.
- 戻り値の型:
- パラメータ:
node (desc_sig_name)
- visit_desc_sig_punctuation(node)[ソース]¶
Visit a desc_sig_punctuation node (punctuation in signatures like ':', '=').
- 戻り値の型:
- パラメータ:
node (desc_sig_punctuation)
- depart_desc_sig_punctuation(node)[ソース]¶
Depart a desc_sig_punctuation node.
- 戻り値の型:
- パラメータ:
node (desc_sig_punctuation)
- visit_desc_sig_operator(node)[ソース]¶
Visit a desc_sig_operator node (operators in signatures).
- 戻り値の型:
- パラメータ:
node (desc_sig_operator)
- depart_desc_sig_operator(node)[ソース]¶
Depart a desc_sig_operator node.
- 戻り値の型:
- パラメータ:
node (desc_sig_operator)
- visit_literal_strong(node)[ソース]¶
Visit a literal_strong node (bold literal text in field lists).
- 戻り値の型:
- パラメータ:
node (inline)
Template Engine¶
Template engine for Typst document generation.
This module implements template loading, parameter mapping, and rendering for Typst documents (Requirement 8).
- class typsphinx.template_engine.TemplateEngine(template_path=None, template_name=None, search_paths=None, parameter_mapping=None, typst_package=None, typst_template_function=None, typst_package_imports=None, typst_authors=None, typst_author_params=None)[ソース]¶
ベースクラス:
objectManages Typst templates for document generation.
Responsibilities: - Load default or custom Typst templates - Search templates in multiple directories with priority - Provide fallback to default template when custom template not found - Map Sphinx metadata to template parameters - Render final Typst document with template and content
Requirement 8.1: Default Typst template included in package Requirement 8.2: Support custom template specification Requirement 8.7: Priority search in user project directory Requirement 8.9: Fallback to default template with warning
- パラメータ:
- DEFAULT_PARAMETER_MAPPING = {'author': 'authors', 'project': 'title', 'release': 'date'}¶
- get_default_template_path()[ソース]¶
Get the path to the default template bundled with the package.
- 戻り値の型:
- 戻り値:
Absolute path to default template file
- load_template()[ソース]¶
Load Typst template with priority order: 1. Explicit template_path if provided 2. Search for template_name in search_paths (first match wins) 3. Default template bundled with package
- 戻り値の型:
- 戻り値:
Template content as string
Requirement 8.1: Load default template Requirement 8.2: Load custom template Requirement 8.7: Search in user project directory Requirement 8.9: Fallback to default with warning
- map_parameters(sphinx_metadata)[ソース]¶
Map Sphinx metadata to template parameters.
- パラメータ:
sphinx_metadata (
Dict[str,Any]) -- Dictionary of Sphinx configuration metadata (project, author, release, etc.)- 戻り値の型:
- 戻り値:
Dictionary of template parameters ready to pass to template
Requirement 8.3: Pass Sphinx metadata to template Requirement 8.4: Support different parameter names Requirement 8.5: Standard metadata name transformation Requirement 8.8: Convert to arrays and complex structures
- generate_package_import()[ソース]¶
Generate Typst package import statement.
- 戻り値の型:
- 戻り値:
Import statement string, or empty string if no package specified
Requirement 8.6: Typst Universe external template packages
- extract_toctree_options(doctree)[ソース]¶
Extract toctree options from doctree for template parameters.
- パラメータ:
doctree (
Any) -- Docutils document tree- 戻り値の型:
- 戻り値:
Dictionary of toctree options for template
Requirement 8.12: toctree options passed as template parameters Requirement 8.13: template reflects toctree options in #outline() Requirement 13.8: #outline() managed at template level Requirement 13.9: toctree options mapped to template parameters
- get_template_content()[ソース]¶
Get the template content for writing to a separate file.
- 戻り値の型:
- 戻り値:
Template content as string
This is used when templates are written as separate files instead of being inlined in the main document.
Configuration¶
Configuration values are registered in the main __init__.py module.
Available Configuration Values¶
Name |
Description |
Default |
|---|---|---|
|
List of documents to build |
|
|
Path to custom template file |
|
|
Template function name or dict |
|
|
Typst Universe package |
|
|
Detailed author information |
|
|
Use mitex for LaTeX math |
|
|
Use codly for code highlighting |
|
|
Show line numbers in code blocks |
|
|
Paper size (e.g., "a4", "us-letter") |
|
|
Base font size |
|
See Configuration for detailed usage of each option.