Skip to content

Module generate:markdown

Summary

The generate:markdown module defines a structured representation for Markdown documents and provides the public API to construct and render them. Its public interfaces include node types such as MarkdownDocument, MarkdownNode, Paragraph, CodeFence, BlockQuote, BulletList, MermaidDiagram, RawMarkdown, TextFragment, CodeFragment, LinkFragment, ListItem, and SemanticSection, along with the SemanticKind enum. The module exposes factory functions like make_text, make_code, make_link, make_paragraph, make_raw_markdown, make_code_fence, make_mermaid, make_blockquote, and make_section, as well as top‑level functions render_markdown, code_spanned_markdown, and code_spanned_fragments for producing final output.

Imports

  • std

Imported By

Types

clore::generate::BlockQuote

Declaration: generate/markdown.cppm:62

Definition: generate/markdown.cppm:62

Declaration: Namespace clore::generate

实现 clore::generate::BlockQuote 的核心是一个 std::vector<InlineFragment> 类型的 fragments 数据成员,用于按顺序存储引用块内的所有内联元素。该结构体借此实现对引用内容的平坦化表达:每个 InlineFragment 对应一段连续的内联文本或样式标记,整个 fragments 向量则完整描述了引用块的正文部分。出于性能考虑,设计上通过直接操作 fragments 来完成内容构建,不引入额外的冗余状态或计数器,因此不变量仅要求 fragments 中的元素必须保持有效的、可被下游序列化步骤正确解释的排列顺序。

Invariants

  • fragments 中的元素顺序表示内联内容的逻辑顺序。

Key Members

  • fragments

Usage Patterns

  • 作为文档生成中块引用的表示被其他生成代码构造和填充。
  • fragments 成员被遍历以生成对应的输出格式。

clore::generate::BulletList

Declaration: generate/markdown.cppm:49

Definition: generate/markdown.cppm:49

Declaration: Namespace clore::generate

该结构体仅包含一个 std::vector<ListItem> items 成员,作为子弹列表条目的容器。内部不存在其他成员或状态,因此其唯一的不变式是 items 向量的元素在逻辑上应构成一个合理的子弹列表序列;具体有效性的维护依赖于外部代码对该向量的操作。结构体本身不提供任何构造函数或方法,所有插入、遍历和修改都直接作用于 items 成员,使其成为一个纯粹的数据持有者。

Invariants

  • items 存储所有的列表项,顺序与显示顺序一致。
  • items 可以包含任意数量的 ListItem,包括零个。

Key Members

  • items:保存所有子弹列表项的向量。

Usage Patterns

  • 通过直接初始化或聚合初始化创建 BulletList 实例并填充 items
  • BulletList 对象传递给 Markdown 生成函数以渲染为无序列表。

clore::generate::CodeFence

Declaration: generate/markdown.cppm:53

Definition: generate/markdown.cppm:53

Declaration: Namespace clore::generate

clore::generate::CodeFence 是一个简单数据持有者,其内部结构仅由两个 std::string 成员 languagecode 组成,分别存储围栏的语言标识和代码主体。该结构体不定义任何自定义构造函数、析构函数或其他成员函数,因此其生命周期的管理完全依赖编译器生成的默认操作。不变量仅在于 languagecode 的内容与外部传入的值一致,结构体本身不施加任何格式或语义约束——这两个字符串可以是任意合法值,包括空字符串。由于 std::string 的存在,实例的复制和移动开销可能较高,但结构体本身为平凡的聚合类型,支持聚合初始化。

Invariants

  • language should be a valid language identifier string.
  • code may be empty or contain any text.

Key Members

  • language: language identifier for the code block.
  • code: the code content.

Usage Patterns

  • Used as a data holder for code fences in Markdown generation.
  • Likely constructed and then serialized into Markdown output.

clore::generate::CodeFragment

Declaration: generate/markdown.cppm:29

Definition: generate/markdown.cppm:29

Declaration: Namespace clore::generate

clore::generate::CodeFragment 的实现是一个简单的聚合类型,仅包含一个 std::string code 成员。该成员负责存储最终的代码文本,是结构体的唯一数据来源。内部没有任何额外的构造函数或成员函数,因此其构造和复制行为完全由编译器默认生成,依赖聚合初始化。该设计使得 CodeFragment 保持极简,仅作为代码片段的轻量容器,其内部状态仅由 code 字符串的字符串语义管理,不引入额外的生命周期或所有权约束。

