How to use unist-util-is - 8 common examples

To help you get started, we’ve selected a few unist-util-is 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 jlevy / atom-flowmark / lib / remark-smart-word-wrap.js View on Github external
function visitor(node, ancestors) {
    if (!is('paragraph', node)) {
      return;
    }
    // TODO: For now, we do not wrap or normalize footnote definitions at all since they need to be indented. Should add this.
    if (ancestors && ancestors.length > 0 && is('footnoteDefinition', ancestors[ancestors.length - 1])) {
      return;
    }

    // Maintain paragraph reflow logic: Full set of lines and column position within each node.
    // Maintained for only the current piece of text being wrapped, which may begin at any column.
    // Rules: We just flow across all pieces, and ignore delimiter text when counting widths,
    // for simplicity. However there are a few tricky things are around mixing text and sibling
    // nodes (strong, emphasis, and link), when breaking is forbidden:
    // Case 1: You can't break after a node if the text follows it with no whitespace.
    // Case 2: You can't break before a node if the text precedes it with no whitespace.
    // Case 3: You can't break immediately at the start of a formatted node (strong, emphasis, or link).

    let position = 0;
    let breakAllowed = false;
    let sentenceEnded = false;
    let currentLine;
github jlevy / atom-flowmark / lib / remark-smart-word-wrap.js View on Github external
// Don't bother wrapping text inside links at all; just normalize the anchor text.
      // You can't wrap URLs. And wrapping anchor text is usually less clear than
      // splitting out the whole anchor and URL on one line.
      // We don't do this for emphasis or strong text, as they most often do flow well in the source.
      if (is('link', parent)) {
        addUnbreakableNode(parent);
        return;
      }

      for (let i = 0; i < parent.children.length; ++i) {
        const current = parent.children[i];
        const next = i + 1 < parent.children.length && parent.children[i + 1];

        if (current.children) {
          process(current, formatChain.concat(current.type));
        } else if (is('text', current)) {
          newText(current, false);

          const isPlain = formatChain.length === 0;
          const words = splitWords(current.value);
          for (let j = 0; j < words.length; ++j) {
            addWord(words[j], j > 0, isPlain);
          }

          // Add break at the end of this text node if the next next word/link isn't going to fit.
          // Unless there is no whitespace at the end of the last text node.
          // Handles Case 2.
          if (next && position + nodeMinLength(next) + 1 >= width && words[words.length - 1].endsWith(' ')) {
            breakLine(isPlain);
          }
          current.value = getLineBrokenText();
        }
github jlevy / atom-flowmark / lib / remark-smart-word-wrap.js View on Github external
function process(parent, formatChain) {
      // Don't bother wrapping text inside links at all; just normalize the anchor text.
      // You can't wrap URLs. And wrapping anchor text is usually less clear than
      // splitting out the whole anchor and URL on one line.
      // We don't do this for emphasis or strong text, as they most often do flow well in the source.
      if (is('link', parent)) {
        addUnbreakableNode(parent);
        return;
      }

      for (let i = 0; i < parent.children.length; ++i) {
        const current = parent.children[i];
        const next = i + 1 < parent.children.length && parent.children[i + 1];

        if (current.children) {
          process(current, formatChain.concat(current.type));
        } else if (is('text', current)) {
          newText(current, false);

          const isPlain = formatChain.length === 0;
          const words = splitWords(current.value);
          for (let j = 0; j < words.length; ++j) {
github jlevy / atom-flowmark / lib / remark-smart-word-wrap.js View on Github external
function nodeLength(node) {
  let len = 0;
  if (is('text', node)) {
    len += node.value.length;
  } else if (is('image', node)) {
    len += node.url.length + (node.alt || '').length;
  } else if (is('link', node)) {
    len += node.url.length;
  } else if (is('linkReference', node)) {
    len += node.identifier.length;
  }
  if (node.children) {
    node.children.forEach(child => {
      len += nodeLength(child);
    });
  }
  // Breaks or anything else treated as zero length.
  return len;
}
github jlevy / atom-flowmark / lib / remark-smart-word-wrap.js View on Github external
function nodeLength(node) {
  let len = 0;
  if (is('text', node)) {
    len += node.value.length;
  } else if (is('image', node)) {
    len += node.url.length + (node.alt || '').length;
  } else if (is('link', node)) {
    len += node.url.length;
  } else if (is('linkReference', node)) {
    len += node.identifier.length;
  }
  if (node.children) {
    node.children.forEach(child => {
      len += nodeLength(child);
    });
  }
  // Breaks or anything else treated as zero length.
  return len;
}
github jlevy / atom-flowmark / lib / remark-smart-word-wrap.js View on Github external
function nodeLength(node) {
  let len = 0;
  if (is('text', node)) {
    len += node.value.length;
  } else if (is('image', node)) {
    len += node.url.length + (node.alt || '').length;
  } else if (is('link', node)) {
    len += node.url.length;
  } else if (is('linkReference', node)) {
    len += node.identifier.length;
  }
  if (node.children) {
    node.children.forEach(child => {
      len += nodeLength(child);
    });
  }
  // Breaks or anything else treated as zero length.
  return len;
}
github attineos / atti-components / bin / generateNativeGuidist / index.js View on Github external
forEach(p.children, child => {
      if (is(MD.TEXT, child)) {
        renders.push({
          id: genUUID(),
          render: ``,
          beforeRender: `const Text = require('react-native').Text`,
        })
      }
    })
  }
github attineos / atti-components / bin / generateNativeGuidist / index.js View on Github external
function currentNode(node, file) {
    if (is(MD.PARAGRAPH, node)) {
      visitParagraph(node)
    } else if (is(MD.CODE, node)) {
      visitCode(node)
    } else if (!!node.children) {
      forEach(node.children, child => currentNode(child, file))
    } else if (is(MD.ROOT, node)) {
    }
  }

unist-util-is

unist utility to check if a node passes a test

MIT
Latest version published 10 months ago

Package Health Score

74 / 100
Full package analysis

Popular unist-util-is functions