@drodil/backstage-plugin-qeta-common 3.1.1 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs.js CHANGED
@@ -26,6 +26,7 @@ exports.qetaReadCommentPermission = permissions.qetaReadCommentPermission;
26
26
  exports.qetaReadPostPermission = permissions.qetaReadPostPermission;
27
27
  exports.TAGS_REGEX = tags.TAGS_REGEX;
28
28
  exports.filterTags = tags.filterTags;
29
+ exports.findUserMentions = utils.findUserMentions;
29
30
  exports.removeMarkdownFormatting = utils.removeMarkdownFormatting;
30
31
  exports.truncate = utils.truncate;
31
32
  exports.QetaClient = QetaClient.QetaClient;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/dist/index.d.ts CHANGED
@@ -271,6 +271,7 @@ declare const TAGS_REGEX: RegExp;
271
271
  declare const filterTags: (input?: null | string | string[]) => string[] | undefined;
272
272
 
273
273
  declare const truncate: (str: string, n: number) => string;
274
+ declare const findUserMentions: (text: string) => string[];
274
275
  declare const removeMarkdownFormatting: (text: string) => string;
275
276
 
276
277
  interface PostsQuery {
@@ -446,4 +447,4 @@ declare class QetaClient implements QetaApi {
446
447
  private getQueryParameters;
447
448
  }
448
449
 
449
- export { ANSWER_RESOURCE_TYPE, type Answer, type AnswerFilter, type AnswerRequest, type AnswerResponse, type AnswerResponseBody, type AnswersQuery, type AnswersResponse, type AnswersResponseBody, type Article, type Attachment, type AttachmentResponseBody, COMMENT_RESOURCE_TYPE, type Collection, type CollectionEntity, type CollectionRequest, type CollectionResponse, type CollectionResponseBody, type CollectionsQuery, type CollectionsResponse, type CollectionsResponseBody, type Comment, type CommentFilter, type EntityResponse, type GlobalStat, type ImpactResponse, POST_RESOURCE_TYPE, type Post, type PostAnswerEntity, type PostFilter, type PostRequest, type PostResponse, type PostResponseBody, type PostType, type PostsQuery, type PostsResponse, type PostsResponseBody, type QetaAnswerStatsSignal, type QetaApi, QetaClient, type QetaDocument, type QetaEntity, type QetaPostsStatsSignal, type QetaSignal, type Question, type RequestOptions, type Stat, type Statistic, type StatisticResponse, type StatisticsOptions, type StatisticsRequestParameters, type StatisticsResponse, TAGS_REGEX, type TagResponse, type UserEntitiesResponse, type UserResponse, type UserStat, type UserTagsResponse, type Vote, filterTags, isQetaPermission, qetaCreateAnswerPermission, qetaCreateCommentPermission, qetaCreatePostPermission, qetaDeleteAnswerPermission, qetaDeleteCommentPermission, qetaDeletePostPermission, qetaEditAnswerPermission, qetaEditCommentPermission, qetaEditPostPermission, qetaPermissions, qetaReadAnswerPermission, qetaReadCommentPermission, qetaReadPostPermission, removeMarkdownFormatting, truncate };
450
+ export { ANSWER_RESOURCE_TYPE, type Answer, type AnswerFilter, type AnswerRequest, type AnswerResponse, type AnswerResponseBody, type AnswersQuery, type AnswersResponse, type AnswersResponseBody, type Article, type Attachment, type AttachmentResponseBody, COMMENT_RESOURCE_TYPE, type Collection, type CollectionEntity, type CollectionRequest, type CollectionResponse, type CollectionResponseBody, type CollectionsQuery, type CollectionsResponse, type CollectionsResponseBody, type Comment, type CommentFilter, type EntityResponse, type GlobalStat, type ImpactResponse, POST_RESOURCE_TYPE, type Post, type PostAnswerEntity, type PostFilter, type PostRequest, type PostResponse, type PostResponseBody, type PostType, type PostsQuery, type PostsResponse, type PostsResponseBody, type QetaAnswerStatsSignal, type QetaApi, QetaClient, type QetaDocument, type QetaEntity, type QetaPostsStatsSignal, type QetaSignal, type Question, type RequestOptions, type Stat, type Statistic, type StatisticResponse, type StatisticsOptions, type StatisticsRequestParameters, type StatisticsResponse, TAGS_REGEX, type TagResponse, type UserEntitiesResponse, type UserResponse, type UserStat, type UserTagsResponse, type Vote, filterTags, findUserMentions, isQetaPermission, qetaCreateAnswerPermission, qetaCreateCommentPermission, qetaCreatePostPermission, qetaDeleteAnswerPermission, qetaDeleteCommentPermission, qetaDeletePostPermission, qetaEditAnswerPermission, qetaEditCommentPermission, qetaEditPostPermission, qetaPermissions, qetaReadAnswerPermission, qetaReadCommentPermission, qetaReadPostPermission, removeMarkdownFormatting, truncate };
package/dist/index.esm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export { ANSWER_RESOURCE_TYPE, COMMENT_RESOURCE_TYPE, POST_RESOURCE_TYPE, isQetaPermission, qetaCreateAnswerPermission, qetaCreateCommentPermission, qetaCreatePostPermission, qetaDeleteAnswerPermission, qetaDeleteCommentPermission, qetaDeletePostPermission, qetaEditAnswerPermission, qetaEditCommentPermission, qetaEditPostPermission, qetaPermissions, qetaReadAnswerPermission, qetaReadCommentPermission, qetaReadPostPermission } from './permissions.esm.js';
2
2
  export { TAGS_REGEX, filterTags } from './tags.esm.js';
3
- export { removeMarkdownFormatting, truncate } from './utils.esm.js';
3
+ export { findUserMentions, removeMarkdownFormatting, truncate } from './utils.esm.js';
4
4
  export { QetaClient } from './api/QetaClient.esm.js';
5
5
  //# sourceMappingURL=index.esm.js.map
package/dist/utils.cjs.js CHANGED
@@ -1,8 +1,28 @@
1
1
  'use strict';
2
2
 
3
+ var catalogModel = require('@backstage/catalog-model');
4
+ var lodash = require('lodash');
5
+
3
6
  const truncate = (str, n) => {
4
7
  return str.length > n ? `${str.slice(0, n - 1)}...` : str;
5
8
  };
9
+ const findUserMentions = (text) => {
10
+ const mentions = text.match(/@(\S+)/g);
11
+ const ret = mentions ? Array.from(new Set(mentions)) : [];
12
+ return lodash.compact(
13
+ ret.map((mention) => {
14
+ try {
15
+ const parsed = catalogModel.parseEntityRef(mention.replace(/^@+/, ""));
16
+ if (parsed.kind.toLocaleLowerCase("en-US") !== "user") {
17
+ return void 0;
18
+ }
19
+ return `@${catalogModel.stringifyEntityRef(parsed)}`;
20
+ } catch (e) {
21
+ return void 0;
22
+ }
23
+ })
24
+ );
25
+ };
6
26
  const removeMarkdownFormatting = (text) => {
7
27
  let fixed = text.replace(/<[^>]*>/g, "");
8
28
  fixed = fixed.replace(/```[\s\S]*?```/g, (match) => {
@@ -14,6 +34,7 @@ const removeMarkdownFormatting = (text) => {
14
34
  return fixed;
15
35
  };
16
36
 
37
+ exports.findUserMentions = findUserMentions;
17
38
  exports.removeMarkdownFormatting = removeMarkdownFormatting;
18
39
  exports.truncate = truncate;
19
40
  //# sourceMappingURL=utils.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.cjs.js","sources":["../src/utils.ts"],"sourcesContent":["export const truncate = (str: string, n: number): string => {\n return str.length > n ? `${str.slice(0, n - 1)}...` : str;\n};\n\n// Covers many common but not all cases of markdown formatting\nexport const removeMarkdownFormatting = (text: string): string => {\n // Remove HTML tags\n let fixed = text.replace(/<[^>]*>/g, '');\n\n // Handle code blocks defined with a language\n fixed = fixed.replace(/```[\\s\\S]*?```/g, match => {\n return match.replace(/(^```[a-z]*\\n)|(```$)/g, '').trim();\n });\n\n // Handle inline code blocks and code blocks defined using ```\n fixed = fixed.replace(/`{1,2}([^`]*)`{1,2}/g, '$1');\n\n // Remove other markdown formatting\n fixed = fixed\n .replace(/(?:\\*\\*|__)([^\\n*]+)(?:\\*\\*|__)/g, '$1') // Bold\n .replace(/(?:\\*|_)([^\\n*]+)(?:\\*|_)/g, '$1') // Italic\n .replace(/(?:~~)([^~]+)(?:~~)/g, '$1') // Strikethrough\n .replace(/^[>\\t]{0,3}>+\\s?/gm, '') // Blockquotes\n .replace(/\\[\\^.+?\\](: .*?$)?/g, '') // Footnotes\n .replace(/^([ \\t]*)([*\\-+]|\\d+\\.)\\s+/gm, '') // Lists\n .replace(/!\\[([^\\]]*)\\]\\([^)]*\\)/g, '$1') // Images\n .replace(/\\[([^\\]]*)\\]\\([^)]*\\)/g, '$1') // Links\n .replace(/^#{1,6}[ \\t]+/gm, '') // Headers\n .replace(/^[=-]{2,}\\s*$/g, '') // Setex style headers\n .replace(/(?:\\r\\n|\\r|\\n)/g, ' ') // Newlines\n .replace(/(^\\s+|\\s+$)/g, ''); // Trimming leading and trailing spaces\n\n // Remove remaining HTML tags\n fixed = fixed.replace(/<[^>]*>/g, '');\n\n return fixed;\n};\n"],"names":[],"mappings":";;AAAa,MAAA,QAAA,GAAW,CAAC,GAAA,EAAa,CAAsB,KAAA;AAC1D,EAAO,OAAA,GAAA,CAAI,MAAS,GAAA,CAAA,GAAI,CAAG,EAAA,GAAA,CAAI,MAAM,CAAG,EAAA,CAAA,GAAI,CAAC,CAAC,CAAQ,GAAA,CAAA,GAAA,GAAA,CAAA;AACxD,EAAA;AAGa,MAAA,wBAAA,GAA2B,CAAC,IAAyB,KAAA;AAEhE,EAAA,IAAI,KAAQ,GAAA,IAAA,CAAK,OAAQ,CAAA,UAAA,EAAY,EAAE,CAAA,CAAA;AAGvC,EAAQ,KAAA,GAAA,KAAA,CAAM,OAAQ,CAAA,iBAAA,EAAmB,CAAS,KAAA,KAAA;AAChD,IAAA,OAAO,KAAM,CAAA,OAAA,CAAQ,wBAA0B,EAAA,EAAE,EAAE,IAAK,EAAA,CAAA;AAAA,GACzD,CAAA,CAAA;AAGD,EAAQ,KAAA,GAAA,KAAA,CAAM,OAAQ,CAAA,sBAAA,EAAwB,IAAI,CAAA,CAAA;AAGlD,EAAQ,KAAA,GAAA,KAAA,CACL,QAAQ,kCAAoC,EAAA,IAAI,EAChD,OAAQ,CAAA,4BAAA,EAA8B,IAAI,CAC1C,CAAA,OAAA,CAAQ,wBAAwB,IAAI,CAAA,CACpC,QAAQ,oBAAsB,EAAA,EAAE,EAChC,OAAQ,CAAA,qBAAA,EAAuB,EAAE,CAAA,CACjC,OAAQ,CAAA,8BAAA,EAAgC,EAAE,CAC1C,CAAA,OAAA,CAAQ,2BAA2B,IAAI,CAAA,CACvC,QAAQ,wBAA0B,EAAA,IAAI,CACtC,CAAA,OAAA,CAAQ,iBAAmB,EAAA,EAAE,EAC7B,OAAQ,CAAA,gBAAA,EAAkB,EAAE,CAC5B,CAAA,OAAA,CAAQ,mBAAmB,GAAG,CAAA,CAC9B,OAAQ,CAAA,cAAA,EAAgB,EAAE,CAAA,CAAA;AAG7B,EAAQ,KAAA,GAAA,KAAA,CAAM,OAAQ,CAAA,UAAA,EAAY,EAAE,CAAA,CAAA;AAEpC,EAAO,OAAA,KAAA,CAAA;AACT;;;;;"}
1
+ {"version":3,"file":"utils.cjs.js","sources":["../src/utils.ts"],"sourcesContent":["import { parseEntityRef, stringifyEntityRef } from '@backstage/catalog-model';\nimport { compact } from 'lodash';\n\nexport const truncate = (str: string, n: number): string => {\n return str.length > n ? `${str.slice(0, n - 1)}...` : str;\n};\n\nexport const findUserMentions = (text: string): string[] => {\n const mentions = text.match(/@(\\S+)/g);\n const ret = mentions ? Array.from(new Set(mentions)) : [];\n return compact(\n ret.map(mention => {\n try {\n const parsed = parseEntityRef(mention.replace(/^@+/, ''));\n if (parsed.kind.toLocaleLowerCase('en-US') !== 'user') {\n return undefined;\n }\n return `@${stringifyEntityRef(parsed)}`;\n } catch (e) {\n return undefined;\n }\n }),\n );\n};\n\n// Covers many common but not all cases of markdown formatting\nexport const removeMarkdownFormatting = (text: string): string => {\n // Remove HTML tags\n let fixed = text.replace(/<[^>]*>/g, '');\n\n // Handle code blocks defined with a language\n fixed = fixed.replace(/```[\\s\\S]*?```/g, match => {\n return match.replace(/(^```[a-z]*\\n)|(```$)/g, '').trim();\n });\n\n // Handle inline code blocks and code blocks defined using ```\n fixed = fixed.replace(/`{1,2}([^`]*)`{1,2}/g, '$1');\n\n // Remove other markdown formatting\n fixed = fixed\n .replace(/(?:\\*\\*|__)([^\\n*]+)(?:\\*\\*|__)/g, '$1') // Bold\n .replace(/(?:\\*|_)([^\\n*]+)(?:\\*|_)/g, '$1') // Italic\n .replace(/(?:~~)([^~]+)(?:~~)/g, '$1') // Strikethrough\n .replace(/^[>\\t]{0,3}>+\\s?/gm, '') // Blockquotes\n .replace(/\\[\\^.+?\\](: .*?$)?/g, '') // Footnotes\n .replace(/^([ \\t]*)([*\\-+]|\\d+\\.)\\s+/gm, '') // Lists\n .replace(/!\\[([^\\]]*)\\]\\([^)]*\\)/g, '$1') // Images\n .replace(/\\[([^\\]]*)\\]\\([^)]*\\)/g, '$1') // Links\n .replace(/^#{1,6}[ \\t]+/gm, '') // Headers\n .replace(/^[=-]{2,}\\s*$/g, '') // Setex style headers\n .replace(/(?:\\r\\n|\\r|\\n)/g, ' ') // Newlines\n .replace(/(^\\s+|\\s+$)/g, ''); // Trimming leading and trailing spaces\n\n // Remove remaining HTML tags\n fixed = fixed.replace(/<[^>]*>/g, '');\n\n return fixed;\n};\n"],"names":["compact","parseEntityRef","stringifyEntityRef"],"mappings":";;;;;AAGa,MAAA,QAAA,GAAW,CAAC,GAAA,EAAa,CAAsB,KAAA;AAC1D,EAAO,OAAA,GAAA,CAAI,MAAS,GAAA,CAAA,GAAI,CAAG,EAAA,GAAA,CAAI,MAAM,CAAG,EAAA,CAAA,GAAI,CAAC,CAAC,CAAQ,GAAA,CAAA,GAAA,GAAA,CAAA;AACxD,EAAA;AAEa,MAAA,gBAAA,GAAmB,CAAC,IAA2B,KAAA;AAC1D,EAAM,MAAA,QAAA,GAAW,IAAK,CAAA,KAAA,CAAM,SAAS,CAAA,CAAA;AACrC,EAAM,MAAA,GAAA,GAAM,WAAW,KAAM,CAAA,IAAA,CAAK,IAAI,GAAI,CAAA,QAAQ,CAAC,CAAA,GAAI,EAAC,CAAA;AACxD,EAAO,OAAAA,cAAA;AAAA,IACL,GAAA,CAAI,IAAI,CAAW,OAAA,KAAA;AACjB,MAAI,IAAA;AACF,QAAA,MAAM,SAASC,2BAAe,CAAA,OAAA,CAAQ,OAAQ,CAAA,KAAA,EAAO,EAAE,CAAC,CAAA,CAAA;AACxD,QAAA,IAAI,MAAO,CAAA,IAAA,CAAK,iBAAkB,CAAA,OAAO,MAAM,MAAQ,EAAA;AACrD,UAAO,OAAA,KAAA,C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AAE,CAAA,CAAA;AAEpC,EAAO,OAAA,KAAA,CAAA;AACT;;;;;;"}
package/dist/utils.esm.js CHANGED
@@ -1,6 +1,26 @@
1
+ import { parseEntityRef, stringifyEntityRef } from '@backstage/catalog-model';
2
+ import { compact } from 'lodash';
3
+
1
4
  const truncate = (str, n) => {
2
5
  return str.length > n ? `${str.slice(0, n - 1)}...` : str;
3
6
  };
7
+ const findUserMentions = (text) => {
8
+ const mentions = text.match(/@(\S+)/g);
9
+ const ret = mentions ? Array.from(new Set(mentions)) : [];
10
+ return compact(
11
+ ret.map((mention) => {
12
+ try {
13
+ const parsed = parseEntityRef(mention.replace(/^@+/, ""));
14
+ if (parsed.kind.toLocaleLowerCase("en-US") !== "user") {
15
+ return void 0;
16
+ }
17
+ return `@${stringifyEntityRef(parsed)}`;
18
+ } catch (e) {
19
+ return void 0;
20
+ }
21
+ })
22
+ );
23
+ };
4
24
  const removeMarkdownFormatting = (text) => {
5
25
  let fixed = text.replace(/<[^>]*>/g, "");
6
26
  fixed = fixed.replace(/```[\s\S]*?```/g, (match) => {
@@ -12,5 +32,5 @@ const removeMarkdownFormatting = (text) => {
12
32
  return fixed;
13
33
  };
14
34
 
15
- export { removeMarkdownFormatting, truncate };
35
+ export { findUserMentions, removeMarkdownFormatting, truncate };
16
36
  //# sourceMappingURL=utils.esm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.esm.js","sources":["../src/utils.ts"],"sourcesContent":["export const truncate = (str: string, n: number): string => {\n return str.length > n ? `${str.slice(0, n - 1)}...` : str;\n};\n\n// Covers many common but not all cases of markdown formatting\nexport const removeMarkdownFormatting = (text: string): string => {\n // Remove HTML tags\n let fixed = text.replace(/<[^>]*>/g, '');\n\n // Handle code blocks defined with a language\n fixed = fixed.replace(/```[\\s\\S]*?```/g, match => {\n return match.replace(/(^```[a-z]*\\n)|(```$)/g, '').trim();\n });\n\n // Handle inline code blocks and code blocks defined using ```\n fixed = fixed.replace(/`{1,2}([^`]*)`{1,2}/g, '$1');\n\n // Remove other markdown formatting\n fixed = fixed\n .replace(/(?:\\*\\*|__)([^\\n*]+)(?:\\*\\*|__)/g, '$1') // Bold\n .replace(/(?:\\*|_)([^\\n*]+)(?:\\*|_)/g, '$1') // Italic\n .replace(/(?:~~)([^~]+)(?:~~)/g, '$1') // Strikethrough\n .replace(/^[>\\t]{0,3}>+\\s?/gm, '') // Blockquotes\n .replace(/\\[\\^.+?\\](: .*?$)?/g, '') // Footnotes\n .replace(/^([ \\t]*)([*\\-+]|\\d+\\.)\\s+/gm, '') // Lists\n .replace(/!\\[([^\\]]*)\\]\\([^)]*\\)/g, '$1') // Images\n .replace(/\\[([^\\]]*)\\]\\([^)]*\\)/g, '$1') // Links\n .replace(/^#{1,6}[ \\t]+/gm, '') // Headers\n .replace(/^[=-]{2,}\\s*$/g, '') // Setex style headers\n .replace(/(?:\\r\\n|\\r|\\n)/g, ' ') // Newlines\n .replace(/(^\\s+|\\s+$)/g, ''); // Trimming leading and trailing spaces\n\n // Remove remaining HTML tags\n fixed = fixed.replace(/<[^>]*>/g, '');\n\n return fixed;\n};\n"],"names":[],"mappings":"AAAa,MAAA,QAAA,GAAW,CAAC,GAAA,EAAa,CAAsB,KAAA;AAC1D,EAAO,OAAA,GAAA,CAAI,MAAS,GAAA,CAAA,GAAI,CAAG,EAAA,GAAA,CAAI,MAAM,CAAG,EAAA,CAAA,GAAI,CAAC,CAAC,CAAQ,GAAA,CAAA,GAAA,GAAA,CAAA;AACxD,EAAA;AAGa,MAAA,wBAAA,GAA2B,CAAC,IAAyB,KAAA;AAEhE,EAAA,IAAI,KAAQ,GAAA,IAAA,CAAK,OAAQ,CAAA,UAAA,EAAY,EAAE,CAAA,CAAA;AAGvC,EAAQ,KAAA,GAAA,KAAA,CAAM,OAAQ,CAAA,iBAAA,EAAmB,CAAS,KAAA,KAAA;AAChD,IAAA,OAAO,KAAM,CAAA,OAAA,CAAQ,wBAA0B,EAAA,EAAE,EAAE,IAAK,EAAA,CAAA;AAAA,GACzD,CAAA,CAAA;AAGD,EAAQ,KAAA,GAAA,KAAA,CAAM,OAAQ,CAAA,sBAAA,EAAwB,IAAI,CAAA,CAAA;AAGlD,EAAQ,KAAA,GAAA,KAAA,CACL,QAAQ,kCAAoC,EAAA,IAAI,EAChD,OAAQ,CAAA,4BAAA,EAA8B,IAAI,CAC1C,CAAA,OAAA,CAAQ,wBAAwB,IAAI,CAAA,CACpC,QAAQ,oBAAsB,EAAA,EAAE,EAChC,OAAQ,CAAA,qBAAA,EAAuB,EAAE,CAAA,CACjC,OAAQ,CAAA,8BAAA,EAAgC,EAAE,CAC1C,CAAA,OAAA,CAAQ,2BAA2B,IAAI,CAAA,CACvC,QAAQ,wBAA0B,EAAA,IAAI,CACtC,CAAA,OAAA,CAAQ,iBAAmB,EAAA,EAAE,EAC7B,OAAQ,CAAA,gBAAA,EAAkB,EAAE,CAC5B,CAAA,OAAA,CAAQ,mBAAmB,GAAG,CAAA,CAC9B,OAAQ,CAAA,cAAA,EAAgB,EAAE,CAAA,CAAA;AAG7B,EAAQ,KAAA,GAAA,KAAA,CAAM,OAAQ,CAAA,UAAA,EAAY,EAAE,CAAA,CAAA;AAEpC,EAAO,OAAA,KAAA,CAAA;AACT;;;;"}
1
+ {"version":3,"file":"utils.esm.js","sources":["../src/utils.ts"],"sourcesContent":["import { parseEntityRef, stringifyEntityRef } from '@backstage/catalog-model';\nimport { compact } from 'lodash';\n\nexport const truncate = (str: string, n: number): string => {\n return str.length > n ? `${str.slice(0, n - 1)}...` : str;\n};\n\nexport const findUserMentions = (text: string): string[] => {\n const mentions = text.match(/@(\\S+)/g);\n const ret = mentions ? Array.from(new Set(mentions)) : [];\n return compact(\n ret.map(mention => {\n try {\n const parsed = parseEntityRef(mention.replace(/^@+/, ''));\n if (parsed.kind.toLocaleLowerCase('en-US') !== 'user') {\n return undefined;\n }\n return `@${stringifyEntityRef(parsed)}`;\n } catch (e) {\n return undefined;\n }\n }),\n );\n};\n\n// Covers many common but not all cases of markdown formatting\nexport const removeMarkdownFormatting = (text: string): string => {\n // Remove HTML tags\n let fixed = text.replace(/<[^>]*>/g, '');\n\n // Handle code blocks defined with a language\n fixed = fixed.replace(/```[\\s\\S]*?```/g, match => {\n return match.replace(/(^```[a-z]*\\n)|(```$)/g, '').trim();\n });\n\n // Handle inline code blocks and code blocks defined using ```\n fixed = fixed.replace(/`{1,2}([^`]*)`{1,2}/g, '$1');\n\n // Remove other markdown formatting\n fixed = fixed\n .replace(/(?:\\*\\*|__)([^\\n*]+)(?:\\*\\*|__)/g, '$1') // Bold\n .replace(/(?:\\*|_)([^\\n*]+)(?:\\*|_)/g, '$1') // Italic\n .replace(/(?:~~)([^~]+)(?:~~)/g, '$1') // Strikethrough\n .replace(/^[>\\t]{0,3}>+\\s?/gm, '') // Blockquotes\n .replace(/\\[\\^.+?\\](: .*?$)?/g, '') // Footnotes\n .replace(/^([ \\t]*)([*\\-+]|\\d+\\.)\\s+/gm, '') // Lists\n .replace(/!\\[([^\\]]*)\\]\\([^)]*\\)/g, '$1') // Images\n .replace(/\\[([^\\]]*)\\]\\([^)]*\\)/g, '$1') // Links\n .replace(/^#{1,6}[ \\t]+/gm, '') // Headers\n .replace(/^[=-]{2,}\\s*$/g, '') // Setex style headers\n .replace(/(?:\\r\\n|\\r|\\n)/g, ' ') // Newlines\n .replace(/(^\\s+|\\s+$)/g, ''); // Trimming leading and trailing spaces\n\n // Remove remaining HTML tags\n fixed = fixed.replace(/<[^>]*>/g, '');\n\n return fixed;\n};\n"],"names":[],"mappings":";;;AAGa,MAAA,QAAA,GAAW,CAAC,GAAA,EAAa,CAAsB,KAAA;AAC1D,EAAO,OAAA,GAAA,CAAI,MAAS,GAAA,CAAA,GAAI,CAAG,EAAA,GAAA,CAAI,MAAM,CAAG,EAAA,CAAA,GAAI,CAAC,CAAC,CAAQ,GAAA,CAAA,GAAA,GAAA,CAAA;AACxD,EAAA;AAEa,MAAA,gBAAA,GAAmB,CAAC,IAA2B,KAAA;AAC1D,EAA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