Key Members

  • code field

Usage Patterns

  • Used to represent a fragment of generated code as a string

clore::generate::Frontmatter

Declaration: generate/markdown.cppm:18

Definition: generate/markdown.cppm:18

Declaration: Namespace clore::generate

clore::generate::Frontmatter 是一个仅包含数据的结构体,用作生成文档的前置元数据块。它有四个 std::string 成员:titledescriptionlayoutpage_template,其中 layoutpage_template 都被默认初始化为 "doc"。这些成员直接存储了文档的标题、描述、布局模板以及页面模板标识,构成了一个不可变的前置元数据集。该结构体没有定义构造函数或成员函数,其不变式仅由默认值保证,调用者应确保所有字符串成员在使用前已被正确赋值。

Invariants

  • layout defaults to "doc"
  • page_template defaults to "doc"
  • All fields are std::string and can be set to any value

Key Members

  • title
  • description
  • layout
  • page_template

Usage Patterns

  • Constructed with default values for typical documentation pages
  • Fields are assigned individually before serialization
  • Consumed by frontmatter generation code in the clore::generate namespace

clore::generate::LinkFragment

Declaration: generate/markdown.cppm:33

Definition: generate/markdown.cppm:33

Declaration: Namespace clore::generate

该结构体是一个简单数据聚合,用于存储 Markdown 链接片段的原始组件。label 保存链接的显示文本,target 保存链接的目标路径或 URL,code_style 标志指示是否应将标签呈现为行内代码样式。三者之间不存在运行时不变性,但通常 labeltarget 应当为非空字符串,且 code_styletrue 时暗示 label 在最终输出中应被包裹代码标记。该结构体本身不提供任何修改或验证逻辑,完全依赖使用方保证语义一致性。

Invariants

  • No documented invariants

Key Members

  • label
  • target
  • code_style

Usage Patterns

  • No documented usage patterns

clore::generate::ListItem

Declaration: generate/markdown.cppm:45

Definition: generate/markdown.cppm:45

Declaration: Namespace clore::generate

clore::generate::ListItem 是一个简单的聚合结构体,其唯一数据成员 fragments 是一个 std::vector<InlineFragment>。该向量的顺序性构成核心不变量:片段按索引排列的顺序直接映射列表项内容的逻辑顺序,且外部代码依赖此顺序完成渲染。结构体未提供任何成员函数或构造函数,因此对 fragments 的填充与访问完全由调用方通过直接成员访问完成。

Invariants

  • fragments 存储了列表项的所有行内片段

Key Members

  • fragments

Usage Patterns

  • 被其他代码用于构建和表示 Markdown 列表的单个列表项

clore::generate::MarkdownDocument

Declaration: generate/markdown.cppm:94

Definition: generate/markdown.cppm:94

Declaration: Namespace clore::generate

结构体 clore::generate::MarkdownDocument 的内部状态完全由两个字段构成:frontmatter 是一个可选的 Frontmatter 实例,存储文档的 YAML 前置元数据;children 是一个 std::vector<MarkdownNode> 容器,保存文档的主体内容节点序列。这两个字段共同描述了整个 Markdown 文档的拆分表示。关键在于 frontmatter 仅在存在时才提供元数据,且其内容与 children 中相邻节点(通常是首节点)之间没有显式的层叠顺序约束,调用者需自行保证前置元数据逻辑上位于主体内容之前。整个结构体无用户自定义构造函数或赋值操作,依赖编译器生成的默认实现,因此 frontmatterchildren 的初始状态为空(即 std::nullopt 和空向量)。

clore::generate::MarkdownNode

Declaration: generate/markdown.cppm:73

Definition: generate/markdown.cppm:73

Declaration: Namespace clore::generate

clore::generate::MarkdownNode 是一个纯聚合结构,其唯一成员 value 是一个 std::variant,封装了七种具体的 Markdown 节点类型。这种设计使得节点在运行时可以动态持有 ParagraphBulletListCodeFenceMermaidDiagramBlockQuoteRawMarkdownSemanticSectionPtr 中的任意一种,且保证了在任何时刻变体恰好包含一个有效备选项。结构体本身未定义任何构造函数、析构函数或赋值运算符,完全依赖编译器生成的特殊成员函数,因此 value 的 invariants 完全由 std::variant 自身维护。

