adf

package
v0.12.0 Latest Latest
Warning

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

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

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

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.

func Code

func Code() Mark

Code creates an inline code mark.

func Em

func Em() Mark

Em creates an emphasis (italic) mark.

func Link(href string) Mark

Link creates a link mark with the given href.

func Strike

func Strike() Mark

Strike creates a strikethrough mark.

func Strong

func Strong() Mark

Strong creates a strong (bold) mark.

type MarkType

type MarkType string

MarkType identifies the type of an inline mark.

const (
	MarkStrong MarkType = "strong"
	MarkEm     MarkType = "em"
	MarkCode   MarkType = "code"
	MarkLink   MarkType = "link"
	MarkStrike MarkType = "strike"
)

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 Blockquote

func Blockquote(content ...*Node) *Node

Blockquote creates a blockquote node.

func BulletList

func BulletList(items ...*Node) *Node

BulletList creates a bullet list node.

func CodeBlock

func CodeBlock(language string, content ...*Node) *Node

CodeBlock creates a code block node with an optional language attribute.

func Convert

func Convert(markdown string) (*Node, error)

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 Document

func Document(content ...*Node) *Node

Document creates a new ADF document root node.

func HardBreak

func HardBreak() *Node

HardBreak creates a hard break (line break) node.

func Heading

func Heading(level int, content ...*Node) *Node

Heading creates a heading node with the given level (1-6).

func ListItem

func ListItem(content ...*Node) *Node

ListItem creates a list item node.

func OrderedList

func OrderedList(items ...*Node) *Node

OrderedList creates an ordered list node.

func Paragraph

func Paragraph(content ...*Node) *Node

Paragraph creates a paragraph node.

func Rule

func Rule() *Node

Rule creates a horizontal rule node.

func Table

func Table(rows ...*Node) *Node

Table creates a table node.

func TableCell

func TableCell(content ...*Node) *Node

TableCell creates a table cell node.

func TableHeader

func TableHeader(content ...*Node) *Node

TableHeader creates a table header cell node.

func TableRow

func TableRow(cells ...*Node) *Node

TableRow creates a table row node.

func Text

func Text(text string, marks ...Mark) *Node

Text creates a text node with optional marks.

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"
)

Jump to

Keyboard shortcuts

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