当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript prosemirror-inputrules.inputRules函数代码示例

本文整理汇总了TypeScript中prosemirror-inputrules.inputRules函数的典型用法代码示例。如果您正苦于以下问题:TypeScript inputRules函数的具体用法?TypeScript inputRules怎么用?TypeScript inputRules使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了inputRules函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: horizontalRuleInputRulePlugin

export function horizontalRuleInputRulePlugin(schema: Schema): Plugin | undefined {
    const rules: Array<InputRule> = []

    if (schema.nodes.rule) {
        // '---' and '***' for hr
        rules.push(
            // -1, so that it also replaces the container paragraph
            createInputRule(
                /^(\-\-\-|\*\*\*)$/,
                (state, match, start, end) => createHorizontalRuleAutoformat(state, start - 1, end),
                true,
            ),
        )

        // '---' and '***' after shift+enter for hr
        rules.push(
            createInputRule(
                new RegExp(`${leafNodeReplacementCharacter}(\\-\\-\\-|\\*\\*\\*)`),
                (state, match, start, end) => {
                    const { hardBreak } = state.schema.nodes
                    if (state.doc.resolve(start).nodeAfter.type !== hardBreak) {
                        return null
                    }
                    return createHorizontalRuleAutoformat(state, start, end)
                },
                true,
            ),
        )
    }

    if (rules.length !== 0) {
        return inputRules({ rules })
    }
}
开发者ID:zodiac-team,项目名称:zodiac-ui,代码行数:34,代码来源:input-rule.ts

示例2: createInputRulePlugin

export function createInputRulePlugin(schema: Schema): Plugin | undefined {
    if (!schema.marks.link) {
        return
    }

    const urlWithASpaceRule = createLinkInputRule((new LinkMatcher() as unknown) as RegExp, match =>
        match[3] ? match[1] : `https?://${match[1]}`,
    )

    // [something](link) should convert to a hyperlink
    const markdownLinkRule = createInputRule(
        /(^|[^])\[(.*?)\]\((\S+)\)$/,
        (state, match, start, end) => {
            // tslint:disable-next-line:no-shadowed-variable
            const { schema } = state
            const [, prefix, linkText, linkUrl] = match
            const url = normalizeUrl(linkUrl)
            const markType = schema.mark("link", { href: url })

            console.log("match?")

            return state.tr.replaceWith(
                start + prefix.length,
                end,
                schema.text(linkText, [markType]),
            )
        },
    )

    return inputRules({
        rules: [urlWithASpaceRule, markdownLinkRule],
    })
}
开发者ID:zodiac-team,项目名称:zodiac-ui,代码行数:33,代码来源:input-rule.ts

示例3: inputRulePlugin

export function inputRulePlugin(schema: Schema): Plugin | undefined {
    const rules: Array<InputRuleWithHandler> = []

    if (schema.nodes.heading) {
        rules.push(...getHeadingRules(schema))
    }

    if (schema.nodes.blockquote) {
        rules.push(...getBlockQuoteRules(schema))
    }

    if (schema.nodes.codeBlock) {
        rules.push(...getCodeBlockRules(schema))
    }

    if (rules.length !== 0) {
        return inputRules({ rules })
    }
}
开发者ID:zodiac-team,项目名称:zodiac-ui,代码行数:19,代码来源:block-type.inputrule.ts

示例4: inputRulePlugin

export function inputRulePlugin(schema: Schema): Plugin | undefined {
    const rules: Array<InputRule> = []

    if (schema.marks.strong) {
        rules.push(...getStrongInputRules(schema))
    }

    if (schema.marks.em) {
        rules.push(...getItalicInputRules(schema))
    }

    if (schema.marks.strike) {
        rules.push(...getStrikeInputRules(schema))
    }

    if (schema.marks.code) {
        rules.push(...getCodeInputRules(schema))
    }

    if (rules.length !== 0) {
        return inputRules({ rules })
    }
}
开发者ID:zodiac-team,项目名称:zodiac-ui,代码行数:23,代码来源:text.formatting.inputrule.ts

