prosemirror

package module
v0.0.0-...-b69a92d Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2024 License: MIT Imports: 3 Imported by: 0

README

prosemirror-go

GoDoc Build Status

This will export ProseMirror content state to HTML, Plain Text, or Markdown

Usage

func Export(rawContentState []byte) (string, error) {
  state := prosemirror.ContentState{}

  if err := json.Unmarshall(rawContentState, &state); err != nil {
    return "", err
  }

  config := prosemirror.NewHTMLConfig() // Export HTML
  // config := prosemirror.NewMarkdownConfig() // Export Markdown
  // config := prosemirror.NewPlainTextConfig() // Export Plain Text

  html := prosemirror.Render(&state, config)
  return html, nil
}

Documentation

Index

Constants

View Source
const ListTypeKey = "__LIST_TYPE__"

ListTypeKey is used to get the list type off of the attrs when rendering a list

Variables

This section is empty.

Functions

func Render

func Render(editorState *EditorState, config *Config) string

Render takes the editorState and config and returns the content as a string

Types

type Config

type Config struct {
	NodeRenderers map[string]Option
	MarkRenderers map[string]Option
}

Config is passed to the render function and configures how to render the various content types

func NewHTMLConfig

func NewHTMLConfig() *Config

NewHTMLConfig returns a Config configured for HTML

func NewMarkdownConfig

func NewMarkdownConfig() *Config

NewMarkdownConfig creates a Config configured to render markdown

func NewPlainTextConfig

func NewPlainTextConfig() *Config

NewPlaintextConfig creates a config configured to render plain text

type Content

type Content struct {
	Attrs   map[string]interface{} `json:"attrs,omitempty"`
	Content []*Content             `json:"content,omitempty"`
	Marks   []*Mark                `json:"marks,omitempty"`
	Text    string                 `json:"text,omitempty"`
	Type    string                 `json:"type"`
}

Content - http://prosemirror.net/docs/ref/#model.Node

type EditorState

type EditorState struct {
	Content   []*Content `json:"content"`
	Selection *Selection `json:"selection"`
	Type      string     `json:"type"`
}

EditorState - http://prosemirror.net/docs/ref/#state.Editor_State

type Mark

type Mark struct {
	Attrs map[string]interface{} `json:"attrs,omitempty"`
	Type  string                 `json:"type"`
}

Mark - http://prosemirror.net/docs/ref/#model.Mark

type Option

type Option interface {
	RenderBefore(int, map[string]interface{}) string
	RenderAfter(int, map[string]interface{}) string
}

Option configures what to render before and after a specific content type

type Selection

type Selection struct {
	Anchor int    `json:"anchor"`
	Head   int    `json:"head"`
	Type   string `json:"type"`
}

Selection - http://prosemirror.net/docs/ref/#state.Selection

type SimpleOption

type SimpleOption struct {
	Before string
	After  string
}

SimpleOption implements Option. Can be used when Before/After strings are constant.

func (SimpleOption) RenderAfter

func (o SimpleOption) RenderAfter(_ int, _ map[string]interface{}) string

RenderBefore returns the After string

func (SimpleOption) RenderBefore

func (o SimpleOption) RenderBefore(_ int, _ map[string]interface{}) string

RenderBefore returns the Before string

Jump to

Keyboard shortcuts

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