clore::generate::MermaidDiagram

Declaration: generate/markdown.cppm:58

Definition: generate/markdown.cppm:58

Declaration: Namespace clore::generate

结构体 clore::generate::MermaidDiagram 是一个极其简单的数据持有者,其唯一内部状态存储于公开成员 code 中,类型为 std::string。该成员用于承载待渲染或输出的 Mermaid 图表的文本表示。结构体不包含任何其他数据成员、构造函数(除编译器生成的默认构造外)或成员函数,因此它的全部不变量依赖于 code 的内容在结构体的使用上下文中具有有效的 Mermaid 语法——但结构体本身不执行任何验证或约束。其实现本质上是一个轻量级包装器,仅在需要传递 Mermaid 代码字符串时提供类型安全,避免裸字符串带来的歧义。

Key Members

  • code

Usage Patterns

  • Instantiated to store a Mermaid diagram code string
  • Accessed to retrieve or set the diagram source

clore::generate::Paragraph

Declaration: generate/markdown.cppm:41

Definition: generate/markdown.cppm:41

Declaration: Namespace clore::generate

clore::generate::Paragraph 内部仅包含一个 std::vector<InlineFragment> fragments 字段,作为段落内容的顺序容器。其核心不变量在于 fragments 中的元素按文本流顺序排列,且每个片段均符合 InlineFragment 的类型约束。该结构体不维护额外状态,所有逻辑通过 fragments 的序列操作隐式表达,例如通过 push_backemplace_back 追加片段,或利用 std::vector 的迭代器进行遍历与拼接。

Invariants

  • Fragments are stored in the order they appear in the paragraph.

Key Members

  • fragments

Usage Patterns

  • Constructed by populating fragments with inline elements.
  • Iterated over to process or render the paragraph.

clore::generate::RawMarkdown

Declaration: generate/markdown.cppm:66

Definition: generate/markdown.cppm:66

Declaration: Namespace clore::generate

结构体 clore::generate::RawMarkdown 是一个仅包含单个 std::string 成员 markdown 的聚合类型。它作为纯数据持有者而存在,没有自定义构造函数、赋值操作或成员函数。唯一的不变量是 markdown 应包含符合调用方预期格式的原始 Markdown 文本;该结构体本身不对其内容施加任何验证或转换。实现仅依赖 std::string 的默认构造、复制和移动语义,从而保持轻量且易于集成到生成流程中。

Invariants

  • markdown 包含任意字符串内容,通常为 Markdown 格式的文本。

Key Members

  • markdown:存储原始 Markdown 字符串的成员变量。

Usage Patterns

  • 作为数据传输对象,在生成过程中传递 Markdown 内容。
  • 可能被其他模块读取用于写入文件或进一步处理。

clore::generate::SemanticKind

Declaration: generate/markdown.cppm:7

Definition: generate/markdown.cppm:7

Declaration: Namespace clore::generate

枚举 clore::generate::SemanticKind 使用 std::uint8_t 作为底层类型,以紧凑的形式表示内部代码元素的语义类别。其枚举值 IndexNamespaceModuleTypeFunctionVariableFileSection 按特定顺序定义,覆盖了文档生成过程中需要区分的所有主要实体类型。该顺序本身在实现中不保证任何语义优先级,但作为一个内部分类标签,用于在后续处理中快速判断当前元素的种类并执行对应的格式化或链接逻辑。每个枚举值都是唯一且正交的,共同构成了一个封闭的语义标签集合。

Invariants

  • Each enumerator corresponds to a unique semantic kind.
  • The underlying type is std::uint8_t.

Key Members

  • Index
  • Namespace
  • Module
  • Type
  • Function
  • Variable
  • File
  • Section

Usage Patterns

  • Used to specify the kind of a semantic symbol.
  • Used to dispatch generation logic per kind.

Member Variables

clore::generate::SemanticKind::File

Declaration: generate/markdown.cppm:14

Declaration: Namespace clore::generate

