Documentation
¶
Overview ¶
Package crossref provides cross-reference and auto-numbering functionality. It supports numbering and referencing figures, tables, and sections, replacing placeholders in HTML with actual numbers.
Index ¶
- type Reference
- type Resolver
- func (r *Resolver) AddCaptions(html string) string
- func (r *Resolver) GetAllReferences() map[string]*Reference
- func (r *Resolver) ProcessHTML(html string) string
- func (r *Resolver) RegisterFigure(id, title string) int
- func (r *Resolver) RegisterSection(id, title string, level int)
- func (r *Resolver) RegisterTable(id, title string) int
- func (r *Resolver) Reset()
- func (r *Resolver) Resolve(id string) (*Reference, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Reference ¶
type Reference struct {
Type referenceType // Reference type (figure, table, or section)
ID string // Unique identifier
Number int // Auto-assigned number
Title string // Title or description
Level int // Heading level for sections; 0 for other types
NumberStr string // Hierarchical number string, e.g. "1.2.3" (sections only)
}
Reference represents a tracked reference object.
type Resolver ¶
type Resolver struct {
// contains filtered or unexported fields
}
Resolver manages all cross-references and auto-numbering.
func NewResolver ¶
func NewResolver() *Resolver
NewResolver creates a new cross-reference resolver instance.
func (*Resolver) AddCaptions ¶
AddCaptions adds numbered captions to figures and tables. Processes HTML like <figure id="fig_1"><img ...></figure> and adds <figcaption>图1: Title</figcaption>.
Example: Input: <figure id="fig_demo"><img src="demo.png"></figure> Output: <figure id="fig_demo"><img src="demo.png"><figcaption>图1: Demo</figcaption></figure>
func (*Resolver) GetAllReferences ¶
GetAllReferences returns all registered references (for debugging or building reference lists). Priority matches Resolve: figures > tables > sections. If the same ID exists in multiple categories, only the highest-priority entry is returned.
func (*Resolver) ProcessHTML ¶
ProcessHTML processes HTML content, replacing {{ref:id}} placeholders with actual references. Supported placeholder formats: - {{ref:fig_1}} replaced with "图1" (Chinese figure label) - {{ref:table_1}} replaced with "表1" (Chinese table label) - {{ref:section_intro}} replaced with "§1.2.3" (section number)
Example: Input: "As shown in {{ref:fig_demo}}, ..." Output: "As shown in 图1, ..."
func (*Resolver) RegisterFigure ¶
RegisterFigure registers a figure and returns its auto-assigned number. The id parameter is the figure's unique identifier (typically used for HTML anchors). The title parameter is the figure's caption or description.
func (*Resolver) RegisterSection ¶
RegisterSection registers a section. The id parameter is the section's unique identifier. The title parameter is the section heading text. The level parameter is the heading level (1-6), used for hierarchical numbering.
Hierarchical numbering example: Level 1: 1. 2. 3. ... Level 2: 1.1. 1.2. 2.1. ... Level 3: 1.1.1. 1.1.2. ...
func (*Resolver) RegisterTable ¶
RegisterTable registers a table and returns its auto-assigned number. The id parameter is the table's unique identifier. The title parameter is the table's caption or description.