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

fix(react): rendering self-closed tags and tags without content (#74)

This commit is contained in:
Nikolay Kostyurin
2020-11-16 22:59:08 +02:00
committed by GitHub
parent 9c71bb5f26
commit 5a7211db91
2 changed files with 10 additions and 2 deletions
+4 -2
View File
@@ -1,3 +1,4 @@
/* eslint-disable no-use-before-define */
import React from 'react';
import core from '@bbob/core';
import * as html from '@bbob/html';
@@ -10,12 +11,13 @@ const toAST = (source, plugins, options) => core(plugins)
render: (input) => html.render(input, { stripTags: true }),
}).tree;
const isContentEmpty = (content) => (!content || content.length === 0);
function tagToReactElement(node, index) {
return React.createElement(
node.tag,
{ ...node.attrs, key: index },
// eslint-disable-next-line no-use-before-define
node.content ? renderToReactNodes(node.content) : null,
isContentEmpty(node.content) ? null : renderToReactNodes(node.content),
);
}