Implementation
cpp
File
clore::generate::SemanticKind::Function

Declaration: generate/markdown.cppm:12

Declaration: Namespace clore::generate

Implementation
cpp
Function
clore::generate::SemanticKind::Index

Declaration: generate/markdown.cppm:8

Declaration: Namespace clore::generate

Implementation
cpp
Index
clore::generate::SemanticKind::Module

Declaration: generate/markdown.cppm:10

Declaration: Namespace clore::generate

Implementation
cpp
Module
clore::generate::SemanticKind::Namespace

Declaration: generate/markdown.cppm:9

Declaration: Namespace clore::generate

Implementation
cpp
Namespace
clore::generate::SemanticKind::Section

Declaration: generate/markdown.cppm:15

Declaration: Namespace clore::generate

Implementation
cpp
Section
clore::generate::SemanticKind::Type

Declaration: generate/markdown.cppm:11

Declaration: Namespace clore::generate

Implementation
cpp
Type
clore::generate::SemanticKind::Variable

Declaration: generate/markdown.cppm:13

Declaration: Namespace clore::generate

Implementation
cpp
Variable

clore::generate::SemanticSection

Declaration: generate/markdown.cppm:70

Definition: generate/markdown.cppm:84

Declaration: Namespace clore::generate

clore::generate::SemanticSection 是一个聚合类型,用于表示语义章节的内部结构。其字段配置了章节的元数据和内容层次:kind 默认初始化为 SemanticKind::Sectionlevel 默认为 2,使得一般章节的标题为二级标题;omit_if_empty 默认为 true,决定了当 children 为空时是否应当省略该章节;code_style_heading 默认为 false,控制标题是否使用代码样式渲染。核心字段 children 持有 std::vector<MarkdownNode>,构成了章节的内容主体,而 heading 字符串存储标题文本,subject_key 可能用于关联主题标识。这些字段的默认值共同维护了一个不变性:除非显式覆盖,语义章节默认具有二级标题并在内容为空时自动隐藏,从而简化了典型用例的实现。

Invariants

  • level 通常为正整数(默认2),表示标题级别
  • omit_if_empty 为 true 且 children 为空,则章节可能被省略

Key Members

  • SemanticKind kind
  • std::string heading
  • std::uint8_t level
  • bool omit_if_empty
  • bool code_style_heading
  • std::vector<MarkdownNode> children
  • std::string subject_key

Usage Patterns

  • 作为树节点通过 children 容器构建嵌套章节结构
  • 在生成文档时根据 kindheading 格式化输出
  • 用于模块或命名空间等实体的语义注释生成

clore::generate::TextFragment

Declaration: generate/markdown.cppm:25

Definition: generate/markdown.cppm:25

Declaration: Namespace clore::generate

该结构体是一个极简的聚合类型,仅包含一个 std::string text 字段。由于未显式定义任何特殊成员函数,编译器会隐式生成默认构造、析构、复制和移动操作,使得 clore::generate::TextFragment 的行为与一个普通的字符串包装器一致。不变量方面没有额外约束:text 成员可以包含任何有效的 std::string 内容,包括空字符串。内部实现直接依赖 std::string 的复杂管理逻辑(如动态分配、小字符串优化等),但结构体本身并不介入这些细节。

Invariants

  • text can be any valid std::string.
  • No additional constraints beyond those of std::string.

Key Members

  • text: the stored string content

Usage Patterns

  • Used to pass or store a piece of text in the markdown generation pipeline.
  • Likely aggregated into larger structures or sequences.

Functions

clore::generate::code_spanned_fragments

Declaration: generate/markdown.cppm:124

Definition: generate/markdown.cppm:693

Declaration: Namespace clore::generate

