mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-08 21:17:08 +02:00
reworking gravprep to fix most links and oddities
This commit is contained in:
parent
8e50c0fd56
commit
e436f65d4c
1 changed files with 100 additions and 73 deletions
|
@ -74,7 +74,7 @@
|
||||||
const html_reg_propertiesHeaderEdit_Replace = '<h4 class="subsection-title">Properties</h4>';
|
const html_reg_propertiesHeaderEdit_Replace = '<h4 class="subsection-title">Properties</h4>';
|
||||||
const html_reg_typeEdit = /(<h5>Returns[\s\S]*?Type)(<\/dt[\s\S]*?type">)(.*?)(<\/span><\/dd>[\s\S]*?<\/dl>)/g;
|
const html_reg_typeEdit = /(<h5>Returns[\s\S]*?Type)(<\/dt[\s\S]*?type">)(.*?)(<\/span><\/dd>[\s\S]*?<\/dl>)/g;
|
||||||
const html_reg_typeEdit_replace = '$1: $3</dt></dl>'
|
const html_reg_typeEdit_replace = '$1: $3</dt></dl>'
|
||||||
const html_reg_methodSize = /(<h4)( class="name"[\s\S]*?<\/span>)(<\/h4>)/g;
|
const html_reg_methodSize = /(<h4)( class="name"[\s\S]*?)(<\/h4>)/g;
|
||||||
const html_reg_methodSize_replace = '<h5$2</h5>';
|
const html_reg_methodSize_replace = '<h5$2</h5>';
|
||||||
const html_reg_typeDefSize = /(<h4)( class="name"[\s\S].*?)(<\/h4>)/g;
|
const html_reg_typeDefSize = /(<h4)( class="name"[\s\S].*?)(<\/h4>)/g;
|
||||||
const html_reg_typeDefSize_replace = '<h5$2</h5>';
|
const html_reg_typeDefSize_replace = '<h5$2</h5>';
|
||||||
|
@ -85,12 +85,14 @@
|
||||||
const html_reg_findByName = '<h5 class="name"';
|
const html_reg_findByName = '<h5 class="name"';
|
||||||
const html_reg_findByTitle = '<h1>';
|
const html_reg_findByTitle = '<h1>';
|
||||||
const html_reg_findByMethod = '<h3 class="subsection-title">Methods</h3>'
|
const html_reg_findByMethod = '<h3 class="subsection-title">Methods</h3>'
|
||||||
|
const html_reg_findByMethod_replace = '<h4 class="subsection-title">Methods</h4>'
|
||||||
const html_reg_containerOverview = `<div class="container-overview">`
|
const html_reg_containerOverview = `<div class="container-overview">`
|
||||||
const html_reg_findByArticleOpen = `<article>`
|
const html_reg_findByArticleOpen = `<article>`
|
||||||
const html_reg_findByArticleClose = `</article>`
|
const html_reg_findByArticleClose = `</article>`
|
||||||
const html_reg_signalTitle = `<h4 class="subsection-title">Signals</h4>`;
|
const html_reg_signalTitle = `<h4 class="subsection-title">Signals</h4>`;
|
||||||
const html_reg_typeDefinitonsTitle = `<h4 class="subsection-title">Type Definitions</h4>`;
|
const html_reg_typeDefinitonsTitle = /<h3 class="subsection-title">Type Definitions<\/h3>/;
|
||||||
const html_reg_firstTableClose = `</table>`;
|
const html_reg_typeDefinitonsTitle_replace = `<h4 class="subsection-title">Type Definitions</h4>`
|
||||||
|
const html_reg_firstDivClose = `</div>`;
|
||||||
const html_reg_fixLinkHashIssue = /(<a href=")(.*?)(\.)(.*?">)/g;
|
const html_reg_fixLinkHashIssue = /(<a href=")(.*?)(\.)(.*?">)/g;
|
||||||
const html_reg_fixLinkHashIssue_replace = "$1$2#$4"
|
const html_reg_fixLinkHashIssue_replace = "$1$2#$4"
|
||||||
const html_reg_findLinks = /(<a href="[\s\S]+?<\/a>)/g;
|
const html_reg_findLinks = /(<a href="[\s\S]+?<\/a>)/g;
|
||||||
|
@ -411,6 +413,7 @@
|
||||||
}
|
}
|
||||||
extractedIDs.push(id)
|
extractedIDs.push(id)
|
||||||
})
|
})
|
||||||
|
// console.log("extractedIDs", extractedIDs)
|
||||||
return extractedIDs;
|
return extractedIDs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -418,8 +421,6 @@
|
||||||
// Takes: Content to split, SearchTerm to Split by, and term to End Splitting By
|
// Takes: Content to split, SearchTerm to Split by, and term to End Splitting By
|
||||||
// Returns: [newContent after Split, Array of extracted ]
|
// Returns: [newContent after Split, Array of extracted ]
|
||||||
function splitBy(content, searchTerm, endSplitTerm){
|
function splitBy(content, searchTerm, endSplitTerm){
|
||||||
console.log("content1", content);
|
|
||||||
console.log("endSplitTerm", endSplitTerm);
|
|
||||||
let foundArray = [];
|
let foundArray = [];
|
||||||
let curIndex = -1;
|
let curIndex = -1;
|
||||||
let afterCurSearchIndex = -1
|
let afterCurSearchIndex = -1
|
||||||
|
@ -430,14 +431,12 @@
|
||||||
do {
|
do {
|
||||||
// Find the index of where to stop searching
|
// Find the index of where to stop searching
|
||||||
curEndSplitTermIndex = content.indexOf(endSplitTerm);
|
curEndSplitTermIndex = content.indexOf(endSplitTerm);
|
||||||
console.log("curEndSplitTermIndex", curEndSplitTermIndex)
|
|
||||||
// Find the index of the the next Search term
|
// Find the index of the the next Search term
|
||||||
curIndex = content.indexOf(searchTerm);
|
curIndex = content.indexOf(searchTerm);
|
||||||
// The index of where the next search will start
|
// The index of where the next search will start
|
||||||
afterCurSearchIndex = curIndex+findbyNameLength;
|
afterCurSearchIndex = curIndex+findbyNameLength;
|
||||||
// Find the content of the next Index
|
// Find the content of the next Index
|
||||||
nextIndex = content.indexOf(searchTerm,afterCurSearchIndex);
|
nextIndex = content.indexOf(searchTerm,afterCurSearchIndex);
|
||||||
console.log("nextIndex", nextIndex)
|
|
||||||
// If the next index isn't found, then next index === index of the end term
|
// If the next index isn't found, then next index === index of the end term
|
||||||
if (nextIndex === -1){
|
if (nextIndex === -1){
|
||||||
nextIndex = curEndSplitTermIndex;
|
nextIndex = curEndSplitTermIndex;
|
||||||
|
@ -448,16 +447,11 @@
|
||||||
content = content.replace(foundArray[curfoundArrayIndex], "");
|
content = content.replace(foundArray[curfoundArrayIndex], "");
|
||||||
curfoundArrayIndex++;
|
curfoundArrayIndex++;
|
||||||
curEndSplitTermIndex = content.indexOf(endSplitTerm);
|
curEndSplitTermIndex = content.indexOf(endSplitTerm);
|
||||||
console.log("curEndSplitTermIndex2", curEndSplitTermIndex)
|
|
||||||
nextIndex = content.indexOf(searchTerm,afterCurSearchIndex);
|
nextIndex = content.indexOf(searchTerm,afterCurSearchIndex);
|
||||||
// console.log("nextIndex2", nextIndex)
|
// handle if nextIndex goes beyond endSplitTerm
|
||||||
|
|
||||||
if (nextIndex > curEndSplitTermIndex) {
|
if (nextIndex > curEndSplitTermIndex) {
|
||||||
curIndex = content.indexOf(searchTerm);
|
curIndex = content.indexOf(searchTerm);
|
||||||
console.log("curIndex", curIndex)
|
|
||||||
console.log("curEndSplitTermIndex", curEndSplitTermIndex)
|
|
||||||
foundArray.push(content.slice(curIndex, curEndSplitTermIndex))
|
foundArray.push(content.slice(curIndex, curEndSplitTermIndex))
|
||||||
console.log("foundArray[curfoundArrayIndex],", foundArray[curfoundArrayIndex],)
|
|
||||||
content = content.replace(foundArray[curfoundArrayIndex], "");
|
content = content.replace(foundArray[curfoundArrayIndex], "");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -468,11 +462,9 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// Split the signals and methods [Might make this more generic]
|
// Split the signals and methods [Might make this more generic]
|
||||||
function splitMethodsSignalsAndTypeDefs(allItemToSplit){
|
function splitMethodsSignals(allItemToSplit){
|
||||||
let methodArray = [];
|
let methodArray = [];
|
||||||
let signalArray = [];
|
let signalArray = [];
|
||||||
let typeDefArray = [];
|
|
||||||
let description;
|
|
||||||
|
|
||||||
allItemToSplit.forEach( (content, index) => {
|
allItemToSplit.forEach( (content, index) => {
|
||||||
// console.log("content", content);
|
// console.log("content", content);
|
||||||
|
@ -482,25 +474,13 @@
|
||||||
// console.log("### FOUND SIGNAL", content);
|
// console.log("### FOUND SIGNAL", content);
|
||||||
signalArray.push(content);
|
signalArray.push(content);
|
||||||
} else if (firstLine.indexOf("span") > -1) {
|
} else if (firstLine.indexOf("span") > -1) {
|
||||||
// console.log("### FOUND SPAN", content);
|
|
||||||
if (content.indexOf("Available in:") > -1){
|
|
||||||
// console.log("### DESCRIPTION", content);
|
|
||||||
description = content;
|
|
||||||
} else {
|
|
||||||
// console.log("### METHOD", content);
|
// console.log("### METHOD", content);
|
||||||
methodArray.push(content);
|
methodArray.push(content);
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// console.log("### TYPEDEF", content);
|
|
||||||
if(firstLine.trim() !== ""){
|
|
||||||
// console.log("### TYPEDEF", content);
|
|
||||||
typeDefArray.push(content);
|
|
||||||
} else {
|
} else {
|
||||||
// console.log("not handled", content);
|
// console.log("not handled", content);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
})
|
})
|
||||||
return [methodArray, signalArray, typeDefArray, description];
|
return [methodArray, signalArray];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper to append
|
// Helper to append
|
||||||
|
@ -508,7 +488,9 @@
|
||||||
// and bool if the append is before the found area
|
// and bool if the append is before the found area
|
||||||
function append(content, searchTermToAppendto, contentToAppend, appendBefore){
|
function append(content, searchTermToAppendto, contentToAppend, appendBefore){
|
||||||
let contentArray = content.split("\n");
|
let contentArray = content.split("\n");
|
||||||
|
console.log("contentArray", contentArray);
|
||||||
let foundIndex = findArrayTrim(contentArray, searchTermToAppendto)
|
let foundIndex = findArrayTrim(contentArray, searchTermToAppendto)
|
||||||
|
console.log("foundIndex", foundIndex)
|
||||||
foundIndex = appendBefore ? foundIndex : foundIndex +1
|
foundIndex = appendBefore ? foundIndex : foundIndex +1
|
||||||
|
|
||||||
contentArray.splice(foundIndex,0,contentToAppend)
|
contentArray.splice(foundIndex,0,contentToAppend)
|
||||||
|
@ -618,58 +600,80 @@
|
||||||
|
|
||||||
// Further HTML Manipulation
|
// Further HTML Manipulation
|
||||||
// Make end term either Type Definitions or by the article
|
// Make end term either Type Definitions or by the article
|
||||||
let endTerm = html_reg_findByArticleClose;
|
let endTerm;
|
||||||
|
let foundTypeDefinitions;
|
||||||
|
let foundSignalsAndMethods;
|
||||||
if (currentContent.indexOf("Type Definitions") > -1){
|
if (currentContent.indexOf("Type Definitions") > -1){
|
||||||
console.log("Found Type Definitions")
|
console.log("Found Type Definitions");
|
||||||
endTerm = `<h3 class="subsection-title">Type Definitions</h3>`
|
endTerm = `<h3 class="subsection-title">Type Definitions</h3>`;
|
||||||
}
|
|
||||||
|
|
||||||
// Split HTML by Each named entry
|
// Split HTML by Each named entry
|
||||||
let contentSplitArray = splitBy(currentContent, html_reg_findByName, endTerm);
|
let contentSplitArray = splitBy(currentContent, html_reg_findByName, endTerm);
|
||||||
|
foundSignalsAndMethods = contentSplitArray[1];
|
||||||
// Create a reference to the current content after split and the split functions
|
// Create a reference to the current content after split and the split functions
|
||||||
currentContent = contentSplitArray[0]
|
currentContent = contentSplitArray[0]
|
||||||
.replace(html_reg_typeDefinitonsTitle, "") // Remove Type Definitions Title to be remade later;
|
.replace(html_reg_typeDefinitonsTitle, ""); // Remove Type Definitions Title to be remade later;
|
||||||
|
endTerm = html_reg_findByArticleClose;
|
||||||
|
// Grab split Type Definitions
|
||||||
|
let contentSplitArrayForTypeDefs = splitBy(currentContent, html_reg_findByName, endTerm);
|
||||||
|
currentContent = contentSplitArrayForTypeDefs[0];
|
||||||
|
foundTypeDefinitions = contentSplitArrayForTypeDefs[1];
|
||||||
|
} else {
|
||||||
|
endTerm = html_reg_findByArticleClose;
|
||||||
|
let contentSplitArray = splitBy(currentContent, html_reg_findByName, endTerm);
|
||||||
|
foundSignalsAndMethods = contentSplitArray[1];
|
||||||
|
currentContent = contentSplitArray[0];
|
||||||
|
}
|
||||||
|
|
||||||
// Create references to the split methods and signals
|
// Create references to the split methods and signals
|
||||||
let processedMethodsSignalsAndTypeDefs = splitMethodsSignalsAndTypeDefs(contentSplitArray[1]);
|
|
||||||
// let splitMethods = processedMethodsSignalsAndTypeDefs[0];
|
let processedMethodsSignalsAndTypeDefs = splitMethodsSignals(foundSignalsAndMethods);
|
||||||
// let splitSignals = processedMethodsSignalsAndTypeDefs[1];
|
let splitMethods = processedMethodsSignalsAndTypeDefs[0];
|
||||||
// let splitTypeDefintions = processedMethodsSignalsAndTypeDefs[2];
|
let splitSignals = processedMethodsSignalsAndTypeDefs[1];
|
||||||
|
let splitTypeDefinitionIDS;
|
||||||
// let splitDescription = processedMethodsSignalsAndTypeDefs[3];
|
// let splitDescription = processedMethodsSignalsAndTypeDefs[3];
|
||||||
// let splitMethodIDS = extractIDs(splitMethods);
|
// console.log("getting split Methods")
|
||||||
// let splitSignalIDS = extractIDs(splitSignals);
|
let splitMethodIDS = extractIDs(splitMethods);
|
||||||
// let splitTypeDefinitionIDS = extractIDs(splitTypeDefintions);
|
// console.log("getting split Signals")
|
||||||
|
let splitSignalIDS = extractIDs(splitSignals);
|
||||||
|
if (foundTypeDefinitions){
|
||||||
|
// console.log("getting split typeDefs")
|
||||||
|
splitTypeDefinitionIDS = extractIDs(foundTypeDefinitions);
|
||||||
|
}
|
||||||
let arrayToPassToClassToc = [];
|
let arrayToPassToClassToc = [];
|
||||||
|
|
||||||
// if (splitDescription) {
|
// if (splitDescription) {
|
||||||
// currentContent = append(currentContent, html_reg_containerOverview, splitDescription);
|
// currentContent = append(currentContent, html_reg_containerOverview, splitDescription);
|
||||||
// }
|
// }
|
||||||
// if (splitMethods.length > 0) {
|
if (splitMethods.length > 0) {
|
||||||
// arrayToPassToClassToc.push({type: "Methods", array: splitMethodIDS});
|
arrayToPassToClassToc.push({type: "Methods", array: splitMethodIDS});
|
||||||
// // Add the Signals header to the Signals HTML
|
// Add the Signals header to the Signals HTML
|
||||||
// splitMethods.unshift(html_reg_findByMethod)
|
splitMethods.unshift(html_reg_findByMethod_replace)
|
||||||
// currentContent = append(currentContent, html_reg_findByArticleClose, splitMethods.join('\n'), true);
|
console.log("appending methods")
|
||||||
// }
|
currentContent = append(currentContent, html_reg_findByArticleClose, splitMethods.join('\n'), true);
|
||||||
// if (splitSignals.length > 0) {
|
}
|
||||||
// arrayToPassToClassToc.push({type: "Signals", array: splitSignalIDS});
|
if (splitSignals.length > 0) {
|
||||||
// // Add the Signals header to the Signals HTML
|
arrayToPassToClassToc.push({type: "Signals", array: splitSignalIDS});
|
||||||
// splitSignals.unshift(html_reg_signalTitle)
|
// Add the Signals header to the Signals HTML
|
||||||
// currentContent = append(currentContent, html_reg_findByArticleClose, splitSignals.join('\n'),true);
|
splitSignals.unshift(html_reg_signalTitle)
|
||||||
// }
|
console.log("appending signals")
|
||||||
// if (splitTypeDefintions.length > 0) {
|
currentContent = append(currentContent, html_reg_findByArticleClose, splitSignals.join('\n'),true);
|
||||||
// arrayToPassToClassToc.push({type: "Type Definitions", array: splitTypeDefinitionIDS});
|
}
|
||||||
// // Add the Signals header to the Signals HTML
|
if (foundTypeDefinitions && foundTypeDefinitions.length > 0) {
|
||||||
// splitTypeDefintions.unshift(html_reg_typeDefinitonsTitle)
|
arrayToPassToClassToc.push({type: "Type Definitions", array: splitTypeDefinitionIDS});
|
||||||
// currentContent = append(currentContent, html_reg_findByArticleClose, splitTypeDefintions.join('\n'), true);
|
// Add the Signals header to the Signals HTML
|
||||||
// }
|
foundTypeDefinitions.unshift(html_reg_typeDefinitonsTitle_replace)
|
||||||
|
console.log("appending typedefs")
|
||||||
|
currentContent = append(currentContent, html_reg_findByArticleClose, foundTypeDefinitions.join('\n'), true);
|
||||||
|
}
|
||||||
|
|
||||||
// let classTOC = makeClassTOC(arrayToPassToClassToc);
|
let classTOC = makeClassTOC(arrayToPassToClassToc);
|
||||||
// if (groupName === "Global"){
|
if (groupName === "Global"){
|
||||||
// currentContent = append(currentContent, html_reg_findByTitle, classTOC);
|
console.log("appending global toc")
|
||||||
// } else {
|
currentContent = append(currentContent, html_reg_findByTitle, classTOC);
|
||||||
// currentContent = append(currentContent, html_reg_firstTableClose, classTOC);
|
} else {
|
||||||
// }
|
console.log("appending normal toc")
|
||||||
|
currentContent = append(currentContent, html_reg_firstDivClose, classTOC);
|
||||||
|
}
|
||||||
|
|
||||||
// Final Pretty Content
|
// Final Pretty Content
|
||||||
currentContent = htmlclean(currentContent);
|
currentContent = htmlclean(currentContent);
|
||||||
|
@ -722,3 +726,26 @@
|
||||||
}
|
}
|
||||||
copyFolderRecursiveSync(dir_md, targetMDDirectory);
|
copyFolderRecursiveSync(dir_md, targetMDDirectory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// function splitTypeDefs(allItemToSplit){
|
||||||
|
// let typeDefArray = [];
|
||||||
|
// allItemToSplit.forEach( (content, index) => {
|
||||||
|
// firstLine = content.split("\n")[0];
|
||||||
|
// if (firstLine.indexOf("{Signal}") > -1){
|
||||||
|
// signalArray.push(content);
|
||||||
|
// } else if (firstLine.indexOf("span") > -1) {
|
||||||
|
// if (content.indexOf("Available in:") > -1){
|
||||||
|
// description = content;
|
||||||
|
// } else {
|
||||||
|
// methodArray.push(content);
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// if(firstLine.trim() !== ""){
|
||||||
|
// typeDefArray.push(content);
|
||||||
|
// } else {
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// })
|
||||||
|
// return [methodArray, signalArray, typeDefArray, description];
|
||||||
|
// }
|
Loading…
Reference in a new issue