@mikezimm/fps-library-v2
Version:
Library of reusable typescript/javascript functions, interfaces and constants
46 lines (44 loc) • 2.29 kB
JavaScript
/**
* CodeAnalizerComment: Updated 3 imports on 2024-09-22 14:49:52
* Update:: import { RegexHashNumber } to '@mikezimm/fps-core-v7/lib/logic/Regex/constants;'
* Update:: import { INullOrStringArray } to '@mikezimm/fps-core-v7/lib/logic/Strings/splitHash;'
* Update:: import { splitByHashNumbers } to '@mikezimm/fps-core-v7/lib/logic/Strings/splitHash;'
*/
/**
* CodeAnalizerComment: Updated 1 imports on 2024-09-21 23:07:24
* Update:: import { IRepoLinks } to '@mikezimm/fps-core-v7/lib/components/atoms/Links/IRepoLinks;'
*/
import * as React from 'react';
import { RegexHashNumber } from '@mikezimm/fps-core-v7/lib/logic/Regex/constants';
import { splitByHashNumbers } from '@mikezimm/fps-core-v7/lib/logic/Strings/splitHash';
// import { IRepoLinks } from '../Links_/CreateLinks';
// import { RegexHashNumber, INullOrStringArray } from '../Services/Regex_/constants_';
// import { splitByHashNumbers } from '../Services/Regex_/functions_';
export function replaceHashNumStringWithRepoIssues(testString, repoLinks) {
//Replace any # with link to issue
//First find all instances of # and digits
let matches = testString.match(RegexHashNumber); //Should get array of all values like #3, #43. etc
let createSpans = splitByHashNumbers(testString, matches); // Gets full array of strings including #3 and everything in between
let spans = [];
createSpans.map(thisSpan => {
if (matches !== null && matches.indexOf(thisSpan) > -1) { //Then replace text with link
// spans.push( `<<${thisSpan}>>` );
spans.push(React.createElement("a", { href: `${repoLinks.href}/issues/${thisSpan.substr(1)}`, target: "_blank" }, thisSpan));
}
else { //Just push text
spans.push(`${thisSpan}`);
}
});
return spans;
}
export function convertIssuesMarkdownStringToSpan(str, repoLinks) {
let StringOrLinkedSpan = null;
if (str && typeof str === 'string' && repoLinks !== null && str.indexOf('#') > -1) {
StringOrLinkedSpan = React.createElement("span", null, replaceHashNumStringWithRepoIssues(str, repoLinks));
}
else {
StringOrLinkedSpan = str;
}
return StringOrLinkedSpan;
}
//# sourceMappingURL=markdown.js.map