How to use the roosterjs-editor-dom.isBlockElement function in roosterjs-editor-dom

To help you get started, we’ve selected a few roosterjs-editor-dom 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 microsoft / roosterjs / packages / roosterjs-editor-core / lib / coreAPI / insertNode.ts View on Github external
node,
                        isBegin ? refNode : refNode.nextSibling
                    );
                } else {
                    // if the refNode can have child, use appendChild (which is like to insert as first/last child)
                    // i.e. <div>hello</div>, the content will be inserted before/after hello
                    insertedNode = refNode.insertBefore(node, isBegin ? refNode.firstChild : null);
                }
            } else {
                // No first block, this can happen when editor is empty. Use appendChild to insert the content in contentDiv
                insertedNode = contentDiv.appendChild(node);
            }

            // Final check to see if the inserted node is a block. If not block and the ask is to insert on new line,
            // add a DIV wrapping
            if (insertedNode &amp;&amp; option.insertOnNewLine &amp;&amp; !isBlockElement(insertedNode)) {
                wrap(insertedNode);
            }

            break;
        case ContentPosition.Range:
        case ContentPosition.SelectionStart:
            let { range, rangeToRestore } = getInitialRange(core, option);

            if (!range) {
                return;
            }

            // if to replace the selection and the selection is not collapsed, remove the the content at selection first
            if (option.replaceSelection &amp;&amp; !range.collapsed) {
                range.deleteContents();
            }
github microsoft / roosterjs / packages / roosterjs-editor-core / lib / coreAPI / insertNode.ts View on Github external
node,
                        isBegin ? refNode : refNode.nextSibling
                    );
                } else {
                    // if the refNode can have child, use appendChild (which is like to insert as first/last child)
                    // i.e. <div>hello</div>, the content will be inserted before/after hello
                    insertedNode = refNode.insertBefore(node, isBegin ? refNode.firstChild : null);
                }
            } else {
                // No first block, this can happen when editor is empty. Use appendChild to insert the content in contentDiv
                insertedNode = contentDiv.appendChild(node);
            }

            // Final check to see if the inserted node is a block. If not block and the ask is to insert on new line,
            // add a DIV wrapping
            if (insertedNode &amp;&amp; option.insertOnNewLine &amp;&amp; !isBlockElement(insertedNode)) {
                wrap(insertedNode);
            }

            break;
        }
        case ContentPosition.DomEnd:
            // Use appendChild to insert the node at the end of the content div.
            let insertedNode = contentDiv.appendChild(node);
            // Final check to see if the inserted node is a block. If not block and the ask is to insert on new line,
            // add a DIV wrapping
            if (insertedNode &amp;&amp; option.insertOnNewLine &amp;&amp; !isBlockElement(insertedNode)) {
                wrap(insertedNode);
            }
            break;
        case ContentPosition.Range:
        case ContentPosition.SelectionStart:
github microsoft / roosterjs / packages / roosterjs-editor-core / lib / coreAPI / insertNode.ts View on Github external
}

            // Final check to see if the inserted node is a block. If not block and the ask is to insert on new line,
            // add a DIV wrapping
            if (insertedNode && option.insertOnNewLine && !isBlockElement(insertedNode)) {
                wrap(insertedNode);
            }

            break;
        }
        case ContentPosition.DomEnd:
            // Use appendChild to insert the node at the end of the content div.
            let insertedNode = contentDiv.appendChild(node);
            // Final check to see if the inserted node is a block. If not block and the ask is to insert on new line,
            // add a DIV wrapping
            if (insertedNode && option.insertOnNewLine && !isBlockElement(insertedNode)) {
                wrap(insertedNode);
            }
            break;
        case ContentPosition.Range:
        case ContentPosition.SelectionStart:
            let { range, rangeToRestore } = getInitialRange(core, option);

            if (!range) {
                return;
            }

            // if to replace the selection and the selection is not collapsed, remove the the content at selection first
            if (option.replaceSelection && !range.collapsed) {
                range.deleteContents();
            }
github microsoft / roosterjs / packages / roosterjs-editor-api / lib / format / clearBlockFormat.ts View on Github external
attributesToPreserve: string[]
): boolean {
    if (node.nodeType != NodeType.Element || getTagOfNode(node) == 'BR') {
        return false;
    }

    // 1. Recursively clear format of all its child nodes
    let allChildrenAreBlock = ([].slice.call(node.childNodes) as Node[])
        .map(n => clearNodeFormat(n, tagsToUnwrap, tagsToStopUnwrap, attributesToPreserve))
        .reduce((previousValue, value) => previousValue && value, true);

    if (!canCollapse(tagsToStopUnwrap, node)) {
        return false;
    }

    let returnBlockElement = isBlockElement(node);

    // 2. If we should unwrap this tag, put it into an array and unwrap it later
    if (tagsToUnwrap.indexOf(getTagOfNode(node)) >= 0 || allChildrenAreBlock) {
        if (returnBlockElement && !allChildrenAreBlock) {
            wrap(node);
        }
        unwrap(node);
    } else {
        // 3. Otherwise, remove all attributes
        clearAttribute(node as HTMLElement, attributesToPreserve);
    }

    return returnBlockElement;
}