Documentation
¶
Overview ¶
Package adfmarkdown converts Atlassian Document Format (ADF) JSON to Markdown.
Build Requirements ¶
This package requires Go 1.25+ with jsonv2 enabled:
GOEXPERIMENT=jsonv2 go build ./... GOEXPERIMENT=jsonv2 go test ./...
Basic Usage ¶
md, err := adfmarkdown.UnmarshalADF(adfJSON)
Options ¶
Use functional options to control schema validation and rendering:
adfmarkdown.UnmarshalADF(adfJSON, adfmarkdown.WithStrictSchema(true), adfmarkdown.WithCodeFenceStyle(adfmarkdown.CodeFenceBackticks), )
Errors ¶
Decode failures return *Error with a stable ErrorKind and ADF path metadata.
Index ¶
- func UnmarshalADF(data []byte, opts ...Option) ([]byte, error)
- func UnmarshalADFTo(w io.Writer, data []byte, opts ...Option) error
- func ValidateADFSchema(data []byte) error
- type CodeFenceStyle
- type Error
- type ErrorKind
- type ExtensionBlockHandler
- type ExtensionInlineHandler
- type HardBreakStyle
- type Option
- func WithAllowUnsupportedNodes(v bool) Option
- func WithBuiltInSchemaValidation(v bool) Option
- func WithCodeFenceStyle(v CodeFenceStyle) Option
- func WithExtensionBlockHandler(fn ExtensionBlockHandler) Option
- func WithExtensionInlineHandler(fn ExtensionInlineHandler) Option
- func WithHardBreakStyle(v HardBreakStyle) Option
- func WithSchemaValidator(fn func([]byte) error) Option
- func WithStrictSchema(v bool) Option
- func WithUnsupportedBlockHandler(fn UnsupportedBlockHandler) Option
- func WithUnsupportedInlineHandler(fn UnsupportedInlineHandler) Option
- type UnsupportedBlockHandler
- type UnsupportedInlineHandler
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func UnmarshalADF ¶
Example ¶
package main
import (
"fmt"
"log"
adfmarkdown "github.com/ajbeck/adf-to-markdown"
)
func main() {
input := []byte(`{"version":1,"type":"doc","content":[{"type":"heading","attrs":{"level":2},"content":[{"type":"text","text":"Overview"}]},{"type":"paragraph","content":[{"type":"text","text":"Hello from ADF"}]}]}`)
md, err := adfmarkdown.UnmarshalADF(input)
if err != nil {
log.Fatal(err)
}
fmt.Println(string(md))
}
Output: ## Overview Hello from ADF
func ValidateADFSchema ¶ added in v1.1.1
Types ¶
type CodeFenceStyle ¶
type CodeFenceStyle string
const ( CodeFenceBackticks CodeFenceStyle = "```" CodeFenceTildes CodeFenceStyle = "~~~" )
type ErrorKind ¶
type ErrorKind string
const ( ErrKindInvalidRoot ErrorKind = "invalid_root" ErrKindInvalidJSON ErrorKind = "invalid_json" ErrKindMissingType ErrorKind = "missing_type" ErrKindUnsupportedNode ErrorKind = "unsupported_node" ErrKindUnsupportedInline ErrorKind = "unsupported_inline" ErrKindUnsupportedMark ErrorKind = "unsupported_mark" ErrKindInvalidAttr ErrorKind = "invalid_attr" ErrKindInvalidMark ErrorKind = "invalid_mark" ErrKindInvalidMarkCombo ErrorKind = "invalid_mark_combo" ErrKindInvalidStructure ErrorKind = "invalid_structure" ErrKindInvalidText ErrorKind = "invalid_text" )
type ExtensionBlockHandler ¶
type ExtensionInlineHandler ¶
type HardBreakStyle ¶
type HardBreakStyle string
const ( HardBreakTwoSpaces HardBreakStyle = "two-spaces" HardBreakBackslash HardBreakStyle = "backslash" )
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
func WithCodeFenceStyle ¶
func WithCodeFenceStyle(v CodeFenceStyle) Option
func WithExtensionBlockHandler ¶
func WithExtensionBlockHandler(fn ExtensionBlockHandler) Option
func WithExtensionInlineHandler ¶
func WithExtensionInlineHandler(fn ExtensionInlineHandler) Option
func WithHardBreakStyle ¶
func WithHardBreakStyle(v HardBreakStyle) Option
func WithSchemaValidator ¶
func WithStrictSchema ¶
func WithUnsupportedBlockHandler ¶
func WithUnsupportedBlockHandler(fn UnsupportedBlockHandler) Option
func WithUnsupportedInlineHandler ¶
func WithUnsupportedInlineHandler(fn UnsupportedInlineHandler) Option
type UnsupportedBlockHandler ¶
Click to show internal directories.
Click to hide internal directories.