EditorTextEncoding
public protocol EditorTextEncoding
Describes an encoder for a content type in Editor. This can be used in conjunction with AnyEditorTextEncoding
to register various encoders for each of the supported content types.
### Usage Example ###
struct ParagraphEncoder: EditorTextEncoding {
func encode(name: EditorContent.Name, string: NSAttributedString) -> JSON {
var paragraph = JSON()
paragraph.type = name.rawValue
if let style = string.attribute(.paragraphStyle, at: 0, effectiveRange: nil) as? NSParagraphStyle {
paragraph[style.key] = style.value
}
paragraph.contents = contentsFrom(string)
return paragraph
}
}
See also
EditorContentEncoder
-
Undocumented
Declaration
Swift
associatedtype EncodedType
-
Encodes the given attributed string to
EncodedType
Declaration
Swift
func encode(name: EditorContent.Name, string: NSAttributedString) -> EncodedType
Parameters
name
Name of the content to encode
string
Attributed string to encode