docformat

package
v2.8.42 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: MIT Imports: 6 Imported by: 0 modules, 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 docformat turns a fetched non-HTML document into Markdown by choosing the right formatter for it: vCard, iCalendar, RSS/Atom, JSON (record arrays, Jupyter notebooks, OpenAPI specs, generic documents), CSV/TSV, Git patches and source files.

The formatters live in internal/extract; this package owns the choice between them, so every caller picks the same formatter for the same body. The order and the checks follow the Cloudflare hub's scrape path (hub/src/scrape.ts), which the hub parity test (cmd/edgefetch/hub_parity_test.go) holds the node to until the hub stops processing pages (docs/HUB-NODE-PROCESSING-PLAN.md).

Index

Constants

View Source
const (
	KindVCard       = "vcard"
	KindICalendar   = "icalendar"
	KindFeed        = "feed"
	KindJSONRecords = "json-records"
	KindJSON        = "json"
	KindCSV         = "csv"
	KindPatch       = "patch"
	KindSource      = "source"
)

Kinds of document Render recognizes.

Variables

This section is empty.

Functions

func LooksLikeHTML

func LooksLikeHTML(body, contentType string) bool

LooksLikeHTML reports whether a body goes to the HTML extractor rather than to Render.

Types

type Doc

type Doc struct {
	Kind        string
	Title       string
	Description string
	Markdown    string
	// Links are the item links of a feed.
	Links []string
	// Records is set for KindJSONRecords.
	Records *jobs.ChunkedJSONRecordsResult
}

Doc is a formatted document.

func Render

func Render(in Input) *Doc

Render picks a formatter for in.Body and returns the formatted document, or nil when none applies (the caller then treats the body as Markdown or plain text). The first match wins, in this order: vCard, iCalendar, feed, JSON records, JSON, CSV/TSV, Git patch, source code.

type Input

type Input struct {
	Body        string
	ContentType string
	URL         string
	// ChunkRecords splits a JSON array of records into one chunk per record (filtered by JSONFilter), as the scrape
	// and extract paths do. Without it, record arrays get the generic JSON formatter.
	ChunkRecords bool
	JSONFilter   string
}

Input is one fetched document. Body must not be HTML; callers send HTML to the HTML extractor instead.

Jump to

Keyboard shortcuts

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