Skip to content

Commit

Permalink
Merge pull request #257 from ONDC-Official/feat/change-log-ui
Browse files Browse the repository at this point in the history
Made changed to render md file in ui
  • Loading branch information
92shreyansh authored May 16, 2024
2 parents 85715c9 + 1fc60b3 commit c210df0
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions ui/change-log.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,40 @@ function renderChangeLogDropDown(branchname, filteredData) {
setsDropDown.innerHTML = "";
filteredData?.forEach(function (item) {
var option = document.createElement("option");
const fileName = item?.split(".docx")[0];
const fileName = item?.split(".md")[0];
option.text = fileName;
setsDropDown.add(option);
});
renderDocument(branchname, filteredData[0]?.split(".docx")[0]);
}

function renderDocument(branchName, file) {
console.log("Calliung render");
const documentDispalyArea = document.getElementById("change-log-container");
// documentDispalyArea.innerHTML = "";
documentDispalyArea.innerHTML = `
<iframe style="width: 100%; height: 500px;" id="something" src="https://docs.google.com/gview?url=https://github.com/ONDC-Official/ONDC-FIS-Specifications/raw/${branchName}/api/components/docs/changeLog/${file}.docx&embedded=true"></iframe>
`;
renderMDFile(branchname, filteredData[0]?.split(".md")[0]);
}

function updateChangeLog() {
var example_set = document.getElementById("change-log-dropdown");
const selectedOption = document.getElementById("contract-dropdown")?.value;
renderDocument(selectedOption, example_set.value);
renderMDFile(selectedOption, example_set.value);
}

function renderMDFile(branchName, file) {
const url = `https://github.com/ONDC-Official/ONDC-FIS-Specifications/raw/${branchName}/api/components/docs/changeLog/${file}`;
console.log("url", url);
fetch(url)
.then((response) => {
console.log("response", response);
response.text();
})
fetch(
`https://raw.githubusercontent.com/ONDC-Official/ONDC-FIS-Specifications/${branchName}/api/components/docs/changeLog/${file}.md`
)
.then((response) => response.text())
.then(async (text) => {
console.log("text:::", text);
})
.catch((e) => {
console.log("eerror", e);
const result = await extractTextBetweenBackticks(text);
//if mermaid diagram exist
let createMermaid;
if (result?.length) {
//const modifiedText = result[0].replace(/mermaid/g, '');
createMermaid = await mermaid.render(`main-summary1`, result[1]);
}
const removedMermaidData = text.replace(/```mermaid[\s\S]+?```/g, "");
const textWithBranchName = removedMermaidData.replace(
/branchName/g,
branchName
);
const textData = marked.parse(textWithBranchName);

document.getElementById("change-log-container").innerHTML =
textData + (createMermaid?.svg ? createMermaid?.svg : "");
});
}

0 comments on commit c210df0

Please sign in to comment.