Documentation
¶
Index ¶
- func ApplyCompatibility(doc Document, schema FieldCompatibility, mode adfmode.Mode) (Document, []Warning, error)
- func FromMarkdownLossy(markdown string) (Document, []Warning, error)
- func Hyperlink(url, text string) string
- func Marshal(doc Document) ([]byte, error)
- func Normalize(d Document) (Document, []Warning)
- func Parse(data []byte) (Document, []Warning, error)
- func RenderActivatable(doc Document, opts RenderOptions) string
- func ToMarkdown(doc Document) string
- func ToPlain(doc Document) string
- type Capabilities
- type CompatibilityError
- type Document
- func (d Document) Validate() errordeprecated
- type Entry
- type FieldCompatibility
- type InvalidDocumentError
- type Kind
- type LossyConversionError
- type LossyResult
- type Mark
- type Node
- type RegistryView
- type RenderOptions
- type Segment
- type Status
- type Warning
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyCompatibility ¶
func ApplyCompatibility(doc Document, schema FieldCompatibility, mode adfmode.Mode) (Document, []Warning, error)
ApplyCompatibility walks doc and reconciles Jira field compatibility. In best-effort mode, unsupported nodes are degraded and each degradation produces one Warning. In strict mode, the first incompatibility aborts with a CompatibilityError; no partial result.
func FromMarkdownLossy ¶
FromMarkdownLossy converts GFM Markdown to an ADF document and reports every Markdown construct it could not represent faithfully in the supported ADF node set. Each unsupported construct yields one Warning (lossy=true) naming the construct and its source position so callers — and strict-mode abort gates — can act on the content loss instead of letting it slip through silently.
func Hyperlink ¶ added in v0.6.0
Hyperlink wraps text in an OSC 8 escape pointing at url, for UI chrome (issue keys, breadcrumbs) — terminals that support it make the text clickable; others show it unchanged. Shares osc8's control-byte hygiene.
func Normalize ¶ added in v0.10.0
Normalize repairs structurally-invalid but losslessly-fixable constructs that Jira's ADF validator rejects outright — an opaque INVALID_INPUT on the whole document — even though they carry no renderable content. It returns the cleaned document and one non-lossy Warning per class of repair, and is meant to run just before ValidateDoc so the submitted document is both valid and minimal. Every repair is provably lossless: it changes nothing the user can see, only "rejected by Jira" into "accepted", so it runs in every mode.
Repairs:
- Empty text nodes. A text node's `text` must be a non-empty string; an empty (or absent) one is rejected by Jira yet renders as nothing. These are a common artifact of document generators that emit blank table cells. Removing them is lossless — the node carried no content — and a parent left with no inline children (e.g. an empty paragraph in a blank cell) is itself valid ADF.
func Parse ¶
Parse decodes ADF JSON into a typed Document and returns any best-effort warnings collected during the decode. Unknown nodes/marks are preserved opaquely and surface no warnings on parse — they only matter at render/submit time. A value of the wrong JSON shape (a string where the document object belongs) returns *InvalidDocumentError so the failure carries a stable identity instead of the raw json error text.
func RenderActivatable ¶
func RenderActivatable(doc Document, opts RenderOptions) string
RenderActivatable renders an ADF document as terminal text with issue keys and bare URLs marked as OSC 8 hyperlinks. When IsTerminal is false, the same call returns plain text without escapes.
func ToMarkdown ¶
Types ¶
type Capabilities ¶
type Capabilities struct {
Author bool `json:"author"`
Render bool `json:"render"`
Preserve bool `json:"preserve"`
Validate bool `json:"validate"`
Submit bool `json:"submit"`
}
Capabilities is the shared envelope's per-row capability struct. All booleans default to false; explicit support is opt-in.
type CompatibilityError ¶
type CompatibilityError struct {
Field string
NodeType string
MarkType string
Path string
Reason string
}
CompatibilityError is the typed error returned by ApplyCompatibility in strict mode when a node would have to be degraded or dropped to fit the target field schema.
func (*CompatibilityError) Error ¶
func (e *CompatibilityError) Error() string
type Document ¶
type Document struct {
Type string `json:"type"`
Version int `json:"version"`
Content []Node `json:"content,omitempty"`
}
Document is the canonical ADF root.
type Entry ¶
type Entry struct {
Kind Kind `json:"kind"`
Name string `json:"name"`
Status Status `json:"status"`
Capabilities Capabilities `json:"capabilities"`
InputShape json.RawMessage `json:"input_shape,omitempty"`
OutputShape json.RawMessage `json:"output_shape,omitempty"`
Warnings []string `json:"warnings,omitempty"`
OfficialURL string `json:"official_url"`
Notes string `json:"notes,omitempty"`
SubmitDescription string `json:"submit_description"`
}
Entry is one row in the registry — the shared envelope shape. input_shape and output_shape are JSON Schema 2020-12 fragments.
type FieldCompatibility ¶
FieldCompatibility describes what a single Jira target field will accept. The zero value (no flags set) means "unknown" and unknown is treated as unsupported.
type InvalidDocumentError ¶ added in v0.10.0
type InvalidDocumentError struct {
// Got names the JSON shape that was supplied ("string", "number", ...).
Got string
// Field optionally names the payload key that carried the bad value;
// callers that know the key tag it after Parse returns.
Field string
}
InvalidDocumentError reports a value that is not an ADF document object — most commonly a plain string where {"type":"doc",...} is required. It is TYPED so the error mapper can emit a stable adf_invalid code with a clean message instead of leaking the raw json unmarshal error to the envelope.
func (*InvalidDocumentError) Code ¶ added in v0.10.0
func (e *InvalidDocumentError) Code() errtax.Code
Code classifies the failure under the taxonomy's adf_invalid code.
func (*InvalidDocumentError) Error ¶ added in v0.10.0
func (e *InvalidDocumentError) Error() string
type Kind ¶
type Kind int
Kind tags whether a registry row describes a node or a mark.
func (Kind) MarshalJSON ¶
type LossyConversionError ¶ added in v0.10.0
type LossyConversionError struct {
Warning Warning
}
LossyConversionError is the strict-mode abort for a lossy Markdown→ADF conversion: it carries the source-mapped warning so the error mapper can surface the offending Markdown line and a remediation hint instead of a bare message with none.
func (LossyConversionError) Code ¶ added in v0.10.0
func (e LossyConversionError) Code() errtax.Code
Code classifies the strict-mode abort under markdown_lossy_conversion.
func (LossyConversionError) Error ¶ added in v0.10.0
func (e LossyConversionError) Error() string
type LossyResult ¶
LossyResult is the typed return for ToMarkdownLossy. Markdown is the best-effort GFM rendering; LossyConstructs is the sorted unique list of node/mark type names the renderer didn't fully round-trip.
func ToMarkdownLossy ¶
func ToMarkdownLossy(doc Document) LossyResult
ToMarkdownLossy renders doc to GFM Markdown and reports every node or mark type the renderer dropped or simplified. The returned LossyConstructs slice is sorted unique. A nil-or-empty doc yields an empty list.
type Mark ¶
type Mark struct {
Type string `json:"type"`
Attrs map[string]any `json:"attrs,omitempty"`
// contains filtered or unexported fields
}
Mark is an inline annotation. Same opaque-preservation rules as Node.
func (Mark) MarshalJSON ¶
func (*Mark) UnmarshalJSON ¶
type Node ¶
type Node struct {
Type string `json:"type"`
Text string `json:"text,omitempty"`
Attrs map[string]any `json:"attrs,omitempty"`
Marks []Mark `json:"marks,omitempty"`
Content []Node `json:"content,omitempty"`
// contains filtered or unexported fields
}
Node is one ADF block or inline element. Unknown JSON keys outside the well-known fields are preserved opaquely in extra so re-marshaling never loses semantics (lossless preservation).
func (Node) MarshalJSON ¶
func (*Node) UnmarshalJSON ¶
type RegistryView ¶
type RegistryView struct {
// contains filtered or unexported fields
}
RegistryView is the read-only handle commands and tests use.
func Registry ¶
func Registry() RegistryView
Registry returns the read-only registry view: the curated rows with computed capabilities, plus a synthesized preserve-only row for every validated node/mark that has no curated entry. The matrix therefore covers the validator's full universe by construction — it cannot under-report what the CLI accepts.
func (RegistryView) All ¶
func (r RegistryView) All() []Entry
type RenderOptions ¶
type RenderOptions struct {
// IsTerminal toggles OSC 8 hyperlink emission. When false, the
// renderer emits plain text.
IsTerminal bool
// BaseURL is the active profile's Jira base URL, used to expand
// issue keys (JCT-7) into browseable links.
BaseURL string
}
RenderOptions configure RenderActivatable.
type Segment ¶
func ToFormatted ¶
type Status ¶
type Status string
Status tags the support tier a row currently sits in. New rows start at "preserve-only" and graduate to "mvp" or higher tiers as authoring lands.
type Warning ¶
type Warning struct {
Type string `json:"type"`
Message string `json:"message"`
Field string `json:"field,omitempty"`
Path string `json:"path,omitempty"`
NodeType string `json:"node_type,omitempty"`
MarkType string `json:"mark_type,omitempty"`
Lossy bool `json:"lossy"`
}
Warning is a structured non-fatal diagnostic emitted by best-effort ADF processing. Strict mode promotes warnings to errors. The shape matches cli.Warning byte-for-byte but the type lives here to avoid an import cycle; commands convert via cli.WarningFrom.
func ValidateDoc ¶
ValidateDoc validates a parsed ADF Document according to the given mode.
Root shape (type="doc", version=1) is always enforced regardless of mode — a structurally invalid root cannot be sent to Jira in any mode.
Validation is registry-backed: the rules in schema_rules.go encode the pinned ADF JSON schema (@atlaskit/adf-schema 56.0.15). In ModeStrict (the mutation-submit default) every rule violation is a fatal error naming the offending field path. In ModeBestEffort every violation is a non-fatal Warning and the document is forwarded as-is.
Rules enforced:
- root shape and root-child node types
- unknown node / mark types
- required attrs, attr types, attr enums, numeric ranges
- content/nesting rules (inline-only nodes, child whitelists)
- marks-on-block-nodes are illegal (marks are inline-only)
- per-mark rules (link href, subsup type, color hex) and the code-mark mutual-exclusion group
Returns (warnings, nil) on success; (nil, err) on fatal validation failure.
func (Warning) WarningField ¶
func (Warning) WarningIsLossy ¶
func (Warning) WarningMarkType ¶
func (Warning) WarningMessage ¶
func (Warning) WarningNodeType ¶
func (Warning) WarningPath ¶
func (Warning) WarningType ¶
Implement cli.WarningSource so commands can do cli.WarningFrom(adfW) without either package importing the other's concrete type.