Skip to content

Commit

Permalink
fix: extract overview fix for repetitive sections
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Mar 19, 2020
1 parent 6e87f65 commit 8114ef5
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 23 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
- [Core packages](#core-packages)
- [@component-controls/instrument](#component-controlsinstrument)
- [UI packages](#ui-packages)
- [@component-controls/components](#component-controlscomponents)
- [@component-controls/editors](#component-controlseditors)
- [@component-controls/blocks](#component-controlsblocks)

# Core packages
Expand Down Expand Up @@ -35,8 +37,24 @@ Parsing a source file will generate the following information:

<package-section file="./ui/components/README.md" section="overview" />

<!-- START-PACKAGE-SECTION -->

## @component-controls/components

A collection of the base UI components used by component-controls

<!-- END-PACKAGE-SECTION -->

<package-section file="./ui/editors/README.md" section="overview" />

<!-- START-PACKAGE-SECTION -->

## @component-controls/editors

A collection of editors used to enter the control values

<!-- END-PACKAGE-SECTION -->

<package-section file="./ui/blocks/README.md" section="overview" />

<!-- START-PACKAGE-SECTION -->
Expand Down
49 changes: 26 additions & 23 deletions scripts/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,32 @@ const inlineNewContent = ({section, tagName, node}, newContent) => {
const startTag = `<!-- START-${tagName.toUpperCase()} -->`;
const endTag = `<!-- END-${tagName.toUpperCase()} -->`;
const index = node.children.indexOf(section);
let deleteNodes = 0;
let foundComment = false;
for (let i = index + 1; i < node.children.length; i +=1) {
const childNode = node.children[i];
if (childNode.type == 'html' && childNode.value == startTag) {
foundComment = true;
}
if (foundComment) {
deleteNodes += 1;
}
if (childNode.type == 'html' && childNode.value == endTag) {
break;
}
}
node.children.splice(index + 1, deleteNodes, ...[
{
type:'html',
value: startTag
},
...newContent, {
type:'html',
value: endTag
}]);
if (index === -1) {
return;
}
let deleteNodes = 0;
let foundComment = false;
for (let i = index + 1; i < node.children.length; i +=1) {
const childNode = node.children[i];
if (childNode.type == 'html' && childNode.value == startTag) {
foundComment = true;
}
if (foundComment) {
deleteNodes += 1;
}
if (childNode.type == 'html' && (childNode.value == endTag || childNode.value.toLowerCase().startsWith(`<${tagName}`))) {
break;
}
}
node.children.splice(index + 1, deleteNodes, ...[
{
type:'html',
value: startTag
},
...newContent, {
type:'html',
value: endTag
}]);

}
module.exports.extractCustomTag = extractCustomTag;
Expand Down

0 comments on commit 8114ef5

Please sign in to comment.