示例5: buildMenuItemsPlugin

  buildMenuItemsPlugin() {
    let r = {}, deps;

    if (this.outputFormat === ProseMirrorFormatTypes.MARKDOWN) {
      if (this.outputSchema.marks.strong) {
        r['toggleStrong'] = this.markItem(this.outputSchema.marks.strong, {
          title: 'Toggle strong style',
          icon: icons.strong
        });
      }
      if (this.outputSchema.marks.em) {
        r['toggleEm'] = this.markItem(this.outputSchema.marks.em, {title: 'Toggle emphasis', icon: icons.em});
      }
      if (this.outputSchema.marks.code) { // this one is bonus
        r['toggleCode'] = this.markItem(this.outputSchema.marks.code, {title: 'Toggle code font', icon: icons.code});
      }
      if (this.outputSchema.marks.link) {
        r['toggleLink'] = this.linkItem(this.outputSchema.marks.link);
      }
      if (this.outputSchema.nodes.image && this.images && this.images.length > 0) {
        if (this.images.length === 1) {
          r['insertImage'] = this.insertImageItem(this.images[0], 'Image: ' + this.images[0].name);
        } else {
          for (let i = 0; i < this.images.length; i++) {
            r['insertImage' + i] = this.insertImageItem(this.images[i], this.images[i].name);
          }
        }
      }
      if (this.outputSchema.nodes.bullet_list) { // lists are bonus
        r['wrapBulletList'] = this.wrapListItem(this.outputSchema.nodes.bullet_list, {
          title: 'Wrap in bullet list',
          icon: icons.bulletList
        });
      }
      if (this.outputSchema.nodes.ordered_list) { // bonus
        r['wrapOrderedList'] = this.wrapListItem(this.outputSchema.nodes.ordered_list, {
          title: 'Wrap in ordered list',
          icon: icons.orderedList
        });
      }
      if (this.outputSchema.nodes.blockquote) { // bonus
        r['wrapBlockQuote'] = wrapItem(this.outputSchema.nodes.blockquote, {
          title: 'Wrap in block quote',
          icon: icons.blockquote
        });
      }
      if (this.outputSchema.nodes.paragraph) {
        r['makeParagraph'] = blockTypeItem(this.outputSchema.nodes.paragraph, {
          title: 'Change to paragraph',
          label: 'Plain'
        });
      }
      if (this.outputSchema.nodes.code_block) {// bonus
        r['makeCodeBlock'] = blockTypeItem(this.outputSchema.nodes.code_block, {
          title: 'Change to code block',
          label: 'Code'
        });
      }
      if (this.outputSchema.nodes.heading) {
        for (let i = 1; i <= 6; i++) {
          r['makeHead' + i] = blockTypeItem(this.outputSchema.nodes.heading, {
            title: 'Change to heading ' + i,
            label: 'Level ' + i,
            attrs: {level: i}
          });
        }
      }
      if (this.outputSchema.nodes.horizontal_rule) {// bonus
        r['insertHorizontalRule'] = new MenuItem({
          title: 'Insert horizontal rule',
          label: 'Horizontal rule',
          select: (state) => {
            return this.canInsert(state, this.outputSchema.nodes.horizontal_rule);
          },
          run: (state, dispatchTransaction) => {
            dispatchTransaction(state.tr.replaceSelectionWith(this.outputSchema.nodes.horizontal_rule.create()));
          }
        });
      }

      let cut = arr => arr.filter(x => x);

      if (this.images && this.images.length > 1) {
        let imageSubs = Object.keys(r).filter(key => key.match(/insertImage+/)).map(key => r[key]);
        let imageSubMenu = new DropdownSubmenu(imageSubs, {label: 'Image'});
        r['insertMenu'] = new Dropdown(cut([imageSubMenu, r['insertHorizontalRule']]), {label: 'Insert'});
      } else {
        r['insertMenu'] = new Dropdown(cut([r['insertImage'], r['insertHorizontalRule']]), {label: 'Insert'});
      }
      r['typeMenu'] = new Dropdown(cut([r['makeParagraph'], r['makeCodeBlock'], r['makeHead1'] && new DropdownSubmenu(cut([
        r['makeHead1'], r['makeHead2'], r['makeHead3'], r['makeHead4'], r['makeHead5'], r['makeHead6']
      ]), {label: 'Heading'})]), {label: 'Type...'});

      r['inlineMenu'] = [cut([r['toggleStrong'], r['toggleEm'], r['toggleCode'], r['toggleLink']]), [r['insertMenu']]];
      r['blockMenu'] = [cut([r['typeMenu'], r['wrapBulletList'], r['wrapOrderedList'], r['wrapBlockQuote'], joinUpItem,
        liftItem])];
      r['fullMenu'] = r['inlineMenu'].concat(r['blockMenu']);

      deps = [
        inputRules({rules: allInputRules.concat(this.buildInputRules())}),
//.........这里部分代码省略.........
开发者ID:PRX,项目名称:publish.prx.org,代码行数:101,代码来源:prosemirror.markdown.editor.ts


注:本文中的prosemirror-inputrules.inputRules函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。