2
0
mirror of https://github.com/tenrok/BBob.git synced 2026-06-05 16:42:27 +03:00

feat: new @bbob/html api (#4)

This commit is contained in:
Nikolay Kostyurin
2018-10-12 00:43:20 +02:00
committed by GitHub
parent bf993813fc
commit 575c1bb932
12 changed files with 66 additions and 45 deletions
+3 -4
View File
@@ -1,7 +1,6 @@
const React = require('react');
const PropTypes = require('prop-types');
const { render } = require('./render');
import React from 'react';
import PropTypes from 'prop-types';
import { render } from './render';
const content = (children, plugins) => React.Children.map(children, child =>
(typeof child === 'string' ? render(child, plugins) : child));
+4 -12
View File
@@ -1,33 +1,25 @@
import React from 'react';
import core from '@bbob/core';
import html from '@bbob/html';
import * as html from '@bbob/html';
import { isTagNode, isStringNode } from '@bbob/plugin-helper';
const toAST = (source, plugins) => core(plugins)
.process(source, {
render: input => html(input, { stripTags: true }),
render: input => html.render(input, { stripTags: true }),
}).tree;
function tagToReactElement(node) {
if (node.content === null) {
return React.createElement(
node.tag,
node.attrs,
null,
);
}
return React.createElement(
node.tag,
node.attrs,
// eslint-disable-next-line no-use-before-define
renderToReactNodes(node.content),
node.content ? renderToReactNodes(node.content) : null,
);
}
function renderToReactNodes(nodes) {
const els = nodes.reduce((arr, node) => {
const els = [].concat(nodes).reduce((arr, node) => {
if (isTagNode(node)) {
arr.push(tagToReactElement(node));
} else if (isStringNode(node)) {