函数 clore::generate::code_spanned_fragments 的实现将输入文本传递给匿名命名空间中的辅助函数 append_code_spanned_fragments,由后者完成主要工作。该辅助函数遍历文本,维护一个位置指针 pos,并基于一系列内联解析函数(如 read_backtick_spanread_code_candidateread_operator_tokenread_link_spanread_angle_suffixread_call_suffix)逐步识别代码片段、普通文本、链接及特定语法元素。解析过程中会调用 is_code_candidate 判断当前位置是否可能为代码开始,使用 has_camel_case_boundaryhas_identifier_separator 辅助代码边界判定,并通过 trim_code_candidateyaml_quote 等函数对提取的代码片段进行规范化。识别出的每个片段被包装为 TextFragmentCodeFragmentLinkFragment(后两者通过 code_style 布尔字段标记是否需要渲染为行内代码),并追加到 fragments 向量中。整个控制流围绕 pos 在文本中逐步前移,直到遍历完所有字符,最终返回填充好的碎片向量。该函数的主要依赖是匿名命名空间内的一系列解析辅助函数和片段类型,这些组件共同实现了代码感知的文本分割逻辑。

Side Effects

No observable side effects are evident from the extracted code.

Reads From

  • text parameter

Usage Patterns

  • Used to extract code spans from a given string
  • Delegates to append_code_spanned_fragments

clore::generate::code_spanned_markdown

Declaration: generate/markdown.cppm:126

Definition: generate/markdown.cppm:699

Declaration: Namespace clore::generate

该函数遍历输入字符串 markdown,逐行扫描以区分代码栅栏内的文本和普通文本。算法维护一个布尔标志 in_fence,每遇到通过 is_fence_line 检测到的栅栏行时切换该标志。在栅栏内部,所有行原样追加到输出字符串 rendered 中;在栅栏外部,每行由 append_code_spanned_line 处理,该函数负责将行内的内联代码元素(如标识符、类型名等)包裹成 Markdown 代码跨度。函数在整个过程中保留换行符(除非遇到文件末尾),最终返回拼接好的 rendered 字符串。

内部控制流完全围绕行迭代器 line_startline_end 构建,依赖 std::string_view::find 定位换行符,并利用 is_fence_lineappend_code_spanned_line 这两个匿名命名空间内的辅助函数完成具体判断与转换。没有额外的外部依赖,仅使用标准库字符串操作。

Side Effects

No observable side effects are evident from the extracted code.

Reads From

  • markdown parameter

Usage Patterns

  • convert plain markdown to code-spanned markdown

clore::generate::make_blockquote

Declaration: generate/markdown.cppm:113

Definition: generate/markdown.cppm:169

Declaration: Namespace clore::generate

clore::generate::make_blockquote 的实现极为精简:它接收一个 std::string 类型的 text,然后构造一个 MarkdownNode,其内部包含一个 BlockQuote 结构体。该 BlockQuotefragments 成员被初始化为一个单元素列表,该元素由调用 make_text 并将 text 移动进去得到。因此,整个函数的控制流就是一次对 make_text 的委托调用和一次简单的聚合初始化。它的唯一内部依赖是 make_text,后者负责将纯文本转换为一个基本的 MarkdownNode(很可能是一个 TextFragment)。该函数没有额外的逻辑,例如多行分割、嵌套检测或引用标记处理,这些细节完全交由上层的 BlockQuote 结构体在渲染阶段通过 prefix_blockquote_lines 等辅助函数完成。

Side Effects

No observable side effects are evident from the extracted code.

Reads From

  • text parameter

Usage Patterns

  • Create blockquote markdown nodes
  • Called when generating markdown content

clore::generate::make_code

Declaration: generate/markdown.cppm:101

Definition: generate/markdown.cppm:136

Declaration: Namespace clore::generate

函数 clore::generate::make_code 是一个工厂,将传入的字符串 code 封装为 CodeFragment 并直接返回。它通过移动 codeCodeFragmentcode 字段构造实例,不涉及任何条件判断或循环。该函数依赖 CodeFragment 结构体的定义,没有其他内部状态或副作用,是生成内联代码片段的轻量入口。

Side Effects

No observable side effects are evident from the extracted code.

Reads From

  • 参数 code

Writes To

  • 返回的 InlineFragment 对象中的 code 字段

Usage Patterns

  • 在 Markdown 渲染中创建内联代码
  • 包装字符串为代码片段

clore::generate::make_code_fence

Declaration: generate/markdown.cppm:109

Definition: generate/markdown.cppm:156

Declaration: Namespace clore::generate

该函数通过构造一个包含 CodeFenceMarkdownNode 来工作,其中 CodeFencelanguagecode 字段由输入参数通过移动赋值填充。它没有复杂的控制流或分支;其核心逻辑就是构造函数调用和移动操作。依赖项包括 MarkdownNodeCodeFence 这两个数据结构。

