All Projects → rosylilly → react-jsx-renderer

rosylilly / react-jsx-renderer

Licence: MIT license
A React component for Rendering JSX

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to react-jsx-renderer

core
Server side rendering with The Elm Architecture in Deno
Stars: ✭ 16 (-62.79%)
Mutual labels:  jsx
react-ui-components
React UI Components (npm @assenti/rui-components)
Stars: ✭ 21 (-51.16%)
Mutual labels:  jsx
math-magicians
Website for all fans of mathematics. It is a Single Page App (SPA) that allows users to make simple calculations. read a random motivation-related quote and write a to-do list.
Stars: ✭ 22 (-48.84%)
Mutual labels:  jsx
SchematicWebViewer
An NPM package to facilitate importing and viewing of modern Minecraft schematics.
Stars: ✭ 44 (+2.33%)
Mutual labels:  renderer
ECHI VUE TODO
使用 Vue 开发的一款 TODO 应用,包含登录、待办、日程、历史事项、回收站。项目较为小型,适合进阶学习使用(💡请注意,项目大量使用 jsx 进行开发)。
Stars: ✭ 19 (-55.81%)
Mutual labels:  jsx
React-Netflix-Clone
A Fully Responsive clone of Netflix website built using React.JS as a Front-end & Firebase as a Back-end.
Stars: ✭ 91 (+111.63%)
Mutual labels:  jsx
string-dom
Create HTML strings using JSX (or functions).
Stars: ✭ 13 (-69.77%)
Mutual labels:  jsx
Vitro
Experimental C++20 multiplatform graphics engine.
Stars: ✭ 14 (-67.44%)
Mutual labels:  renderer
vuetify-tsx
Vuetify TSX is just a wrapper lib around vuetify components.
Stars: ✭ 20 (-53.49%)
Mutual labels:  jsx
jupyterlab plotly
This repository is deprecated. The extension has moved to https://github.com/jupyterlab/jupyter-renderers
Stars: ✭ 16 (-62.79%)
Mutual labels:  renderer
SwiftMark
[⚠️Not a complete implementation] A Markdown renderer written in Swift.
Stars: ✭ 77 (+79.07%)
Mutual labels:  renderer
studybuddy-web
📚 Website for all the study materials for IIITV curriculums 🎉
Stars: ✭ 17 (-60.47%)
Mutual labels:  jsx
vue3-jd-h5
🔥 Based on vue3.0.0, vant3.0.0, vue-router v4.0.0-0, vuex^4.0.0-0, vue-cli3, mockjs, imitating Jingdong Taobao, mobile H5 e-commerce platform! 基于vue3.0.0 ,vant3.0.0,vue-router v4.0.0-0, vuex^4.0.0-0,vue-cli3,mockjs,仿京东淘宝的,移动端H5电商平台!
Stars: ✭ 660 (+1434.88%)
Mutual labels:  jsx
remark-jsx
A simple way to use React inside Markdown.
Stars: ✭ 29 (-32.56%)
Mutual labels:  jsx
pose refine
cuda icp for 6D pose estimation
Stars: ✭ 84 (+95.35%)
Mutual labels:  renderer
ios-scriptable-tsx
在 vscode 上使用 typescript 和 jsx 开发 ios 小组件的小框架.基于 Scriptable app.
Stars: ✭ 113 (+162.79%)
Mutual labels:  jsx
datum
Vulkan Renderer
Stars: ✭ 31 (-27.91%)
Mutual labels:  renderer
react-calculator
📐 PWA React + Redux Calculator
Stars: ✭ 65 (+51.16%)
Mutual labels:  jsx
crud-app
❄️ A simple and beautiful CRUD application built with React.
Stars: ✭ 61 (+41.86%)
Mutual labels:  jsx
electron-esbuild
Create Electron apps using esbuild and your favorite frontend tool
Stars: ✭ 60 (+39.53%)
Mutual labels:  renderer

React JSX Renderer

npm (latest) npm (nightlyt)

demo Coverage Status Dependencies Status Install size License: MIT

latest nightly build test lint

A React Component for Rendering JSX.

Description

React JSX Renderer is a React Component for rendering JSX to React nodes.

It has a JavaScript Runtime inside, and can execute the user's JSX with controlled behavior.

Launch Demo

Features

  • Rendering JSX as React nodes
  • TypeScritpt ready
  • Provides CommonJS and ES Modules
  • JavaScript syntax and featues
    • without async, await and generator
  • Injectable custom React components
  • Pass binding variables
  • Applicable filters to parsed nodes
    • You can create allowlist / denylist filters to tagName, attributes or properties
  • Avoid user's call expressions
  • Avoid user's new expressions
  • Parse with meriyah

Installation

  1. npm install -s react-jsx-renderer (or yarn add react-jsx-renderer)
  2. Add import { JSXRenderer } from 'react-jsx-renderer';
  3. <JSXRenderer code="Hello, World" /> to render Hello, World

Requirements

  • React: >= 16.0.0

Options

