Documentation Generator#
Implementation#
- class clanguru.doc_generator.CodeContent(code: str, language: str = 'c', linenos: bool = True, highlight_lines: list[int] | None = None, start_line: int | None = None)[source]#
Bases:
object
- class clanguru.doc_generator.DocStructure(title: str)[source]#
Bases:
objectFormat independent documentation structure.
- class clanguru.doc_generator.DocsFormat(*values)[source]#
Bases:
Enum- property format_tag: str#
Return the tag used in source comments for this format.
- class clanguru.doc_generator.MarkdownFormatter(flavour: MarkdownFlavour = MarkdownFlavour.Raw, *, jinja_raw_tags: bool = False)[source]#
Bases:
OutputFormatterMarkdown output formatter for documentation.
Two flavours are supported: * Raw: plain GitHub style fenced code blocks. * Myst: MystParser extended
code-blockdirective with options (linenos & highlight lines).- property docs_format: DocsFormat#
Return the documentation format for this formatter.
- format(doc: DocStructure) str[source]#
Format the entire documentation structure.
- format_code(content: CodeContent) str[source]#
Format a code block.
- format_code_block_myst(content: CodeContent) str[source]#
Return a fenced code block or Myst code-block directive.
Myst format example:
```{code-block} c :linenos: :lineno-start: 5 :emphasize-lines: 2,4 int main() {} ```
- class clanguru.doc_generator.OutputFormatter[source]#
Bases:
ABCAbstract base class for output formatters.
- abstract property docs_format: DocsFormat#
Return the documentation format for this formatter.
- abstractmethod format(doc: DocStructure) str[source]#
Format the entire documentation structure.
- abstractmethod format_code(content: CodeContent) str[source]#
Format a code block.
- class clanguru.doc_generator.RSTFormatter(*, jinja_raw_tags: bool = False)[source]#
Bases:
OutputFormatterreStructuredText output formatter for documentation.
- property docs_format: DocsFormat#
Return the documentation format for this formatter.
- format(doc: DocStructure) str[source]#
Format the entire documentation structure.
- format_code(content: CodeContent) str[source]#
Format a code block.
- clanguru.doc_generator.generate_doc_structure(translation_unit: TranslationUnit, docs_format: DocsFormat = DocsFormat.md) DocStructure[source]#
Generate documentation structure from a translation unit.
Uses the CLangParser to extract functions and classes from the translation unit and creates a DocStructure object with the extracted information.
- clanguru.doc_generator.generate_documentation(translation_unit: TranslationUnit, formatter: OutputFormatter, output_file: Path) None[source]#
Generate documentation from a translation unit and write it to a file using the specified formatter.
Testing#
- test_doc_generator.test_crlf_line_endings_function_body_extraction(tmp_path: Path) None[source]#
Regression test: ensure CRLF line endings donβt truncate function bodies.
We create two identical source files differing only by newline style (LF vs CRLF) and confirm the extracted function bodies are identical.
- test_doc_generator.test_crlf_line_endings_function_comment_extraction(tmp_path: Path) None[source]#
Regression test: ensure CRLF line endings in function comments are normalized.
We create two identical source files with multi-line comments differing only by newline style (LF vs CRLF) and confirm the extracted comment content is identical and uses normalized LF line endings.
- test_doc_generator.test_end_to_end_c_source_to_markdown_file(tmp_path: Path) None[source]#
End-to-end: parse a .c file, generate a .md file, and verify its exact content.
Uses @docs (generic) and @md (format-specific) tagged blocks between /* START DOCS */ and /* END DOCS */ markers. Untagged comments are ignored. An @rst block would also be ignored when generating markdown.