How to use the parchment.Scope function in parchment

To help you get started, we’ve selected a few parchment 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 webiny / Webiny / Js / Webiny / Assets / node_modules / quill / modules / toolbar.js View on Github external
Object.keys(formats).forEach((name) => {
          // Clean functionality in existing apps only clean inline formats
          if (Parchment.query(name, Parchment.Scope.INLINE) != null) {
            this.quill.format(name, false);
          }
        });
      } else {
github sillsdev / web-languageforge / src / angular-app / bellows / apps / translate / editor / quill / suggestions-theme.ts View on Github external
setFormatUsx(elem, format);
      } else {
        super.format(name, value);
      }
    }
  }

  Scroll.allowedChildren.push(ParaBlock);
  Scroll.allowedChildren.push(ChapterEmbed);

  const HighlightClass = new QuillParchment.Attributor.Class('highlight', 'highlight', {
    scope: Parchment.Scope.INLINE
  });

  const SegmentClass = new QuillParchment.Attributor.Attribute('segment', 'data-segment', {
    scope: Parchment.Scope.INLINE
  });

  // Add a suggest tooltip to Quill
  class SuggestionsTooltip implements Tooltip {
    quill: Quill;
    boundsContainer: HTMLElement;
    root: HTMLElement;

    private top: number;

    constructor(quill: Quill, boundsContainer: HTMLElement) {
      this.quill = quill;
      this.boundsContainer = boundsContainer || document.body;
      this.root = quill.addContainer('ql-suggest-tooltip');
      if (this.quill.root === this.quill.scrollingContainer) {
        this.quill.root.addEventListener('scroll', () => {
github quilljs / quill / src / formats / code-block.js View on Github external
import Delta from 'rich-text/lib/delta';
import Parchment from 'parchment';
import logger from '../lib/logger';


let debug = logger('quill:code-block');


class TokenAttributor extends Parchment.Attributor.Class {
  value(domNode) {
    return undefined;
  }
}

let CodeToken = new TokenAttributor('token', 'hljs', {
  scope: Parchment.Scope.INLINE
});


class CodeBlock extends Block {
  format(name, value) {
    // TODO allow changing language
    debug.warn(`format(${name}, ${value}) called on code block`);
  }

  formatAt(index, length, name, value) {
    debug.warn(`formatAt(${index}, ${length}, ${name}, ${value}) called on code block`);
  }

  formats() {
    return {
      'code-block': this.domNode.getAttribute('data-language') || true
github quilljs / quill / blots / cursor.js View on Github external
format(name, value) {
    if (this._length !== 0) {
      return super.format(name, value);
    }
    let target = this, index = 0;
    this._length = Cursor.CONTENTS.length;
    while (target != null && target.statics.scope !== Parchment.Scope.BLOCK_BLOT) {
      index += target.offset(target.parent);
      target = target.parent;
    }
    if (target != null) {
      target.formatAt(index, Cursor.CONTENTS.length, name, value);
    }
    this._length = 0;
  }
github twofactor / MenubarNotes / node_modules / quill / core / quill.js View on Github external
return modify.call(this, () => {
      let range = this.getSelection(true);
      let change = new Delta();
      if (range == null) {
        return change;
      } else if (Parchment.query(name, Parchment.Scope.BLOCK)) {
        change = this.editor.formatLine(range.index, range.length, { [name]: value });
      } else if (range.length === 0) {
        this.selection.format(name, value);
        return change;
      } else {
        change = this.editor.formatText(range.index, range.length, { [name]: value });
      }
      this.setSelection(range, Emitter.sources.SILENT);
      return change;
    }, source);
  }
github webiny / Webiny / Js / Webiny / Assets / node_modules / quill / modules / keyboard.js View on Github external
let lineFormats = Object.keys(context.format).reduce(function(lineFormats, format) {
    if (Parchment.query(format, Parchment.Scope.BLOCK) && !Array.isArray(context.format[format])) {
      lineFormats[format] = context.format[format];
    }
    return lineFormats;
  }, {});
  this.quill.insertText(range.index, '\n', lineFormats, Quill.sources.USER);
github quilljs / quill / formats / font.js View on Github external
import Parchment from 'parchment';

let config = {
  scope: Parchment.Scope.INLINE,
  whitelist: ['serif', 'monospace']
};

let FontClass = new Parchment.Attributor.Class('font', 'ql-font', config);

class FontStyleAttributor extends Parchment.Attributor.Style {
  value(node) {
    return super.value(node).replace(/["']/g, '');
  }
}

let FontStyle = new FontStyleAttributor('font', 'font-family', config);

export { FontStyle, FontClass };
github sillsdev / web-languageforge / src / SIL.XForge.Scripture / ClientApp / src / app / shared / text / quill-scripture.ts View on Github external
}

    static value(node: HTMLElement): Chapter {
      return getUsxValue(node);
    }
  }

  Scroll.allowedChildren.push(ParaBlock);
  Scroll.allowedChildren.push(ChapterEmbed);

  const HighlightClass = new QuillParchment.Attributor.Class('highlight', 'highlight', {
    scope: Parchment.Scope.INLINE
  });

  const SegmentClass = new QuillParchment.Attributor.Attribute('segment', 'data-segment', {
    scope: Parchment.Scope.INLINE
  });

  class DisableHtmlClipboard extends QuillClipboard {
    onPaste(e: ClipboardEvent): void {
      if (e.defaultPrevented || !this.quill.isEnabled()) {
        return;
      }
      const range = this.quill.getSelection();
      let delta = new Delta().retain(range.index);
      const scrollTop = this.quill.scrollingContainer.scrollTop;
      this.container.focus();
      this.quill.selection.update('silent');

      const text = e.clipboardData.getData('text/plain');
      setTimeout(() => {
        this.container.innerHTML = text;
github vanilla / vanilla / plugins / rich-editor / src / scripts / quill / blots / blocks / ListBlot.ts View on Github external
export class UnorderedListGroup extends ListGroup {
    public static blotName = "unorderedListGroup";
    public static className = "unorderedListGroup";
    public static tagName = ListTag.UL;
}

/**
 * The li in <ul><li><span></span></li></ul>
 *
 * Although this blot represents the item itself, the actual format, value, &amp; delta
 * all come from the list content.
 *
 * This item is purely a wrapper so that nested list content can be included separately form the
 */
export class ListItemWrapper extends withWrapper(Container as any) {
    public static scope = Parchment.Scope.BLOCK_BLOT;
    public static blotName = "listItemWrapper";
    public static className = "listItemWrapper";
    public static tagName = ListTag.LI;
    public static parentName = [UnorderedListGroup.blotName, OrderedListGroup.blotName];

    /**
     * Create the dom node for th item and
     *
     * @param value
     */
    public static create(value: IListObjectValue) {
        const element = super.create(value) as HTMLElement;
        syncValueToElement(element, value);
        return element;
    }
github quilljs / quill / formats / background.js View on Github external
import Parchment from 'parchment';
import { ColorAttributor } from './color';

let BackgroundClass = new Parchment.Attributor.Class('background', 'ql-bg', {
  scope: Parchment.Scope.INLINE
});
let BackgroundStyle = new ColorAttributor('background', 'background-color', {
  scope: Parchment.Scope.INLINE
});

export { BackgroundClass, BackgroundStyle };