html_to_editorjs

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2022 License: BSD-3-Clause Imports: 5 Imported by: 0

README

Simple converter from html to json for editor.js

Installation

go get github.com/LegGnom/html-to-editorjs

Usage

package main

import (
	"encoding/json"
    "fmt"
    "github.com/LegGnom/html-to-editorjs"
)

func main() {
	htmlString := `
        <h2>Editor.js</h2>
        <p>Hey. Meet the new Editor. On this page you can see it in action — try to edit this text.</p>
        <h3>Key features</h3>
        <ul>
            <li>It is a block-styled editor</li>
            <li>It returns clean data output in JSON</li>
            <li>Designed to be extendable and pluggable with a simple API</li>
        </ul>
	`

	j, _ := json.MarshalIndent(html_to_editorjs.Parse(html), "", "   ")
	fmt.Println(string(j))
}

It will generate the following output:

{
   "time": 1641162829,
   "blocks": [
      {
         "type": "header",
         "data": {
            "level": 2,
            "text": "Editor.js"
         }
      },
      {
         "type": "paragraph",
         "data": {
            "text": "Hey. Meet the new Editor. On this page you can see it in action — try to edit this text."
         }
      },
      {
         "type": "header",
         "data": {
            "level": 3,
            "text": "Key features"
         }
      },
      {
         "type": "list",
         "data": {
            "items": [
               "It is a block-styled editor",
               "It returns clean data output in JSON",
               "Designed to be extendable and pluggable with a simple API"
            ],
            "style": "unordered"
         }
      }
   ],
   "version": ""
}

License

The BSD 3-Clause license, the same as the Go language.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearAllBlocks

func ClearAllBlocks()

ClearAllBlocks removes all block handlers

func Parse

func Parse(payload string) scheme.Response

Parse - converts html to scheme.Response.

func RegistryAll

func RegistryAll()

RegistryAll adds all system block handlers to the parser

func RegistryBlock

func RegistryBlock(name string, handler scheme.BlockHandler)

RegistryBlock adds new handlers for blocks

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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