adf

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2022 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package adf translates Atlassian Document Format (ADF) to other formats like markdown.

See: https://developer.atlassian.com/cloud/jira/platform/apis/document/structure/

Index

Constants

View Source
const (
	NodeTypeParent  = NodeType("parent")
	NodeTypeChild   = NodeType("child")
	NodeTypeUnknown = NodeType("unknown")

	NodeBlockquote  = NodeType("blockquote")
	NodeBulletList  = NodeType("bulletList")
	NodeCodeBlock   = NodeType("codeBlock")
	NodeHeading     = NodeType("heading")
	NodeOrderedList = NodeType("orderedList")
	NodePanel       = NodeType("panel")
	NodeParagraph   = NodeType("paragraph")
	NodeTable       = NodeType("table")
	NodeMedia       = NodeType("media")

	ChildNodeText        = NodeType("text")
	ChildNodeListItem    = NodeType("listItem")
	ChildNodeTableRow    = NodeType("tableRow")
	ChildNodeTableHeader = NodeType("tableHeader")
	ChildNodeTableCell   = NodeType("tableCell")

	InlineNodeCard      = NodeType("inlineCard")
	InlineNodeEmoji     = NodeType("emoji")
	InlineNodeMention   = NodeType("mention")
	InlineNodeHardBreak = NodeType("hardBreak")

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

Node types.

Variables

This section is empty.

Functions

func IsChildNode

func IsChildNode(identifier NodeType) bool

IsChildNode checks if the node is a child node.

func IsParentNode

func IsParentNode(identifier NodeType) bool

IsParentNode checks if the node is a parent node.

Types

type ADF

type ADF struct {
	Version int     `json:"version"`
	DocType string  `json:"type"`
	Content []*Node `json:"content"`
}

ADF is an Atlassian document format object.

func (*ADF) ReplaceAll

func (a *ADF) ReplaceAll(old, new string)

ReplaceAll replaces all occurrences of an old string in a text node with a new one.

type Connector

type Connector interface {
	GetType() NodeType
	GetAttributes() interface{}
}

Connector is a connector interface.

type JiraMarkdownTranslator

type JiraMarkdownTranslator struct {
	*MarkdownTranslator
}

JiraMarkdownTranslator is a jira markdown translator.

func NewJiraMarkdownTranslator

func NewJiraMarkdownTranslator() *JiraMarkdownTranslator

NewJiraMarkdownTranslator constructs jira markdown translator.

func (*JiraMarkdownTranslator) Close

Close implements TagCloser interface.

func (*JiraMarkdownTranslator) Open

func (tr *JiraMarkdownTranslator) Open(n Connector, d int) string

Open implements TagOpener interface.

type MarkNode

type MarkNode struct {
	MarkType   NodeType    `json:"type,omitempty"`
	Attributes interface{} `json:"attrs,omitempty"`
}

MarkNode is a mark node type.

func (MarkNode) GetAttributes

func (n MarkNode) GetAttributes() interface{}

GetAttributes gets node attributes.

func (MarkNode) GetType

func (n MarkNode) GetType() NodeType

GetType gets node type.

type MarkdownTranslator

type MarkdownTranslator struct {
	// contains filtered or unexported fields
}

MarkdownTranslator is a markdown translator.

func NewMarkdownTranslator

func NewMarkdownTranslator(opts ...MarkdownTranslatorOption) *MarkdownTranslator

NewMarkdownTranslator constructs markdown translator.

func (*MarkdownTranslator) Close

func (tr *MarkdownTranslator) Close(n Connector) string

Close implements TagCloser interface.

func (*MarkdownTranslator) Open

func (tr *MarkdownTranslator) Open(n Connector, _ int) string

Open implements TagOpener interface.

type MarkdownTranslatorOption

type MarkdownTranslatorOption func(*MarkdownTranslator)

MarkdownTranslatorOption is a functional option for MarkdownTranslator.

func WithMarkdownCloseHooks

func WithMarkdownCloseHooks(hooks nodeTypeHook) MarkdownTranslatorOption

WithMarkdownCloseHooks sets close hooks of a markdown translator.

func WithMarkdownOpenHooks

func WithMarkdownOpenHooks(hooks nodeTypeHook) MarkdownTranslatorOption

WithMarkdownOpenHooks sets open hooks of a markdown translator.

type Node

type Node struct {
	NodeType   NodeType    `json:"type"`
	Content    []*Node     `json:"content,omitempty"`
	Attributes interface{} `json:"attrs,omitempty"`
	NodeValue
}

Node is an ADF content node.

func (Node) GetAttributes

func (n Node) GetAttributes() interface{}

GetAttributes gets node attributes.

func (Node) GetType

func (n Node) GetType() NodeType

GetType gets node type.

type NodeType

type NodeType string

NodeType is an Atlassian document node type.

func ChildNodes

func ChildNodes() []NodeType

ChildNodes returns supported ADF child nodes.

func GetADFNodeType

func GetADFNodeType(identifier NodeType) NodeType

GetADFNodeType returns the type of ADF node.

func ParentNodes

func ParentNodes() []NodeType

ParentNodes returns supported ADF parent nodes.

type NodeValue

type NodeValue struct {
	Text  string     `json:"text,omitempty"`
	Marks []MarkNode `json:"marks,omitempty"`
}

NodeValue is an actual ADF node content.

type TagCloser

type TagCloser interface {
	Close(Connector) string
}

TagCloser is a tag closer.

type TagOpener

type TagOpener interface {
	Open(c Connector, depth int) string
}

TagOpener is a tag opener.

type TagOpenerCloser

type TagOpenerCloser interface {
	TagOpener
	TagCloser
}

TagOpenerCloser wraps tag opener and closer.

type Translator

type Translator struct {
	// contains filtered or unexported fields
}

Translator transforms ADF to a new format.

func NewTranslator

func NewTranslator(adf *ADF, tr TagOpenerCloser) *Translator

NewTranslator constructs an ADF translator.

func (*Translator) Translate

func (a *Translator) Translate() string

Translate translates ADF to a new format.

Jump to

Keyboard shortcuts

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