2
0
mirror of https://github.com/tenrok/BBob.git synced 2026-06-02 16:04:04 +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
+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)) {