Side Effects

No observable side effects are evident from the extracted code.

Reads From

  • parameters language and code

Writes To

  • returned MarkdownNode

Usage Patterns

  • Used to generate a code fence MarkdownNode for embedding code snippets in documentation.

Declaration: generate/markdown.cppm:103

Definition: generate/markdown.cppm:140

Declaration: Namespace clore::generate

clore::generate::make_link 是其实现中最简单的工厂函数之一:它直接从三个参数构造一个 LinkFragment 结构体实例。labeltargetcode_style 分别被复制到结果对象的对应字段中,没有进行任何转换或验证。该函数不涉及内部控制流分支或循环,其全部依赖仅在于 LinkFragment 类型的定义以及 std::move 对字符串参数的高效转移。

Side Effects

No observable side effects are evident from the extracted code.

Reads From

  • label
  • target
  • code_style

Usage Patterns

  • Building inline links for markdown generation
  • Creating link fragments with optional code formatting

clore::generate::make_mermaid

Declaration: generate/markdown.cppm:111

Definition: generate/markdown.cppm:165

Declaration: Namespace clore::generate

函数 clore::generate::make_mermaid 的实现极为简洁:它接受一个 std::string code 参数,就地构造一个 clore::generate::MermaidDiagram 实例,将该实例的 code 成员初始化为传入的代码内容,然后将该实例包装进一个 clore::generate::MarkdownNode 并返回。内部没有条件分支、循环或辅助调用,唯一的外部依赖是 clore::generate::MermaidDiagram 结构体与 clore::generate::MarkdownNode 的聚合构造。该函数是 clore::generate 命名空间中面向用户的工厂之一,为后续的 Markdown 渲染管道提供原始 mermaid 图数据。

Side Effects

No observable side effects are evident from the extracted code.

Reads From

  • parameter code

Writes To

  • the returned MarkdownNode holding a MermaidDiagram

Usage Patterns

  • Wrap Mermaid diagram code into a MarkdownNode for markdown generation

clore::generate::make_paragraph

Declaration: generate/markdown.cppm:105

Definition: generate/markdown.cppm:148

Declaration: Namespace clore::generate

clore::generate::make_paragraph 的实现非常直接。它将传入的文本字符串通过 make_text 转换为 TextFragment,然后构造一个包含该片段的 Paragraph 对象,最后将该段落包装为 MarkdownNode 并返回。整个流程不涉及任何条件分支或状态循环,其唯一的外部依赖是 make_text,用于生成基础文本片段。该函数不进行任何解析、格式检测或嵌套结构调整,仅仅创建一个无结构的段落节点。

Side Effects

No observable side effects are evident from the extracted code.

Reads From

  • text parameter

Writes To

  • returned MarkdownNode

Usage Patterns

  • creating a paragraph markdown element
  • wrapping text into a paragraph node

clore::generate::make_raw_markdown

Declaration: generate/markdown.cppm:107

Definition: generate/markdown.cppm:152

Declaration: Namespace clore::generate

clore::generate::make_raw_markdown 的实现极为简洁:它接受一个 std::string 类型的 markdown 参数,将其移动构造到 RawMarkdown 结构的 markdown 字段中,然后直接返回一个以该 RawMarkdownvalueMarkdownNode。该函数不涉及任何算法或分支控制流,其唯一作用是为后续的渲染管线提供一个保留原始 Markdown 文本的节点封装,使调用方能够将尚未解析或无法解析的文本片段直接嵌入到最终生成的文档结构中。

Side Effects

No observable side effects are evident from the extracted code.

Reads From

  • markdown parameter (string value)

Writes To

  • returned MarkdownNode object

Usage Patterns

  • Constructing a MarkdownNode from a raw markdown string
  • Wrapping preformatted markdown content for inclusion in a document

clore::generate::make_section

Declaration: generate/markdown.cppm:115

Definition: generate/markdown.cppm:173

Declaration: Namespace clore::generate

