sourceloc

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: Apache-2.0, MIT Imports: 17 Imported by: 0

Documentation

Overview

Package sourceloc maps parsed Markdown back to positions in the original file: it re-aims parser-reported source blocks after the ingestion pipeline rewrites the text, aligns parser output to the structure of office files, and derives the per-chunk locators that citations open.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Align

func Align(markdown string, units []Unit) []types.SourceBlock

Align maps complete source units, never extending a hit through unmatched content. Unknown gaps must stay unknown: assigning them to the preceding block can point a citation at an entirely different page.

func AlignStructure

func AlignStructure(fileType string, data []byte, markdown string) ([]types.SourceBlock, error)

AlignStructure reads the structure of an office file and aligns the parser's markdown against it. It returns nil when the file type is not supported or nothing could be placed.

func AppendLocator

AppendLocator appends loc to list, folding it into the last entry when both point at the same place.

func CleanQuote

func CleanQuote(text string) string

CleanQuote strips Markdown image and link destinations and HTML tags from text, collapses whitespace, and caps it at types.SourceLocatorQuoteMax runes.

func MergeLocators

func MergeLocators(a, b types.SourceLocators) types.SourceLocators

MergeLocators unions two locator lists, dropping exact duplicates, for search results that the chat pipeline merges.

func RemapBlocks

func RemapBlocks(blocks []types.SourceBlock, oldText, newText string) []types.SourceBlock

RemapBlocks re-aims blocks recorded against oldText at newText. Blocks that collapse to nothing are dropped.

func SortBlocks

func SortBlocks(blocks []types.SourceBlock)

SortBlocks orders blocks by start offset.

func SupportsStructure

func SupportsStructure(fileType string) bool

SupportsStructure reports whether StructureUnits can read fileType.

func TextBlocks

func TextBlocks(content string) []types.SourceBlock

TextBlocks splits a plain-text original (Markdown, TXT) that the parser passed through unchanged into paragraph blocks whose text locators point at the same rune ranges of the original file.

Types

type Index

type Index struct {
	// contains filtered or unexported fields
}

Index answers "which source positions does this range of the final Markdown cover" for the chunker's output.

func NewIndex

func NewIndex(markdown string, blocks []types.SourceBlock) *Index

NewIndex builds an index over blocks recorded against markdown.

func (*Index) Locators

func (x *Index) Locators(start, end int) types.SourceLocators

Locators returns the locators of the blocks overlapping the rune range [start, end), each quoting the overlapping text. Adjacent locators that point at the same place (one page without a region, one slide, a run of rows) are folded together.

func (*Index) LocatorsAt

func (x *Index) LocatorsAt(pos int) types.SourceLocators

LocatorsAt returns the locators of the blocks containing rune offset pos, without quotes. Used to place an image reference found in the markdown.

type Remapper

type Remapper struct {
	// contains filtered or unexported fields
}

Remapper translates rune offsets in one version of a text to the matching offsets in a rewritten version.

Ingestion rewrites parser output before chunking (line endings, HTML tables, image references). Every rewrite is local, so the two texts share most of their lines: the remapper pairs identical lines, maps offsets inside a paired line directly, and spreads offsets proportionally across the unpaired stretches between pairs. That keeps it correct for any future rewrite step without each step having to report its edits.

func NewRemapper

func NewRemapper(oldText, newText string) *Remapper

NewRemapper prepares a best-effort offset mapping. Deprecated: source positions must use RemapBlocks, which verifies full text.

func (*Remapper) Map

func (r *Remapper) Map(pos int) int

Map returns the offset in the new text corresponding to pos in the old one.

type Unit

type Unit struct {
	Text    string
	Locator types.SourceLocator
}

Unit is one structural piece of an original file (a paragraph, a slide shape, a sheet row) with the locator it should resolve to.

func StructureUnits

func StructureUnits(fileType string, data []byte) ([]Unit, error)

StructureUnits lists the structural pieces of an office file in document order, each with the locator it resolves to.

Jump to

Keyboard shortcuts

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