interface ParseOptions {
  /**
   * Options of parser
   */
  meriyah?: meriyah.Options;

  /**
   * When this option is enabled, always parse as an expression.
   */
  forceExpression?: boolean;
}

interface EvaluateOptions {
  /**
   * binding
   */
  binding?: Binding;

  /**
   * components
   */
  components?: ComponentsBinding;

  /**
   * Prefix of generated keys.
   */
  keyPrefix?: string;

  /**
   * When this option is enabled, no key will be generated
   */
  disableKeyGeneration?: boolean;

  /**
   * When this option is enabled, bindings will be excluded from the component search.
   */
  disableSearchCompontsByBinding?: boolean;

  /**
   * When this option is enabled, Call Expression and New Expression will always return undefined.
   */
  disableCall?: boolean;

  /**
   * When this option is enabled, New Expression will always return undefined.
   */
  disableNew?: boolean;

  /**
   * When this option is enabled, access to undefined variables will raise an exception.
   */
  raiseReferenceError?: boolean;

  /**
   * List of functions allowed to be executed.
   *
   * If empty, all functions will be allowed to execute.
   */
  allowedFunctions?: AnyFunction[];

  /**
   * Add user-defined functions to the allowed list.
   */
  allowUserDefinedFunction?: boolean;

  /**
   * List of functions denied to be executed.
   *
   * If empty, all functions will be allowed to execute.
   */
  deniedFunctions?: AnyFunction[];
}

interface RenderingOptions {
  /**
   * List of filters to be applied to elements.
   */
  elementFilters?: JSXElementFilter[];

  /**
   * List of filters to be applied to fragments.
   */
  fragmentFilters?: JSXFragmentFilter[];

  /**
   * List of filters to be applied to text nodes.
   */
  textFilters?: JSXTextFilter[];

  /**
   * When this option is enabled, non-existent HTML elements will not be rendered.
   */
  disableUnknownHTMLElement?: boolean;

  /**
   * Function to determine Unknown HTML Element
   */
  isUnknownHTMLElementTagName?: UnknownHTMLElementTagNameFunction;
}

interface RendererOptions extends {
  /**
   * JSX code
   */
  code?: string;

  /**
   * The component that will be displayed instead when an error occurs.
   */
  fallbackComponent?: JSXFallbackComponent;

  /**
   * If you want to receive the parsed result, set a Ref object to this option.
   */
  refNodes?: Ref<JSXNode[]>;
}

Usage

Using like a simple HTML template engine

input:

import { render } from 'react-dom';
import { JSXRenderer } from 'react-jsx-renderer';

const root = document.getElementById('root');

render(
  <JSXRenderer
    binding={{ name: 'Sho Kusano' }}
    code={'<p>Hello, {name}</p>'}
  />,
  root
);

to:

<p>Hello, Sho Kusano</p>

Using JSX with JavaScript expressions

input:

render(
  <JSXRenderer
    binding={{
      three: 3,
      seven: 7,
    }}
    code={
      '<p>+ {three + seven}</p>' +
      '<p>- {three - seven}</p>' +
      '<p>bitwise shift {three << seven}</p>'
    }
  />,
  root
);

to:

<p>+ 10</p>
<p>- -4</p>
<p>bitwise shift 384</p>

Using JSX with your favorite custom components

const Red = ({ children }) => <b style={{ color: 'red' }}>{children}</b>

render(
  <JSXRenderer
    components={{ RedColor: Red }}
    code={'<p><RedColor>red</RedColor></p>'}
  />,
  root
);

to:

<p><b style="color: red">red</b></p>

Convert JSX with filters

const hrefFilter = (element: JSXElement) => {
  const { props, component, children } = element;
  if (component !== 'a') return element;

  let href = props.href || '';
  if (href.includes('//')) {
    href = secureURLConvert(href); // Add prefix https://secure.url/redirect?url=
  }
  const filteredProps = { ...props, href };
  return { component, children, props: filteredProps };
}

render(
  <JSXRenderer
    elementFilters={[hrefFilter]}
    code={
      '<p><a href="https://github.com/">root</a></p>' +
      '<p><a href="../">upper directory</a></p>' +
      '<p><a href="subdir">sub directory</a></p>' +
      '<p><a href="https://github.com/">github</a></p>' +
    }
  />,
  root
);

to:

<p><a href="/">root</a></p>
<p><a href="../">upper directory</a></p>
<p><a href="subdir">sub directory</a></p>
<p><a href="https://secure.url/redirect?url=https://github.com">github</a></p>

Provide options by context

ex: Server side rendering.

import { JSDOM } from 'jsdom';

render(
  <JSXRendererOptionsProvider isUnknownHTMLElement={(tagName) => {
    const { window } = new JSDOM();
    return window.document.createElement(tagName) instanceof window.HTMLUnknownElement;
  }}>
    <JSXRenderer
      code={
        '<p><unknown>Avoid</unknown></p>'
      }
    />
  </JSXRendererOptionsProvider>,
  root
);

to:

<p></p>

License

MIT License

Related projects

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].