crossref

package
v0.7.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 6, 2026 License: MIT Imports: 6 Imported by: 0

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

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

func (r *Resolver) AddCaptions(html string) string

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

func (r *Resolver) GetAllReferences() map[string]*Reference

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

func (r *Resolver) ProcessHTML(html string) string

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

func (r *Resolver) RegisterFigure(id, title string) int

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

func (r *Resolver) RegisterSection(id, title string, level int)

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

func (r *Resolver) RegisterTable(id, title string) int

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.

func (*Resolver) Reset

func (r *Resolver) Reset()

Reset clears all references and reinitializes the resolver. Used when processing multiple independent documents.

func (*Resolver) Resolve

func (r *Resolver) Resolve(id string) (*Reference, error)

Resolve looks up reference information by ID. Returns the found Reference pointer, or an error if not found.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL