sub-contents
This commit is contained in:
+110
-53
@@ -54,6 +54,28 @@ const hrefStyle = {
|
|||||||
textDecoration: "none",
|
textDecoration: "none",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const hrefStyleToc = {
|
||||||
|
color: "rgba(255, 255, 255, 0.6)",
|
||||||
|
textDecoration: "none",
|
||||||
|
fontSize: "14px",
|
||||||
|
fontWeight: 400,
|
||||||
|
padding: "4px 0",
|
||||||
|
paddingLeft: "8px",
|
||||||
|
paddingRight: "8px",
|
||||||
|
lineHeight: "20px",
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
const hrefStyleToc2 = {
|
||||||
|
color: "rgba(255, 255, 255, 0.6)",
|
||||||
|
textDecoration: "none",
|
||||||
|
fontSize: "14px",
|
||||||
|
fontWeight: 400,
|
||||||
|
padding: "4px 0",
|
||||||
|
paddingLeft: "12px",
|
||||||
|
paddingRight: "12px",
|
||||||
|
lineHeight: "20px",
|
||||||
|
};
|
||||||
|
|
||||||
const hrefStyle2 = {
|
const hrefStyle2 = {
|
||||||
color: "#f86a3e",
|
color: "#f86a3e",
|
||||||
@@ -66,6 +88,9 @@ const innerHrefStyle = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export const CopyToClipboard = (props) => {
|
export const CopyToClipboard = (props) => {
|
||||||
const { text, style, onCopy } = props;
|
const { text, style, onCopy } = props;
|
||||||
const parsedstyle = style !== undefined ? style : {
|
const parsedstyle = style !== undefined ? style : {
|
||||||
@@ -232,6 +257,10 @@ const Docs = (defaultprops) => {
|
|||||||
setAnchorEl(event.currentTarget);
|
setAnchorEl(event.currentTarget);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleCollapse(index) {
|
||||||
|
setOpen(isopen === index ? -1 : index)
|
||||||
|
}
|
||||||
|
|
||||||
function handleMouseOver() {
|
function handleMouseOver() {
|
||||||
setHover(!hover);
|
setHover(!hover);
|
||||||
}
|
}
|
||||||
@@ -240,6 +269,42 @@ const Docs = (defaultprops) => {
|
|||||||
setAnchorEl(null);
|
setAnchorEl(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function tocvalue(markdown) {
|
||||||
|
const items = [];
|
||||||
|
let currentMainItem = null;
|
||||||
|
|
||||||
|
const lines = markdown.split('\n');
|
||||||
|
|
||||||
|
for (let i = 0; i < lines.length; i++) {
|
||||||
|
const line = lines[i];
|
||||||
|
if (line.startsWith('* [')) {
|
||||||
|
const matches = line.match(/^\* \[([^)]+)\]\(#([^)]+)\)/);
|
||||||
|
if (matches) {
|
||||||
|
currentMainItem = {
|
||||||
|
id: matches[2],
|
||||||
|
title: matches[1],
|
||||||
|
items: [],
|
||||||
|
};
|
||||||
|
items.push(currentMainItem);
|
||||||
|
}
|
||||||
|
} else if (line.startsWith(' * [')) {
|
||||||
|
if (currentMainItem) {
|
||||||
|
const matches = line.match(/^ \* \[([^)]+)\]\(#([^)]+)\)/);
|
||||||
|
if (matches) {
|
||||||
|
currentMainItem.items.push({
|
||||||
|
id: matches[2],
|
||||||
|
title: matches[1],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (line.startsWith('##')) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return items
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const SidebarPaperStyle = {
|
const SidebarPaperStyle = {
|
||||||
backgroundColor: "rgb(26,26,26)",
|
backgroundColor: "rgb(26,26,26)",
|
||||||
@@ -293,8 +358,8 @@ const Docs = (defaultprops) => {
|
|||||||
width: "17%",
|
width: "17%",
|
||||||
position: "sticky",
|
position: "sticky",
|
||||||
top: 50,
|
top: 50,
|
||||||
minHeight: "90vh",
|
minHeight: "100vh",
|
||||||
maxHeight: "90vh",
|
maxHeight: "100vh",
|
||||||
overflowX: "hidden",
|
overflowX: "hidden",
|
||||||
overflowY: "auto",
|
overflowY: "auto",
|
||||||
zIndex: 1000,
|
zIndex: 1000,
|
||||||
@@ -350,7 +415,6 @@ const Docs = (defaultprops) => {
|
|||||||
const tocRegex = /^## Table of contents[\s\S]*?(?=^##\s|\Z)|^\* \[[^\]]+\]\([^)]+\)\n?(?![^\n]+\]\([^)]+\))/gm;
|
const tocRegex = /^## Table of contents[\s\S]*?(?=^##\s|\Z)|^\* \[[^\]]+\]\([^)]+\)\n?(?![^\n]+\]\([^)]+\))/gm;
|
||||||
const newdata = responseJson.reason.replace(imgRegex, '')
|
const newdata = responseJson.reason.replace(imgRegex, '')
|
||||||
.replace(tocRegex, "");
|
.replace(tocRegex, "");
|
||||||
console.log(newdata)
|
|
||||||
setData(newdata);
|
setData(newdata);
|
||||||
if (docId === undefined) {
|
if (docId === undefined) {
|
||||||
document.title = "Shuffle documentation introduction";
|
document.title = "Shuffle documentation introduction";
|
||||||
@@ -372,50 +436,10 @@ const Docs = (defaultprops) => {
|
|||||||
responseJson.reason !== undefined &&
|
responseJson.reason !== undefined &&
|
||||||
responseJson.reason !== null
|
responseJson.reason !== null
|
||||||
) {
|
) {
|
||||||
const splitkey = responseJson.reason.split("\n");
|
const values = tocvalue(responseJson.reason.match(tocRegex)
|
||||||
var innerTocLines = [];
|
.join()
|
||||||
var record = false;
|
.toString());
|
||||||
for (var key in splitkey) {
|
setTocLines(values);
|
||||||
const line = splitkey[key];
|
|
||||||
//console.log("Line: ", line)
|
|
||||||
if (line.toLowerCase().includes("table of contents")) {
|
|
||||||
record = true;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (record && line.length < 3) {
|
|
||||||
record = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (record) {
|
|
||||||
const parsedline = line.split("](");
|
|
||||||
if (parsedline.length > 1) {
|
|
||||||
parsedline[0] = parsedline[0].replaceAll("*", "");
|
|
||||||
parsedline[0] = parsedline[0].replaceAll("[", "");
|
|
||||||
parsedline[0] = parsedline[0].replaceAll("]", "");
|
|
||||||
parsedline[0] = parsedline[0].replaceAll("(", "");
|
|
||||||
parsedline[0] = parsedline[0].replaceAll(")", "");
|
|
||||||
parsedline[0] = parsedline[0].trim();
|
|
||||||
|
|
||||||
parsedline[1] = parsedline[1].replaceAll("*", "");
|
|
||||||
parsedline[1] = parsedline[1].replaceAll("[", "");
|
|
||||||
parsedline[1] = parsedline[1].replaceAll("]", "");
|
|
||||||
parsedline[1] = parsedline[1].replaceAll(")", "");
|
|
||||||
parsedline[1] = parsedline[1].replaceAll("(", "");
|
|
||||||
parsedline[1] = parsedline[1].trim();
|
|
||||||
//console.log(parsedline[0], parsedline[1])
|
|
||||||
|
|
||||||
innerTocLines.push({
|
|
||||||
text: parsedline[0],
|
|
||||||
link: parsedline[1],
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
console.log("Bad line for parsing: ", line);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
setTocLines(innerTocLines);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
setData("# Error\nThis page doesn't exist.");
|
setData("# Error\nThis page doesn't exist.");
|
||||||
@@ -758,19 +782,52 @@ const Docs = (defaultprops) => {
|
|||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
<nav style={IndexBar}>
|
<div style={IndexBar}>
|
||||||
{tocLines.map(data => (
|
<h2 style={{ fontWeight: 600, margin: 0, fontSize: "16px", marginBottom: "8px" }}>Table Of Content</h2>
|
||||||
|
<nav>
|
||||||
|
{tocLines.map((data, index) => {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
<ListItemButton
|
<ListItemButton
|
||||||
component={Link}
|
component={Link}
|
||||||
key={data.text}
|
key={data.text}
|
||||||
style={hrefStyle}
|
style={hrefStyleToc}
|
||||||
to={data.link}
|
to={`#${data.id}`}
|
||||||
|
onClick={() => (
|
||||||
|
handleCollapse(index)
|
||||||
|
)}
|
||||||
>
|
>
|
||||||
{data.text}
|
{data.title}
|
||||||
|
{data.items.length > 0 ? (
|
||||||
|
<>{isopen == index ? <ExpandMoreIcon /> : <KeyboardArrowRightIcon />}</>
|
||||||
|
) : null}
|
||||||
</ListItemButton>
|
</ListItemButton>
|
||||||
))}
|
{data.items.length > 0 &&
|
||||||
|
data.items !== null &&
|
||||||
|
data.items !== undefined ? (
|
||||||
|
<Collapse in={isopen === index} timeout="auto" unmountOnExit>
|
||||||
|
{data.items.map((d, i) => {
|
||||||
|
return (
|
||||||
|
<ListItemButton
|
||||||
|
component={Link}
|
||||||
|
key={i}
|
||||||
|
style={hrefStyleToc2}
|
||||||
|
to={`#${d.id}`}
|
||||||
|
>
|
||||||
|
{d.title}
|
||||||
|
</ListItemButton>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</Collapse>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
)
|
||||||
|
})}
|
||||||
</nav>
|
</nav>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
</div >
|
||||||
);
|
);
|
||||||
|
|
||||||
const mobileStyle = {
|
const mobileStyle = {
|
||||||
|
|||||||
Reference in New Issue
Block a user