Skip to content

Commit

Permalink
Add same possibilities to example description #241
Browse files Browse the repository at this point in the history
  • Loading branch information
afonsobspinto committed May 8, 2020
1 parent 6f4cc1a commit 63f3035
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
39 changes: 24 additions & 15 deletions geppetto-showcase/components/showcase/ShowcaseUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ function getExample(start) {
let elements = getElementsUntil('pre', start, true);
let example = {
name: start.innerHTML,
description: '',
};
let description = [];

for (let elem of elements) {
if (elem.matches('pre')) {
Expand All @@ -124,10 +124,12 @@ function getExample(start) {
path +
'.js');
} else {
example['description'] += elem.innerHTML;
let innerElements = parseInnerHTML(elem.innerHTML);
description.push(...innerElements);
}
}

const container = React.createElement('div', {}, description);
example['description'] = container;
return example;
}

Expand Down Expand Up @@ -173,18 +175,8 @@ function getContentUntil(selector, start) {
const content = getElementsUntil(selector, start);
for (let element of content) {
let innerHTML = element.innerHTML;
let breaks = innerHTML.split('\n');
for (let i = 0; i < breaks.length; i++) {
const b = breaks[i];
const src = isImageTag(b);
if (src) {
const img = React.createElement('img', { src: src });
elements.push(img);
} else {
const p = React.createElement('p', { key: `${i}${b[0]}` }, b);
elements.push(p);
}
}
let innerElements = parseInnerHTML(innerHTML);
elements.push(...innerElements);
const br = React.createElement('br');
elements.push(br);
}
Expand All @@ -193,6 +185,23 @@ function getContentUntil(selector, start) {
return container;
}

function parseInnerHTML(innerHTML) {
let breaks = innerHTML.split('\n');
let elements = [];
for (let i = 0; i < breaks.length; i++) {
const b = breaks[i];
const src = isImageTag(b);
if (src) {
const img = React.createElement('img', { src: src });
elements.push(img);
} else {
const p = React.createElement('p', { key: `${i}${b[0]}` }, b);
elements.push(p);
}
}
return elements;
}

function isImageTag(text) {
let re = new RegExp('<img.*?src="(.*?)"');
let matches = text.match(re);
Expand Down
4 changes: 4 additions & 0 deletions geppetto-ui/src/components/connectivity-viewer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ connectivity-viewer/ConnectivityComponent

Draws a square matrix, where each row [column] correspond to a source [target] node. Therefore, filled squares at i,j denote a directed edge from node i to node j. The rows/columns can be sorted by node name, number of incoming connections, and number of outgoing connections. Circles above each row/column indicate the type of nodes in that row/column.

Paragraph

![alt text](https://github.com/adam-p/markdown-here/raw/master/src/common/images/icon48.png 'Logo Title Text 1')

```
connectivity-viewer/showcase/examples/ConnectivityShowcaseMatrix
```
Expand Down

0 comments on commit 63f3035

Please sign in to comment.