convert

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2026 License: MIT Imports: 52 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package convert turns documents into Markdown for language models.

Convert picks a converter from the input's MIME type, falling back to its file extension and then to its content, and returns Markdown that keeps the structure a model can use: headings, lists, tables, links and slide notes. Styling that carries no meaning (fonts, colors, positions) is dropped.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrPasswordRequired = errors.New("encrypted, and needs a password to open")
	ErrWrongPassword    = errors.New("wrong password")
)

ErrPasswordRequired is returned, wrapped, for an encrypted document that does not open without a password; ErrWrongPassword when the password given does not open it either.

View Source
var ErrNoText = errors.New("no text found")

ErrNoText is returned, wrapped, when a document converts but holds no text, such as a PDF of scanned pages.

View Source
var ErrUnsupported = errors.New("unsupported format")

ErrUnsupported is returned, wrapped, for a format no converter handles.

Functions

func Detect

func Detect(in Input) string

Detect returns the MIME type in is converted as: the caller's MIME type when it is specific, else the one its extension names, else one sniffed from its content.

func Supported

func Supported() []string

Supported lists the MIME types Convert handles, besides text/*.

Types

type Input

type Input struct {
	// Name is the document's file name, path or URL. Only its extension is
	// used, to help detect the format; it may be empty.
	Name string
	// MIME is the document's media type when the caller knows it, such as an
	// HTTP Content-Type. Parameters are ignored. It may be empty.
	MIME string
	// Password opens an encrypted document (a PDF); most open without one.
	Password string
	// Reader reads the document, which is Size bytes long.
	Reader io.ReaderAt
	Size   int64
}

Input is a document to convert.

type Result

type Result struct {
	Markdown string
	// Title is the document's own title when it records one, else empty.
	Title string
	// MIME is the format the document was converted as.
	MIME string
}

Result is a converted document.

func Convert

func Convert(ctx context.Context, in Input) (res Result, err error)

Convert converts in to Markdown.

Jump to

Keyboard shortcuts

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