editorjs

package module
v0.0.0-...-472e59a Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2023 License: MIT Imports: 7 Imported by: 0

README

Editor.js (Go)

Server-side implementation sample for the Editor.js. It contains data validation and converts output from Editor.js to HTML.

Installation

go get github.com/si3nloong/go-editorjs

Basic usage

import (
    editorjs "github.com/si3nloong/go-editorjs"
)

func main() {
    b := []byte(`
    {
        "time": 1589098011153,
        "blocks": [
            {
            "type": "header",
            "data": {
                "text": "Editor.js",
                "level": 2
            }
            }
        ],
        "version": "2.17.0"
    }
    `)

    ejs := editorjs.NewEditorJS()
    buf := new(bytes.Buffer)
    if err := ejs.ParseTo(b, buf); err != nil {
        panic(err)
    }

    log.Println("HTML result =>", buf.String())
}

Example of Editor.js output

{
  "time": 1589098011153,
  "blocks": [
    {
      "type": "header",
      "data": {
        "text": "Editor.js",
        "level": 2
      }
    }
  ],
  "version": "2.17.0"
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Block

type Block struct {
	Type string          `json:"type"`
	Data json.RawMessage `json:"data"`
}

type Data

type Data struct {
	Blocks  []Block `json:"blocks"`
	Version string  `json:"version"`
}

Data

type DefaultParser

type DefaultParser struct{}

DefaultParser :

func (DefaultParser) ParseHeader

func (d DefaultParser) ParseHeader(b []byte, w Writer) error

ParseHeader :

func (DefaultParser) ParseImage

func (d DefaultParser) ParseImage(b []byte, w Writer) error

ParseImage :

func (DefaultParser) ParseList

func (d DefaultParser) ParseList(b []byte, w Writer) error

ParseList :

func (DefaultParser) ParseParagraph

func (d DefaultParser) ParseParagraph(b []byte, w Writer) error

ParseParagraph :

func (DefaultParser) ParseTable

func (d DefaultParser) ParseTable(b []byte, w Writer) error

ParseTable :

type EditorJS

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

EditorJS :

func NewEditorJS

func NewEditorJS() *EditorJS

NewEditorJS : create new Editorjs object

func (*EditorJS) ParseTo

func (ejs *EditorJS) ParseTo(b []byte, w Writer) error

ParseTo : convert editorjs data to HTML

func (*EditorJS) RegisterParser

func (ejs *EditorJS) RegisterParser(name string, p ParseFunc)

RegisterParser :

type Flusher

type Flusher interface {
	Flush() error
}

Flusher :

type Image

type Image struct {
	File struct {
		Url string `json:"url"`
	} `json:"file"`
	Caption   string `json:"caption"`
	Stretched bool   `json:"stretched"`
}

type List

type List struct {
	Style string   `json:"style"`
	Items []string `json:"items"`
}

type ParseFunc

type ParseFunc func(b []byte, w Writer) error

ParseFunc :

type Table

type Table struct {
	WithHeadings bool       `json:"withHeadings"`
	Content      [][]string `json:"content"`
}

type Writer

type Writer interface {
	io.StringWriter
	io.Writer
}

Writer :

Jump to

Keyboard shortcuts

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