render

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package render turns the document model into text for the model to read: markdown (default), plain text, and an outline. Every renderer works on a block range of one segment so reads can be scoped and budgeted.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CommentThreads added in v0.4.0

func CommentThreads(threads []Thread) string

CommentThreads lists whole threads, each with its replies under it. The caller writes the count line above.

func NamedStyle added in v0.5.0

func NamedStyle(d *doc.NamedStyleDef) string

NamedStyle describes what a named style means, for the reads that report the definitions layout_document can rewrite. Unlike styleAnnotation it names bold and italic too: here there is no markdown around it to show them.

func Outline

func Outline(d *doc.Document, tabs []OutlineTab) string

Outline renders the outline as markdown.

Types

type DiffResult added in v0.2.0

type DiffResult struct {
	Text      string
	Stats     DiffStats
	Truncated bool
}

DiffResult is a rendered unified diff.

func UnifiedDiff added in v0.2.0

func UnifiedDiff(oldText, newText string, context, maxChars int) DiffResult

UnifiedDiff renders the line-level differences between two texts in unified-diff form with the given lines of context, cut at a hunk boundary when the output would exceed maxChars (0 = no limit).

type DiffStats added in v0.2.0

type DiffStats struct {
	Added   int `json:"added_lines"`
	Removed int `json:"removed_lines"`
	Hunks   int `json:"hunks"`
}

DiffStats count the changed lines of a diff.

type Mark added in v0.2.0

type Mark struct {
	TabID     string
	SegmentID string
	Start     int64
	End       int64
	Thread    Thread
	Replies   int
}

Mark is a comment thread where a read found it. A located thread names the segment and range it sits on; an unlocated one (no handle) is only counted. Replies is a count, not the posts: the footer says how many there are, and list_comments is where they are read.

type Options

type Options struct {
	// WithHandles prefixes every block with its handle.
	WithHandles bool
	// WithStyles annotates runs whose formatting markdown cannot express.
	WithStyles bool
	// Suggestions shows pending suggestions as CriticMarkup. When false
	// the committed view is rendered (suggested insertions hidden).
	Suggestions bool
	// MaxChars stops after the block that would cross the budget. 0 = no limit.
	MaxChars int
	// Marks are comment threads to show as {>>c:<id><<} after the text
	// they cover, and to list below the content when CommentFooter is set.
	Marks []Mark
	// CommentFooter appends the list of the threads marked in the
	// rendered range and counts the ones outside it.
	CommentFooter bool
}

Options tune a render.

type OutlineHeading

type OutlineHeading struct {
	Handle    string `json:"handle"`
	HeadingID string `json:"heading_id,omitempty"`
	Level     int    `json:"level"`
	Text      string `json:"text"`
	Blocks    int    `json:"blocks"`
	Words     int    `json:"words"`
}

OutlineHeading is one heading in the outline.

type OutlineTab

type OutlineTab struct {
	Number     int              `json:"number"`
	ID         string           `json:"id,omitempty"`
	Title      string           `json:"title"`
	Nesting    int              `json:"nesting,omitempty"`
	Paragraphs int              `json:"paragraphs"`
	Tables     int              `json:"tables"`
	Words      int              `json:"words"`
	Headers    int              `json:"headers"`
	Footers    int              `json:"footers"`
	Footnotes  int              `json:"footnotes"`
	Preamble   int              `json:"preamble_blocks"`
	Headings   []OutlineHeading `json:"headings"`
}

OutlineTab is one tab's outline.

func OutlineData

func OutlineData(d *doc.Document, only *doc.Tab) []OutlineTab

OutlineData computes the outline for the tabs given (all when nil).

type Reply added in v0.4.0

type Reply struct {
	Author  string
	Content string
	Created string
	Action  string // resolve or reopen
	Deleted bool
}

Reply is one post in a thread after the first.

type Result

type Result struct {
	Text         string
	Blocks       int
	To           int
	Chars        int
	Truncated    bool
	ContinueFrom string
}

Result is a rendered block range. To is the index one past the last block the render consumed (the continuation point when truncated).

func Markdown

func Markdown(seg *doc.Segment, from, to int, o Options) Result

Markdown renders blocks [from, to) of a segment as markdown.

func Plain

func Plain(seg *doc.Segment, from, to int, o Options) Result

Plain renders blocks [from, to) as plain text: no markdown markers, headings and list items still recognisable, tables tab-separated.

func Raw added in v0.3.0

func Raw(seg *doc.Segment, from, to, maxChars int) (Result, error)

Raw renders blocks [from, to) as the API's structural elements: one JSON array, cut at element boundaries when over budget.

type Thread added in v0.4.0

type Thread struct {
	ID       string
	Handle   string
	Author   string
	Created  string
	Quote    string
	Content  string
	Resolved bool
	Deleted  bool
	Replies  []Reply
}

Thread is a comment thread. It is shown twice: as one line in the footer of a read that marked it inline, and in full with its replies for list_comments. A view sets only the fields it wants shown — the footer leaves Created and Quote empty, because the read already shows the marked text where it sits.

Jump to

Keyboard shortcuts

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