code

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2025 License: MIT Imports: 2 Imported by: 0

README ¶

EDITORJS GO CODE

editorjs-go-code is a plugin for editorjs-go that renders Editor.js code blocks using <pre><code> with safe HTML escaping.

✨ Features

  • ✅ Escapes code content for safe rendering
  • ✅ Semantic HTML output: <pre><code>...</code></pre>
  • 🧩 Easy integration with editorjs-go

📦 Installation

go get github.com/christiandenisi/editorjs-go
go get github.com/christiandenisi/editorjs-go-code

🚀 Usage

package main

import (
    "fmt"
    "github.com/christiandenisi/editorjs-go"
    "github.com/christiandenisi/editorjs-go-code"
)

func main() {
    jsonData := []byte(`{
        "blocks": [{
            "type": "code",
            "data": {
                "code": "<script>alert('x')</script>"
            }
        }]
    }`)

    conv := editorjs.New()
    editorjs.Register(conv, "code", code.RenderCode)

    html, err := conv.Convert(jsonData)
    if err != nil {
        panic(err)
    }

    fmt.Println(html)
}

📌 Notes

  • All code content is escaped using html.EscapeString to prevent HTML injection.
  • Suitable for displaying code in documentation or blogs.

🧱 Compatibility

  • Compatible with editorjs-go version 1.x

👤 License

MIT

Documentation ¶

Index ¶

Constants ¶

This section is empty.

Variables ¶

This section is empty.

Functions ¶

func RenderCode ¶

func RenderCode(b editorjs.Block[CodeData], ctx *editorjs.Context) (string, error)

RenderCode is the renderer function for the "code" block. It escapes code content and wraps it inside <pre><code>...</code></pre>.

Types ¶

type CodeData ¶

type CodeData struct {
	Code string `json:"code"`
}

CodeData represents the data structure for a code block in Editor.js.

Jump to

Keyboard shortcuts

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