Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions raw_op.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func (ro *rawOp) makeOp(o *Op) error {
for mk := range ins {
o.Type = mk
o.Data = extractString(ins[mk])
o.DataMap = extractMap(ins[mk])
break
}
default:
Expand Down Expand Up @@ -69,3 +70,19 @@ func extractString(v interface{}) string {
}
return ""
}

func extractMap(v interface{}) map[string]string {
switch val := v.(type) {
case map[string]interface{}:
newMap := make(map[string]string)
for key, value := range val {
if strValue, ok := value.(string); ok {
newMap[key] = strValue
} else {
newMap[key] = fmt.Sprint(value)
}
}
return newMap
}
return make(map[string]string)
}
12 changes: 8 additions & 4 deletions render.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ func RenderExtended(ops []byte, customFormats func(string, *Op) Formatter) ([]by
o: Op{Attrs: make(map[string]string, 3)},
}

raw = append(raw, rawOp{
Insert: "\n",
})
for i := range raw {

if err := raw[i].makeOp(&vars.o); err != nil {
Expand Down Expand Up @@ -133,9 +136,10 @@ func (o *Op) addFmTer(vars *renderVars, fmTer Formatter) {
// 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.
type Op struct {
Data string // the text to insert or the value of the embed object (http://quilljs.com/docs/delta/#embeds)
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)
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)
}

// writeBlock writes a block element (which may be nested inside another block element if it is a FormatWrapper).
Expand Down Expand Up @@ -393,7 +397,7 @@ type Format struct {

// A blankOp can be used to signal any FormatWrapper formats to write the final closing wrap.
func blankOp() *Op {
return &Op{"", "text", make(map[string]string)}
return &Op{"", make(map[string]string), "text", make(map[string]string)}
}

// If cl has something, then classesList returns the class attribute to add to an HTML element with a space before the
Expand Down