export default function(editor) { editor.addMarks([ Mark.create({ type: 'bold', data: { thing: 'value' }, }), Mark.create({ type: 'italic', data: { thing2: 'value2' }, }), ]) }
export default function(editor) { editor.addMark( Mark.create({ type: 'bold', data: { thing: 'value' }, }) ) }
export function createLeaves(tagName, attributes, children) { const { marks = Mark.createSet() } = attributes let length = 0 let leaves = Leaf.createList([]) let leaf children.forEach(child => { if (Leaf.isLeafList(child)) { if (leaf) { leaves = leaves.push(leaf) leaf = null } child.forEach(l => { l = preservePoint(l, obj => obj.addMarks(marks)) leaves = leaves.push(l) }) } else { if (!leaf) { leaf = Leaf.create({ marks, text: '' }) length = 0 } if (typeof child === 'string') { const offset = leaf.text.length leaf = preservePoint(leaf, obj => obj.insertText(offset, child)) length += child.length } if (isPoint(child)) { setPoint(leaf, child, length) } } }) if (!leaves.size && !leaf) { leaf = Leaf.create({ marks, text: '' }) } if (leaf) { leaves = leaves.push(leaf) } return leaves }
export default function( type: string, currentTextNode: Text, matched: any, change: Change ) { const matchedLength = matched[0].length; const addText = matched[0].trim().replace(new RegExp(/~/, "g"), ""); return change .deleteAtRange( Range.create({ anchorKey: currentTextNode.key, focusKey: currentTextNode.key, anchorOffset: matched.index, focusOffset: matched.index + matchedLength }) ) .insertTextByKey(currentTextNode.key, matched.index, addText, [ Mark.create({ type }) ]) .call(removeAllMark); }
export function createMark(tagName, attributes, children) { const { key, ...mark } = attributes const marks = Mark.createSet([mark]) const list = createChildren(children) let node if (list.size > 1) { throw new Error( `The <mark> hyperscript tag must only contain a single node's worth of children.` ) } else if (list.size === 0) { node = Text.create({ key, marks }) } else { node = list.first() node = preservePoints(node, n => { if (key) n = n.set('key', key) if (marks) n = n.set('marks', n.marks.union(marks)) return n }) } return node }
/** @jsx h */ import { Set } from 'immutable' import h from '../../../../helpers/h' import { Mark } from 'slate' export const input = ( <text> <b /> </text> ) export default function(t) { return t.getMarks() } export const output = Set.of(Mark.create('bold'))
marks: create('Set<Mark>', function (v) { return slate.Mark.isMarkSet(v); }),
mark: create('Mark', function (v) { return slate.Mark.isMark(v); }),
marks: create('Set<Mark>', v => Mark.isMarkSet(v)),
mark: create('Mark', v => Mark.isMark(v)),
export function createMark(tagName, attributes, children) { const marks = Mark.createSet([attributes]) const leaves = createLeaves('leaves', { marks }, children) return leaves }
export default function(t) { return t.updateMark(0, 3, Mark.create('bold'), { data: { x: 1 } }) }
/** @jsx h */ import h from '../../../../helpers/h' import { Set } from 'immutable' import { Mark } from 'slate' export const input = ( <text> <b> <i>Cat is </i> <i>Cute</i> </b> </text> ) export default function(t) { return t.getActiveMarks() } export const output = Set.of(Mark.create('italic'), Mark.create('bold'))
}) }, focus(tagName, attributes, children) { return FOCUS }, inline(tagName, attributes, children) { return Inline.create({ ...attributes, nodes: createChildren(children), }) }, mark(tagName, attributes, children) { const marks = Mark.createSet([attributes]) const nodes = createChildren(children, { marks }) return nodes }, selection(tagName, attributes, children) { return Range.create(attributes) }, value(tagName, attributes, children) { const { data } = attributes const document = children.find(Document.isDocument) let selection = children.find(Range.isRange) || Range.create() const props = {} // Search the document's texts to see if any of them have the anchor or
node = preservePoints(node, n => { if (key) n = n.set('key', key) if (marks) n = n.set('marks', Mark.createSet(marks)) return n })