doc.silverstripe.org/src/utils/parseChildrenOf.ts
Aaron Carlino 8ffc3eeb5b
WIP: Add userhelp to new site (#216)
* Docs/userguide switching

* Initial commit of userdocs merge

* Remove service worker, fix rendering

* Remove limited sources

* UX improvements per Paul design

* Tweak version select for FF

* Fix mobile view

* Final tweaks to UI

* Tweaks to search bar, clean up conflicts

* Fix icons

* Hide search if no API key
2019-12-19 11:54:23 +13:00

49 lines
2.0 KiB
TypeScript

import { ReactElement, createElement } from 'react';
import ChildrenOf from '../components/ChildrenOf';
import { getCurrentNode } from './nodes';
/**
* Turn [CHILDREN ... ] into a proper React component.
* @param data
*/
const parseChildrenOf = (data: any): ReactElement|false => {
const currentNode = getCurrentNode();
let matches;
matches = data.match(/\[CHILDREN Folder="?([A-Za-z0-9_<>\/]+)"?.*?\]/);
if (matches) {
const folderName = matches[1].replace(/<\/?em>/g, '_');
const asList = matches[0].match(' asList');
const includeFolders = matches[0].match(' includeFolders');
const reverse = matches[0].match(' reverse');
return createElement(ChildrenOf, { folderName, currentNode, asList, includeFolders, reverse })
}
matches = data.match(/\[CHILDREN Exclude="?([A-Za-z0-9_,]+)"?.*?\]/);
if (matches) {
const asList = matches[0].match(' asList');
const includeFolders = matches[0].match(' includeFolders');
const reverse = matches[0].match(' reverse');
const exclude = matches[1].replace(/<\/?em>/g, '_');
return createElement(ChildrenOf, { exclude, currentNode, asList, includeFolders, reverse })
}
matches = data.match(/\[CHILDREN Only="?([A-Za-z0-9_,]+)"?.*?\]/);
if (matches) {
const asList = matches[0].match(' asList');
const includeFolders = matches[0].match(' includeFolders');
const reverse = matches[0].match(' reverse');
const only = matches[1].replace(/<\/?em>/g, '_');
return createElement(ChildrenOf, { only, currentNode, asList, includeFolders, reverse })
}
matches = data.match(/\[CHILDREN(\sasList)?.*?\]/);
if (matches) {
const asList = !!matches[1];
const includeFolders = matches[0].match(' includeFolders');
const reverse = matches[0].match(' reverse');
return createElement(ChildrenOf, { currentNode, asList, includeFolders, reverse })
}
return false;
};
export default parseChildrenOf;