How to use the mobiledoc-kit/utils/dom-utils.normalizeTagName function in mobiledoc-kit

To help you get started, we’ve selected a few mobiledoc-kit 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 gazooka / GhostInAzureWebApp / node_modules / @tryghost / mobiledoc-kit / src / js / parsers / section.js View on Github external
&& isListSection
        && tagName !== lastSection.tagName;

      if (
        isNewListSection ||
        (isListSection && !isNestedListSection) ||
        isMarkupSection ||
        isListItem
      ) {
        // don't break out of the list for list items that contain a single <p>.
        // deals with typical case of </p><li><p>Text</p></li><li><p>Text</p></li>
        if (
          this.state.section.isListItem &amp;&amp;
          tagName === 'p' &amp;&amp;
          !node.nextSibling &amp;&amp;
          contains(VALID_LIST_ITEM_TAGNAMES, normalizeTagName(node.parentElement.tagName))
         ) {
          this.parseElementNode(node);
          return;
        }

        // avoid creating empty paragraphs due to wrapper elements around
        // section-creating elements
        if (this.state.section.isMarkerable &amp;&amp; !this.state.text &amp;&amp; this.state.section.markers.length === 0) {
          this.state.section = null;
        } else {
          this._closeCurrentSection();
        }

        this._updateStateFromElement(node);
      }
github bustle / mobiledoc-kit / src / js / utils / element-utils.js View on Github external
function getEventTargetMatchingTag(tagName, target, container) {
  tagName = normalizeTagName(tagName);
  // Traverses up DOM from an event target to find the node matching specifed tag
  while (target && target !== container) {
    if (normalizeTagName(target.tagName) === tagName) {
      return target;
    }
    target = target.parentNode;
  }
}
github gazooka / GhostInAzureWebApp / node_modules / @tryghost / mobiledoc-kit / src / js / parsers / section.js View on Github external
parseNode(node) {
    if (!this.state.section) {
      this._updateStateFromElement(node);
    }

    let nodeFinished = this.runPlugins(node);
    if (nodeFinished) {
      return;
    }

    // handle closing the current section and starting a new one if we hit a
    // new-section-creating element.
    if (this.state.section && !isTextNode(node) && node.tagName) {
      let tagName = normalizeTagName(node.tagName);
      let isListSection = contains(VALID_LIST_SECTION_TAGNAMES, tagName);
      let isListItem = contains(VALID_LIST_ITEM_TAGNAMES, tagName);
      let isMarkupSection = contains(VALID_MARKUP_SECTION_TAGNAMES, tagName);
      let isNestedListSection = isListSection && this.state.section.isListItem;
      let lastSection = this.sections[this.sections.length - 1];

      // we can hit a list item after parsing a nested list, when that happens
      // and the lists are of different types we need to make sure we switch
      // the list type back
      if (isListItem && lastSection && lastSection.isListSection) {
        let parentElement = node.parentElement;
        let parentElementTagName = normalizeTagName(parentElement.tagName);
        if (parentElementTagName !== lastSection.tagName) {
          this._closeCurrentSection();
          this._updateStateFromElement(parentElement);
        }
github bustle / mobiledoc-kit / src / js / parsers / section.js View on Github external
// handle closing the current section and starting a new one if we hit a
    // new-section-creating element.
    if (this.state.section && !isTextNode(node) && node.tagName) {
      let tagName = normalizeTagName(node.tagName);
      let isListSection = contains(VALID_LIST_SECTION_TAGNAMES, tagName);
      let isListItem = contains(VALID_LIST_ITEM_TAGNAMES, tagName);
      let isMarkupSection = contains(VALID_MARKUP_SECTION_TAGNAMES, tagName);
      let isNestedListSection = isListSection && this.state.section.isListItem;
      let lastSection = this.sections[this.sections.length - 1];

      // we can hit a list item after parsing a nested list, when that happens
      // and the lists are of different types we need to make sure we switch
      // the list type back
      if (isListItem && lastSection && lastSection.isListSection) {
        let parentElement = node.parentElement;
        let parentElementTagName = normalizeTagName(parentElement.tagName);
        if (parentElementTagName !== lastSection.tagName) {
          this._closeCurrentSection();
          this._updateStateFromElement(parentElement);
        }
      }

      // if we've broken out of a list due to nested section-level elements we
      // can hit the next list item without having a list section in the current
      // state. In this instance we find the parent list node and use it to
      // re-initialize the state with a new list section
      if (
        isListItem &&
        !(this.state.section.isListItem || this.state.section.isListSection) &&
        !lastSection.isListSection
      ) {
        this._closeCurrentSection();
github bustle / mobiledoc-kit / src / js / parsers / section.js View on Github external
parseNode(node) {
    if (!this.state.section) {
      this._updateStateFromElement(node);
    }

    let nodeFinished = this.runPlugins(node);
    if (nodeFinished) {
      return;
    }

    // handle closing the current section and starting a new one if we hit a
    // new-section-creating element.
    if (this.state.section && !isTextNode(node) && node.tagName) {
      let tagName = normalizeTagName(node.tagName);
      let isListSection = contains(VALID_LIST_SECTION_TAGNAMES, tagName);
      let isListItem = contains(VALID_LIST_ITEM_TAGNAMES, tagName);
      let isMarkupSection = contains(VALID_MARKUP_SECTION_TAGNAMES, tagName);
      let isNestedListSection = isListSection && this.state.section.isListItem;
      let lastSection = this.sections[this.sections.length - 1];

      // we can hit a list item after parsing a nested list, when that happens
      // and the lists are of different types we need to make sure we switch
      // the list type back
      if (isListItem && lastSection && lastSection.isListSection) {
        let parentElement = node.parentElement;
        let parentElementTagName = normalizeTagName(parentElement.tagName);
        if (parentElementTagName !== lastSection.tagName) {
          this._closeCurrentSection();
          this._updateStateFromElement(parentElement);
        }
github gazooka / GhostInAzureWebApp / node_modules / @tryghost / mobiledoc-kit / src / js / parsers / section.js View on Github external
_isSkippable(element) {
    return element.nodeType === NODE_TYPES.ELEMENT &&
           contains(SKIPPABLE_ELEMENT_TAG_NAMES,
                    normalizeTagName(element.tagName));
  }
}
github bustle / mobiledoc-kit / src / js / parsers / section.js View on Github external
_markupsFromElement(element) {
    let { builder } = this;
    let markups = [];
    if (isTextNode(element)) {
      return markups;
    }

    const tagName = normalizeTagName(element.tagName);
    if (this._isValidMarkupForElement(tagName, element)) {
      markups.push(builder.createMarkup(tagName, getAttributes(element)));
    }

    this._markupsFromElementStyle(element).forEach(
      markup => markups.push(markup)
    );

    return markups;
  }
github bustle / mobiledoc-kit / src / js / parsers / section.js View on Github external
_isSkippable(element) {
    return isCommentNode(element) ||
           (element.nodeType === NODE_TYPES.ELEMENT &&
            contains(SKIPPABLE_ELEMENT_TAG_NAMES,
                    normalizeTagName(element.tagName)));
  }
}