clore::generate::make_section 是一个工厂函数,其实现直接构造一个 SemanticSection 实例并返回。函数接收一个 SemanticKind 枚举值、三个字符串(subject_keyheading)、一个 uint8_t 类型的 level、以及两个布尔值 omit_if_emptycode_style_heading。内部使用指定的字段值以聚合初始化方式创建 SemanticSection,其中 children 初始化为空向量,然后通过 std::make_unique 将对象包装为 SemanticSectionPtr 返回。

该函数没有任何复杂控制流或外部依赖,仅依赖于 std::make_uniqueSemanticSection 的聚合初始化规则。所有参数通过值传递,字符串通过 std::move 转移所有权以优化复制。

Side Effects

  • Allocates a new SemanticSection object on the heap
  • Transfers ownership of the allocated object to the caller via a unique_ptr

Reads From

  • kind (SemanticKind)
  • subject_key (std::string)
  • heading (std::string)
  • level (std::uint8_t)
  • omit_if_empty (bool)
  • code_style_heading (bool)

Writes To

  • Heap-allocated SemanticSection object (constructed and initialized)

Usage Patterns

  • Creating a semantic section for markdown generation
  • Building a section node in the page structure

clore::generate::make_text

Declaration: generate/markdown.cppm:99

Definition: generate/markdown.cppm:132

Declaration: Namespace clore::generate

clore::generate::make_text 提供最简单的内联片段构造路径。它接收一个 std::string 参数 text,通过直接初始化 TextFragment 并将其 text 成员移动构造来返回一个 InlineFragment。该函数不包含分支或循环逻辑;整个实现等同于 return TextFragment{std::move(text)};。它依赖 TextFragment 结构体的定义(其 text 字段持有字符串数据),并作为生成器中多个高层片段函数的构造基元。

Side Effects

  • moves the input string, leaving it in a valid but unspecified state

Reads From

  • text parameter (the string content is consumed via move)

Writes To

  • return value (TextFragment constructed with moved string)

Usage Patterns

  • building markdown inline fragments
  • converting std::string to TextFragment

clore::generate::render_markdown

Declaration: generate/markdown.cppm:122

Definition: generate/markdown.cppm:730

Declaration: Namespace clore::generate

clore::generate::render_markdown 接受一个 const MarkdownDocument &,首先检查 document.frontmatter 是否包含值。若存在,则提取 fm.titlefm.descriptionfm.layoutfm.page_template,通过 yaml_quote 对标题与描述进行转义后,按 YAML front matter 格式拼接 --- 分隔的键值对,并追加到输出字符串开头。随后,迭代 document.children 中的每个 MarkdownNode,依次调用 render_node 将各节点渲染为字符串并累加至结果中。函数完全依赖内部组件:yaml_quote 用于转义 YAML 值,render_node 则基于节点类型(如段落、代码块、列表、语义节等)分发至相应的渲染逻辑,最终返回完整的 Markdown 文本。

Side Effects

No observable side effects are evident from the extracted code.

Reads From

  • document.frontmatter
  • document.children

Writes To

  • local rendered string

Usage Patterns

  • Called by rendering functions to produce a markdown string from a MarkdownDocument
  • Used as a building block for page generation

Internal Structure

模块 generate:markdown 将 Markdown 文档生成过程拆解为独立的数据模型与渲染逻辑两层。数据模型层由一组轻量结构体组成,包括原子片段(TextFragmentCodeFragmentLinkFragment)、块级节点(ParagraphCodeFenceBlockQuoteBulletListMermaidDiagramRawMarkdown)以及可嵌套的 SemanticSectionMarkdownNode(通过 std::variant 统一表示)。顶层 MarkdownDocument 集成了可选的 Frontmatter 与节点列表,构成完整的文档树。这些类型均定义在模块导出部分,供外部构建或组合。

内部实现层通过匿名命名空间组织,负责底层文本解析与片段处理,包括标识符边界检测、代码跨度识别、链接标签解析、运算符后缀读取、行首缩进与块引用前缀处理等。这些辅助函数被公共构造函数(如 make_textmake_code_fencemake_sectionrender_markdown)调用,形成“解析‑构建‑渲染”的清晰流水线。模块仅依赖 std,无外部库导入,体现了紧凑的垂直分解:最内层处理原始字符序列,中层组装结构化节点,外层遍历节点树并输出最终 Markdown。