UNPKG

@mikezimm/npmfunctions

Version:
59 lines 2.91 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.convertIssuesMarkdownStringToSpan = exports.replaceHashNumStringWithRepoIssues = void 0; var React = __importStar(require("react")); var constants_1 = require("../Services/Regex/constants"); var functions_1 = require("../Services/Regex/functions"); function replaceHashNumStringWithRepoIssues(testString, repoLinks) { //Replace any # with link to issue //First find all instances of # and digits var matches = testString.match(constants_1.RegexHashNumber); //Should get array of all values like #3, #43. etc var createSpans = (0, functions_1.splitByHashNumbers)(testString, matches); // Gets full array of strings including #3 and everything in between var spans = []; createSpans.map(function (thisSpan) { if (matches !== null && matches.indexOf(thisSpan) > -1) { //Then replace text with link // spans.push( `<<${thisSpan}>>` ); spans.push(React.createElement("a", { href: "".concat(repoLinks.href, "/issues/").concat(thisSpan.substr(1)), target: "_blank" }, thisSpan)); } else { //Just push text spans.push("".concat(thisSpan)); } }); return spans; } exports.replaceHashNumStringWithRepoIssues = replaceHashNumStringWithRepoIssues; function convertIssuesMarkdownStringToSpan(str, repoLinks) { var 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; } exports.convertIssuesMarkdownStringToSpan = convertIssuesMarkdownStringToSpan; //# sourceMappingURL=Markdown.js.map