Skip to content

Commit 495d12f

Browse files
fix(hastutiltojsx.js): didnt include childre element in reactElementList
1 parent 6a74a84 commit 495d12f

5 files changed

+26
-11
lines changed

input/1.testmarkdown.md

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ look like:
2424
Here's a numbered list:
2525

2626
1. first item
27+
- test under bullet
2728
2. second item
2829
3. third item
2930
--------------------------------------------

lib/flotFyrHastCompiler.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ module.exports = function flotFyrHastCompiler(options) {
1010

1111
function compiler(ast) {
1212
const jsxWithPlaceholders = hastToJsx(ast, options);
13-
1413
// jsxWithPlaceholders.htmlToJsx = a array of all used htmltags to jsxtags
1514
// [ 'headline', ''. '', '', '', 'quotes', '', '', '', '', 'headline']
1615
// empty strings in the array is element that didt not match, so we have to remove dublicated:
16+
1717
let uniqElementNames = [...new Set(jsxWithPlaceholders.htmlToJsx)];
1818

1919
let result = jsxWithPlaceholders.element;

lib/hastUtilToJsx.js

+17-8
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,32 @@ const kebabCase = require("kebab-case");
88
const stringifyEntities = require("stringify-entities");
99
const stringifyObject = require("stringify-object");
1010

11+
let ALL_HTML_JSX_TAGS = [];
12+
13+
function addElementToList(newHtmlToJsx) {
14+
if (!ALL_HTML_JSX_TAGS.includes(newHtmlToJsx)) {
15+
ALL_HTML_JSX_TAGS.push(newHtmlToJsx);
16+
}
17+
}
18+
1119
// Render all of a node's children to a single string.
1220
function renderChildren(ctx, parent, index) {
1321
if (!parent.children || parent.children.length === 0) {
22+
// let data = renderNode(ctx, node, index, parent);
1423
return {
15-
allNotes: null,
16-
allUsedHtmlToJsxTag: null
24+
allNotes: null
1725
};
1826
}
19-
let htmlToJsxTag = [];
27+
// let htmlToJsxTag = [];
2028
let all = parent.children
2129
.map((node, index) => {
2230
let data = renderNode(ctx, node, index, parent);
23-
htmlToJsxTag.push(data.htmlToJsx);
31+
addElementToList(data.htmlToJsx);
2432
return data.element;
2533
})
2634
.join("");
27-
2835
return {
29-
allNotes: all,
30-
allUsedHtmlToJsxTag: htmlToJsxTag
36+
allNotes: all
3137
};
3238
}
3339

@@ -282,11 +288,14 @@ function renderNode(ctx, node, index, parent) {
282288
}
283289
// return `<${wrapperName}>${element.allNotes}</${wrapperName}>`;
284290

291+
let listOfElements = ALL_HTML_JSX_TAGS;
292+
ALL_HTML_JSX_TAGS = [];
285293
return {
286294
element: `<${wrapperName}>${element.allNotes}</${wrapperName}>`,
287-
htmlToJsx: element.allUsedHtmlToJsxTag
295+
htmlToJsx: listOfElements
288296
};
289297
}
298+
290299
return {
291300
element: element,
292301
htmlToJsx: htmlToJsx

output/1.testmarkdown.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const frontMatter = {
1515
quantity: 834
1616
};
1717

18-
export default class Print extends React.PureComponent {
18+
export default class Testmarkdown extends React.PureComponent {
1919
render() {
2020
const props = this.props;
2121
return (
@@ -38,6 +38,11 @@ export default class Print extends React.PureComponent {
3838
<p>Here's a numbered list:</p>
3939
<ol>
4040
<li>first item</li>
41+
</ol>
42+
<ul>
43+
<li>test under bullet</li>
44+
</ul>
45+
<ol start={2}>
4146
<li>second item</li>
4247
<li>third item</li>
4348
</ol>

output/3.development.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const frontMatter = {
88
title: 'react development env'
99
};
1010

11-
export default class Print extends React.PureComponent {
11+
export default class Testmarkdown extends React.PureComponent {
1212
render() {
1313
const props = this.props;
1414
return (

0 commit comments

Comments
 (0)