How to use hast-to-hyperscript - 7 common examples

To help you get started, we’ve selected a few hast-to-hyperscript 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 FujitsuLaboratories / cattaz / src / WikiParser.js View on Github external
if (ctx.cursorPosition && WikiParser.isInside(ctx.cursorPosition, position)) {
            propsForElem.className += ' active-inner'; // must have 'md' class
          }
        }
        delete propsForElem.position;
      }
      return React.createElement(name, propsForElem, children);
    }

    let rootNode = customHast;
    if (rootNode.type === 'root') {
      rootNode = clone(rootNode);
      rootNode.type = 'element';
      rootNode.tagName = 'div';
    }
    return toH(h, rootNode);
  }
github mdx-js / mdx / src / react-transformer.js View on Github external
this.Compiler = node => {
    parseFrontmatter(node)

    console.log(node)

    return toHyper(h, {
      type: 'element',
      tagName: 'div',
      properties: {},
      children: toHast(node, {
        allowDangerousHTML: true,
        handlers: {
          html: (h, node, parent) => {
            console.log(parent)
            parent.type = 'element'
            parent.tagName = 'React.Fragment'
          }
        }
      }).children
    })
  }
}
github patternplate / patternplate / packages / client / source / application / utils / to-elements.js View on Github external
function toElements(data) {
  if (!data) {
    return null;
  }

  const root = toh(React.createElement, data);
  return root.props.children;
}
github wix / okidoc / packages / okidoc-site / site / src / utils / renderHtmlAst.js View on Github external
type: 'element',
      tagName: FRAGMENT_TAG_NAME,
      properties: {},
      children: node.children,
    };
  }

  function h(name, props, children) {
    return React.createElement(
      getReactElement(name, components),
      props,
      getReactChildren(name, children),
    );
  }

  return toH(h, node);
}
github patternplate / patternplate / packages / client / src / app / utils / to-elements.js View on Github external
function toElements(data) {
  if (!data) {
    return null;
  }

  const root = toh(React.createElement, data);
  return root.props.children;
}
github benawad / codeponder / packages / web / utils / highlightCode.ts View on Github external
export const getHighlightedCode = (
  code: string,
  lang: string,
  firstLineNum: number
): React.ReactNode[] | string => {
  let ast = getHast(code, lang);
  if (ast) {
    if (!isNaN(firstLineNum)) {
      ast = addLineNumber(ast, firstLineNum || 1).nodes;
    }
    const root = toH(React.createElement, { type: "root", children: ast });
    return root.props.children;
  }
  return code;
};
github patternplate / patternplate / packages / client / src / app / components / common / code / to-elements.js View on Github external
function toElements(children) {
  if (!Array.isArray(children)) {
    return children;
  }

  const root = toh(React.createElement, {
    type: "element",
    tagName: "div",
    children
  });

  return root.props.children;
}

hast-to-hyperscript

Deprecated: use [`hast-util-to-jsx-runtime`][hast-util-to-jsx-runtime] instead, which is much better :)

Unknown
Latest version published 1 year ago

Package Health Score

52 / 100
Full package analysis

Popular hast-to-hyperscript functions

Similar packages