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


TypeScript MarkType.create方法代码示例

本文整理汇总了TypeScript中prosemirror-model.MarkType.create方法的典型用法代码示例。如果您正苦于以下问题:TypeScript MarkType.create方法的具体用法?TypeScript MarkType.create怎么用?TypeScript MarkType.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在prosemirror-model.MarkType的用法示例。


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

示例1: allowedBlocks

    state.doc.nodesBetween(from, to, (node, pos, parent) => {
        if (!node.type.isBlock) {
            return false
        }

        if (
            (!allowedBlocks ||
                (Array.isArray(allowedBlocks)
                    ? allowedBlocks.indexOf(node.type) > -1
                    : allowedBlocks(state.schema, node, parent))) &&
            parent.type.allowsMarkType(markType)
        ) {
            const oldMarks = node.marks.filter(mark => mark.type === markType)

            const prevAttrs = oldMarks.length ? (oldMarks[0].attrs as T) : undefined
            const newAttrs = getAttrs(prevAttrs, node)

            if (newAttrs !== undefined) {
                tr.setNodeMarkup(
                    pos,
                    node.type,
                    node.attrs,
                    node.marks
                        .filter(mark => !markType.excludes(mark.type))
                        .concat(newAttrs === false ? [] : markType.create(newAttrs)),
                )
                markApplied = true
            }
        }
    })
开发者ID:zodiac-team,项目名称:zodiac-ui,代码行数:30,代码来源:toggle-block-mark.ts

示例2: return

    return (state, match, start, end) => {
        const [, prefix, textWithCombo] = match
        const to = end
        // in case of *string* pattern it matches the text from beginning of the paragraph,
        // because we want ** to work for strong text
        // that's why "start" argument is wrong and we need to calculate it ourselves
        const from = textWithCombo ? start + prefix.length : start
        const nodeBefore = state.doc.resolve(start + prefix.length).nodeBefore

        if (
            prefix &&
            prefix.length > 0 &&
            !validRegex(char, prefix) &&
            !(nodeBefore && nodeBefore.type === state.schema.nodes.hardBreak)
        ) {
            return null
        }
        // fixes the following case: my `*name` is *
        // expected result: should ignore special characters inside "code"
        if (
            state.schema.marks.code &&
            state.schema.marks.code.isInSet(state.doc.resolve(from + 1).marks())
        ) {
            return null
        }

        // Prevent autoformatting across hardbreaks
        let containsHardBreak
        state.doc.nodesBetween(from, to, node => {
            if (node.type === schema.nodes.hardBreak) {
                containsHardBreak = true
                return false
            }
            return !containsHardBreak
        })
        if (containsHardBreak) {
            return null
        }

        // fixes autoformatting in heading nodes: # Heading *bold*
        // expected result: should not autoformat *bold*; <h1>Heading *bold*</h1>
        if (state.doc.resolve(from).sameParent(state.doc.resolve(to))) {
            if (!state.doc.resolve(from).parent.type.allowsMarkType(markType)) {
                return null
            }
        }

        // apply mark to the range (from, to)
        let tr = state.tr.addMark(from, to, markType.create())

        if (charSize > 1) {
            // delete special characters after the text
            // Prosemirror removes the last symbol by itself, so we need to remove "charSize - 1" symbols
            tr = tr.delete(to - (charSize - 1), to)
        }

        return (
            tr
                // delete special characters before the text
                .delete(from, from + charSize)
                .removeStoredMark(markType)
        )
    }
开发者ID:zodiac-team,项目名称:zodiac-ui,代码行数:63,代码来源:text.formatting.inputrule.ts


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