mdrender

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: GPL-3.0 Imports: 4 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 mdrender renders the dictionary-neutral Entry IR as Markdown.

It is a sibling of internal/bobadapter, not a layer on top of it:

EntrySet → bobadapter → Bob toDict
EntrySet → mdrender   → Markdown

Both read the same canonical IR and neither can see the other. That is the whole point of the arrangement. Markdown is not produced by converting entry HTML — a second semantic path would drift from the parser the moment either changed — and the parser needs no knowledge that Markdown exists.

The renderer has two callers: deterministic diagnostics, which keep per-process resource URLs out, and user presentation, which enables resolved loopback audio/image links without enabling parser provenance.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Escape

func Escape(text string) string

Escape exposes the renderer's escaping to tooling that needs to look for IR text inside rendered output. Re-implementing it in the checker would let the two drift, and the check would then be testing the copy.

func NavigationTarget(text string) string

NavigationTarget exposes how a lookup target is written, for the same reason Escape is exposed. A navigation target is inside a code span, where Markdown syntax is already inert and escaping it would put literal backslashes on the page — so it is not escaped, and tooling must look for this form instead.

func RenderEntry

func RenderEntry(entry *entryir.Entry, opts Options) string

RenderEntry renders one entry as a standalone document.

func RenderEntrySet

func RenderEntrySet(set *entryir.EntrySet, opts Options) string

RenderEntrySet renders a complete EntrySet, preserving record boundaries.

Distinct records are never merged: each keeps its own heading and its own ordinal, because two records under one key are two things the dictionary chose to say separately. No field of one record is ever interleaved with another's, in either mode.

Types

type MultiRecordMode

type MultiRecordMode string

MultiRecordMode selects how several records under one key are presented.

It mirrors the Bob adapter's option of the same name. The concept is shared — show one record, or show them all — but each surface expresses it with what it actually has. Bob has clickable related words; Markdown has a horizontal rule and no documented lookup action, so combined mode divides records with a thematic break and separate mode lists siblings as copyable query text.

const (
	// MultiRecordCombined renders every record in canonical order, divided by
	// a Markdown thematic break. It is the default because a caller that has
	// not chosen — diagnostics above all — must see everything the parser
	// produced rather than one arbitrary record.
	MultiRecordCombined MultiRecordMode = "combined"
	// MultiRecordSeparate renders exactly one record plus sibling selectors.
	MultiRecordSeparate MultiRecordMode = "separate"
)

type Options

type Options struct {
	IncludeExamples     bool
	IncludeExtras       bool
	MaxExamplesPerSense int
	// AudioLinks writes the playable loopback URL for a resolved recording.
	//
	// It is off by default because those URLs carry a per-process resource
	// token: including one would make the same EntrySet render differently on
	// every run and destroy snapshot comparison. With it off, an available
	// recording is still reported — just as a fact rather than as a link.
	AudioLinks bool
	// AudioURL, when set, chooses the link for a recording in place of its
	// resource URL; "" keeps the resource URL. The service uses it to play a
	// recording in the background instead of opening it in a browser.
	AudioURL func(*entryir.Audio) string
	// ImageLinks writes resolved inline MDD illustrations at their original
	// prose position. It is disabled for deterministic diagnostic snapshots.
	ImageLinks bool
	// RecordOrdinal selects one visible record when a record selector was used.
	// A non-zero value always wins over MultiRecordMode, because the user asked
	// for that record by name.
	RecordOrdinal int
	// MultiRecordMode selects combined or separate presentation. Empty means
	// combined.
	MultiRecordMode MultiRecordMode
	// IncludeProvenance annotates each structure with the parser rule that
	// produced it. Development only; it is what makes a snapshot answer "which
	// heuristic did this?".
	IncludeProvenance bool
	// IncludeGrammar preserves verbose linguistic rules (e.g. "[used in negatives]")
	// in presentation. When false, they are omitted to reduce noise.
	IncludeGrammar bool
}

Options configures rendering. The zero value renders senses only.

func DefaultOptions

func DefaultOptions() Options

DefaultOptions renders a complete entry for a human reader.

func UserOptions

func UserOptions() Options

UserOptions returns complete, user-facing Markdown. It intentionally does not enable IncludeProvenance: parser rules and confidence belong only in diagnostic artifacts.

Jump to

Keyboard shortcuts

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