How to use the slate.Mark.create function in slate

To help you get started, we’ve selected a few slate examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Simon-Initiative / authoring-client / src / data / content / learning / slate / topersistence.ts View on Github external
function handleMarkedText(node: Text, content) {
  const isBdo = (m: Mark) => m.type === 'bdo';
  const isForeign = (m: Mark) => m.type === 'foreign';

  // const marks = node.marks.toArray().map(m => m.type);
  const marks = node.marks.toArray();

  // if bdo is present, it must be the first element that
  // we place in the OLI JSON.  This is a DTD constraint.
  const adjustedMarks = marks.some(isBdo)
    ? [Mark.create({ type: 'bdo' }), ...marks.filter(m => !isBdo(m))]
    : marks;

  const root = { root: {} };
  let last = root;

  adjustedMarks.forEach((mark) => {
    // For each style, create the object representation for that style
    if (mark === undefined) {
      return;
    }

    const type = mark.type;
    const container = styleContainers[type];
    let style;
    if (container === undefined) {
      style = Object.assign({}, styleContainers.em());
github blocks / blocks / packages / mdx / editor / src / plugins / markdown-shortcuts.js View on Github external
key: currentTextNode.key,
      path: currentTextNode.path,
      offset: isBackwards ? other.length + 1 : offset
    })
    const range = Range.create({
      anchor,
      focus
    })

    return editor
      .deleteAtRange(range)
      .insertTextByKey(
        currentTextNode.key,
        isBackwards ? offset : other.length,
        inlineCode,
        [Mark.create({ type })]
      )
      .command(editor =>
        editor.value.marks.forEach(mark => {
          editor.removeMark(mark)
        })
      )
  }

  next()
}
github haiwen / seahub / frontend / src / lib / seafile-slate-plugin.js View on Github external
) {
  const matchedLength = matched[0].length;
  const reg = matched[1] === "*" ? /\*/ : matched[1];
  const addText = matched[0].replace(new RegExp(reg, "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: "ITALIC" })
    ])
    .call(trailingSpace, currentTextNode, matched.index)
    .call(removeAllMark);
}
github sanity-io / sanity / packages / @sanity / block-editor / src / conversion.js View on Github external
return new Set(tags.map(tag => {
    return Mark.create({type: tag, data: {}})
  }))
}
github letterpad / letterpad / admin / features / article / editor / plugins / markdown / match / boldItalic.js View on Github external
export default (type, currentTextNode, matched, change) => {
  const matchedLength = matched[0].length;
  const reg = matched[1] === "***" ? /\*\*\*/ : matched[1];
  const addText = matched[0].trim().replace(new RegExp(reg, "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: "bold" }),
      Mark.create({ type: "italic" }),
    ])
    .call(trailingSpace, currentTextNode, matched.index)
    .call(removeAllMark);
};
github letterpad / letterpad / admin / features / article / editor / plugins / markdown / match / italic.js View on Github external
export default (type, currentTextNode, matched, change) => {
  const matchedLength = matched[0].length;
  const reg = matched[1] === "*" ? /\*/ : matched[1];
  const addText = matched[0].replace(new RegExp(reg, "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(trailingSpace, currentTextNode, matched.index)
    .call(removeAllMark);
};
github Foundry376 / Mailspring / app / src / components / composer-editor / link-plugins.jsx View on Github external
function onPaste(event, change, editor) {
  const html = event.clipboardData.getData('text/html');
  const plain = event.clipboardData.getData('text/plain');
  const regex = RegExpUtils.urlRegex({ matchStartOfString: true, matchTailOfString: true });
  if (!html && plain && plain.match(regex)) {
    const mark = Mark.create({ type: LINK_TYPE, data: { href: plain } });
    change
      .addMark(mark)
      .insertText(plain)
      .removeMark(mark);
    return true;
  }
}
github Foundry376 / Mailspring / app / src / components / composer-editor / markdown-plugins.tsx View on Github external
transform: (transform, e, matches) => {
      const text = matches.before[2];
      const mark = Mark.create({ type: MARK_CONFIG.bold.type });
      const marks = Mark.createSet([mark]);
      transform.insertText(text, marks).removeMark(mark.type);
    },
  }),