Documentation
¶
Overview ¶
Package adf provides types and conversion utilities for Atlassian Document Format (ADF). ADF is the mandatory rich-text format for Jira Cloud v3 description and comment fields.
Index ¶
- func ExtractText(raw json.RawMessage) string
- func ToMarkdown(raw json.RawMessage) (string, error)
- func ToPlaintext(doc json.RawMessage) string
- type Mark
- type MarkType
- type Node
- func Blockquote(content ...*Node) *Node
- func BulletList(items ...*Node) *Node
- func CodeBlock(language string, content ...*Node) *Node
- func Convert(markdown string) (*Node, error)
- func Document(content ...*Node) *Node
- func HardBreak() *Node
- func Heading(level int, content ...*Node) *Node
- func ListItem(content ...*Node) *Node
- func OrderedList(items ...*Node) *Node
- func Paragraph(content ...*Node) *Node
- func Rule() *Node
- func Table(rows ...*Node) *Node
- func TableCell(content ...*Node) *Node
- func TableHeader(content ...*Node) *Node
- func TableRow(cells ...*Node) *Node
- func Text(text string, marks ...Mark) *Node
- type NodeType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractText ¶
func ExtractText(raw json.RawMessage) string
ExtractText walks an ADF document (as raw JSON) and returns a plain-text representation by concatenating all text nodes. Block-level nodes are separated by newlines. Returns an empty string for nil/empty input.
NOTE: Returns the raw string as fallback for invalid JSON. This is intentional — callers display the result in text mode, where raw JSON is a better degradation than an empty string or error. If callers need to detect parse failure, compare the result to string(raw).
func ToMarkdown ¶
func ToMarkdown(raw json.RawMessage) (string, error)
ToMarkdown converts an ADF document (as raw JSON) into a Markdown string. This is the inverse of Convert() (Markdown→ADF). Unlike ToPlaintext, it produces standard CommonMark Markdown with proper syntax for headings, lists, code blocks, inline marks, etc.
Returns empty string for nil/empty input. Returns an error for invalid JSON rather than silently falling back, since this feeds a file-writing pipeline where data integrity matters.
func ToPlaintext ¶
func ToPlaintext(doc json.RawMessage) string
ToPlaintext converts an ADF document (as raw JSON) into structured readable plaintext suitable for terminal display. Unlike ExtractText, it preserves formatting structure: bullets, numbered lists, code block indentation, blockquote prefixes, and nested list indentation.
Returns empty string for nil/empty input. Returns the raw string as fallback for invalid JSON (same rationale as ExtractText — raw text beats empty).
Types ¶
type Mark ¶
type Mark struct {
Type MarkType `json:"type"`
Attrs map[string]interface{} `json:"attrs,omitempty"`
}
Mark represents an inline formatting mark on a text node.
type Node ¶
type Node struct {
Type NodeType `json:"type"`
Version int `json:"version,omitempty"` // only on doc node (always 1)
Content []*Node `json:"content,omitempty"`
Text string `json:"text,omitempty"`
Marks []Mark `json:"marks,omitempty"`
Attrs map[string]interface{} `json:"attrs,omitempty"`
}
Node is the building block of an ADF document tree.
func Convert ¶
Convert parses a CommonMark Markdown string and returns an ADF Document. Plain text (no Markdown syntax) passes through as a single paragraph with a text node. Empty input returns an empty document.
func TableHeader ¶
TableHeader creates a table header cell node.
type NodeType ¶
type NodeType string
NodeType identifies the type of an ADF node.
const ( TypeDoc NodeType = "doc" TypeParagraph NodeType = "paragraph" TypeHeading NodeType = "heading" TypeBulletList NodeType = "bulletList" TypeOrderedList NodeType = "orderedList" TypeListItem NodeType = "listItem" TypeCodeBlock NodeType = "codeBlock" TypeBlockquote NodeType = "blockquote" TypeRule NodeType = "rule" TypeText NodeType = "text" TypeHardBreak NodeType = "hardBreak" TypeTable NodeType = "table" TypeTableRow NodeType = "tableRow" TypeTableHeader NodeType = "tableHeader" TypeTableCell NodeType = "tableCell" )