1 | import core from '@bbob/core';
|
2 | import * as html from '@bbob/html';
|
3 | import { isStringNode, isTagNode } from '@bbob/plugin-helper';
|
4 | const toAST = (source, plugins = [], options = {})=>core(plugins).process(source, {
|
5 | ...options,
|
6 | render: (input)=>html.render(input, {
|
7 | stripTags: true
|
8 | })
|
9 | }).tree;
|
10 | const isContentEmpty = (content)=>!content || content.length === 0;
|
11 | function tagToVueNode(createElement, node, index) {
|
12 | const { class: className , style , ...domProps } = node.attrs || {};
|
13 | return createElement(node.tag, {
|
14 | key: index,
|
15 | class: className,
|
16 | style,
|
17 | domProps
|
18 | }, isContentEmpty(node.content) ? null : renderToVueNodes(createElement, node.content));
|
19 | }
|
20 | function renderToVueNodes(createElement, nodes) {
|
21 | return [].concat(nodes).reduce((arr, node, index)=>{
|
22 | if (isTagNode(node)) {
|
23 | arr.push(tagToVueNode(createElement, node, index));
|
24 | } else if (isStringNode(node)) {
|
25 | arr.push(node);
|
26 | }
|
27 | return arr;
|
28 | }, []);
|
29 | }
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 | export function render(createElement, source, plugins, options) {
|
38 | return renderToVueNodes(createElement, toAST(source, plugins, options));
|
39 | }
|