Fixed HTML formatting bug

This commit is contained in:
Nanddeep Nachan 2020-08-13 09:47:50 +00:00
parent 40930889f8
commit 9827636b35
1 changed files with 12 additions and 4 deletions

View File

@ -32,13 +32,21 @@ export class SPService {
while (HTMLString.search(/<h[1-4]>/g) !== -1) { while (HTMLString.search(/<h[1-4]>/g) !== -1) {
/* The Header Text value */ /* The Header Text value */
let headingValue = HTMLString.substring(HTMLString.search(/<h[1-4]>/g) + 4, HTMLString.search(/<\/h[1-4]>/g)); // .replace(/<.+?>/gi, "") replaces in the headingValue any html tags like <strong> </strong>
console.log(headingValue); // .replace(/&.+;/gi, "") replaces in the headingValue any &****; tags like &nbsp;
let headingValue = HTMLString.substring(HTMLString.search(/<h[1-4]>/g) + 4, HTMLString.search(/<\/h[1-4]>/g))
.replace(/<.+?>/gi, "")
.replace(/\&.+\;/gi, "");
headingOrder = parseInt(HTMLString.charAt(HTMLString.search(/<h[1-4]>/g) + 2)); headingOrder = parseInt(HTMLString.charAt(HTMLString.search(/<h[1-4]>/g) + 2));
/* Check if same anchorUrl already exists */ /* Check if same anchorUrl already exists */
let urlExists = true; let urlExists = true;
let anchorUrl = `#${headingValue.replace(/ /g, '-')}`.toLowerCase(); // .replace(/'|?|\|/| |&/g, "-") replaces any blanks and special characters (list is for sure not complete) with "-"
// .replace(/--+/g, "-") replaces any additional - with only one -; e.g. --- get replaced with -, -- get replaced with - etc.
let anchorUrl = `#${headingValue
.replace(/\'|\?|\\|\/| |\&/g, "-")
.replace(/--+/g, "-")}`.toLowerCase();
let urlSuffix = 1; let urlSuffix = 1;
while (urlExists === true) { while (urlExists === true) {
urlExists = (allUrls.indexOf(anchorUrl) === -1) ? false : true; urlExists = (allUrls.indexOf(anchorUrl) === -1) ? false : true;
@ -62,7 +70,7 @@ export class SPService {
} else { } else {
if (headingOrder === 4) { if (headingOrder === 4) {
anchorLinks[headingIndex].links[subHeadingIndex].links.push({ name: headingValue, key: anchorUrl, url: anchorUrl, links: [], isExpanded: true }); anchorLinks[headingIndex].links[subHeadingIndex].links.push({ name: headingValue, key: anchorUrl, url: anchorUrl, links: [], isExpanded: true });
} else if (headingOrder === 3){ } else if (headingOrder === 3) {
anchorLinks[headingIndex].links.push({ name: headingValue, key: anchorUrl, url: anchorUrl, links: [], isExpanded: true }); anchorLinks[headingIndex].links.push({ name: headingValue, key: anchorUrl, url: anchorUrl, links: [], isExpanded: true });
subHeadingIndex++; subHeadingIndex++;
} }