Documentation ¶
Overview ¶
Package quill takes a Quill-based Delta (https://github.com/quilljs/delta) as a JSON array of `insert` operations and renders the defined HTML document.
This library is designed to be easily extendable. Simply call RenderExtended with a function that may provide its own formats for certain kinds of ops and attributes.
Example ¶
package main import ( "fmt" "github.com/dchenk/go-render-quill" ) var ops = []byte(` [ { "insert": "Heading1" }, { "attributes": { "header": 1 }, "insert": "\n" }, { "insert": "Hello, this is text.\nAnd " }, { "attributes": { "italic": true }, "insert": "here is italic " }, { "insert": "(and not).\nAnd " }, { "attributes": { "bold": true }, "insert": "here is bold" }, { "insert": "\n" } ]`) func main() { html, err := quill.Render(ops) if err != nil { panic(err) } fmt.Println(string(html)) }
Output: <h1>Heading1</h1><p>Hello, this is text.</p><p>And <em>here is italic </em>(and not).</p><p>And <strong>here is bold</strong></p>
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Render ¶
Render takes a Delta array of insert operations and returns the rendered HTML using the built-in settings. If an error occurs while rendering, any HTML already rendered is returned.
func RenderExtended ¶
RenderExtended takes a Delta array of insert operations and, optionally, a function that may provide a Formatter to customize the way certain kinds of inserts are rendered, and returns the rendered HTML. If the given Formatter is nil, then the default one that is built in is used. If an error occurs while rendering, any HTML already rendered is returned.
Types ¶
type Format ¶
type Format struct { Val string // the value to print Place FormatPlace // where this format is placed in the text Block bool // indicate whether this is a block-level format (not printed until a "\n" is reached) // contains filtered or unexported fields }
A Format specifies how styling to text is applied. The Val string is what is printed in the place given by Place. Block indicates if this is a block-level format.
type FormatPlace ¶
type FormatPlace uint8
A FormatPlace is either an HTML tag name, a CSS class, or a style attribute value.
const ( Tag FormatPlace = iota Class Style )
type FormatWrapper ¶
type FormatWrapper interface { Formatter Wrap() (pre, post string) // Say what opening and closing wraps will be written. Open([]*Format, *Op) bool // Given the open formats and current Op, say if to write the pre string. Close([]*Format, *Op, bool) bool // Given the open formats, current Op, and if the Op closes a block, say if to write the post string. }
A FormatWrapper wraps text with additional text of any kind (such as "<ul>" for lists).
type FormatWriter ¶
A FormatWriter can write the body of an Op in a custom way (useful for embeds).
type Formatter ¶
type Formatter interface { Fmt() *Format // Format gives the string to write and where to place it. HasFormat(*Op) bool // Say if the Op has the Format that Fmt returns. }
A Formatter is able to give a Format and say whether a given Op should have that Format applied.
type Op ¶
type Op struct { Data string // the text to insert or the value of the embed object (http://quilljs.com/docs/delta/#embeds) DataMap map[string]string Type string // the type of the op (typically "text", but any other type can be registered) Attrs map[string]string // key is attribute name; value is either the attribute value or "y" (meaning true) }
An Op is a Delta insert operations (https://github.com/quilljs/delta#insert) that has been converted into this format for usability with the type safety in Go.