@drodil/backstage-plugin-qeta-common 3.15.3 → 3.16.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 +1 -0
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.esm.js +1 -1
- package/dist/tags.cjs.js +1 -1
- package/dist/tags.cjs.js.map +1 -1
- package/dist/tags.esm.js +1 -1
- package/dist/tags.esm.js.map +1 -1
- package/dist/utils.cjs.js +11 -0
- package/dist/utils.cjs.js.map +1 -1
- package/dist/utils.esm.js +11 -1
- package/dist/utils.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -27,6 +27,7 @@ exports.qetaReadPostPermission = permissions.qetaReadPostPermission;
|
|
|
27
27
|
exports.TAGS_REGEX = tags.TAGS_REGEX;
|
|
28
28
|
exports.filterTags = tags.filterTags;
|
|
29
29
|
exports.isValidTag = tags.isValidTag;
|
|
30
|
+
exports.findTagMentions = utils.findTagMentions;
|
|
30
31
|
exports.findUserMentions = utils.findUserMentions;
|
|
31
32
|
exports.removeMarkdownFormatting = utils.removeMarkdownFormatting;
|
|
32
33
|
exports.truncate = utils.truncate;
|
package/dist/index.cjs.js.map
CHANGED
|
@@ -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
|
@@ -595,6 +595,7 @@ declare const filterTags: (input?: null | string | string[]) => string[];
|
|
|
595
595
|
|
|
596
596
|
declare const truncate: (str: string, n: number) => string;
|
|
597
597
|
declare const findUserMentions: (text: string) => string[];
|
|
598
|
+
declare const findTagMentions: (text: string) => string[];
|
|
598
599
|
declare const removeMarkdownFormatting: (text: string) => string;
|
|
599
600
|
|
|
600
|
-
export { type AIQuery, type AIResponse, type AIStatusResponse, 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 EntitiesQuery, type EntitiesResponse, type EntityResponse, type GlobalStat, type ImpactResponse, type NewArticleSuggestion, type NewQuestionSuggestion, type NoCorrectAnswerSuggestion, POST_RESOURCE_TYPE, type PaginatedQuery, 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 QetaCollectionDocument, type QetaEntity, type QetaPostDocument, type QetaPostsStatsSignal, type QetaSignal, type Question, type RequestOptions, type Stat, type Statistic, type StatisticResponse, type StatisticsOptions, type StatisticsRequestParameters, type StatisticsResponse, type Suggestion, type SuggestionType, type SuggestionsQuery, type SuggestionsResponse, TAGS_REGEX, type TagResponse, type TagsQuery, type TagsResponse, type Template, type TemplateRequest, type TemplateResponse, type TemplatesResponse, type UserCollectionsResponse, type UserEntitiesResponse, type UserResponse, type UserStat, type UserTagsResponse, type UserUsersResponse, type UsersQuery, type UsersResponse, type Vote, filterTags, findUserMentions, isQetaPermission, isValidTag, qetaCreateAnswerPermission, qetaCreateCommentPermission, qetaCreatePostPermission, qetaDeleteAnswerPermission, qetaDeleteCommentPermission, qetaDeletePostPermission, qetaEditAnswerPermission, qetaEditCommentPermission, qetaEditPostPermission, qetaPermissions, qetaReadAnswerPermission, qetaReadCommentPermission, qetaReadPostPermission, removeMarkdownFormatting, truncate };
|
|
601
|
+
export { type AIQuery, type AIResponse, type AIStatusResponse, 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 EntitiesQuery, type EntitiesResponse, type EntityResponse, type GlobalStat, type ImpactResponse, type NewArticleSuggestion, type NewQuestionSuggestion, type NoCorrectAnswerSuggestion, POST_RESOURCE_TYPE, type PaginatedQuery, 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 QetaCollectionDocument, type QetaEntity, type QetaPostDocument, type QetaPostsStatsSignal, type QetaSignal, type Question, type RequestOptions, type Stat, type Statistic, type StatisticResponse, type StatisticsOptions, type StatisticsRequestParameters, type StatisticsResponse, type Suggestion, type SuggestionType, type SuggestionsQuery, type SuggestionsResponse, TAGS_REGEX, type TagResponse, type TagsQuery, type TagsResponse, type Template, type TemplateRequest, type TemplateResponse, type TemplatesResponse, type UserCollectionsResponse, type UserEntitiesResponse, type UserResponse, type UserStat, type UserTagsResponse, type UserUsersResponse, type UsersQuery, type UsersResponse, type Vote, filterTags, findTagMentions, findUserMentions, isQetaPermission, isValidTag, 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, isValidTag } from './tags.esm.js';
|
|
3
|
-
export { findUserMentions, removeMarkdownFormatting, truncate } from './utils.esm.js';
|
|
3
|
+
export { findTagMentions, 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/tags.cjs.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const TAGS_REGEX = new RegExp("^[a-z0-9
|
|
3
|
+
const TAGS_REGEX = new RegExp("^[a-z0-9+]+(([-_])[a-z0-9+]+)*$");
|
|
4
4
|
const isValidTag = (tag) => {
|
|
5
5
|
const trimmed = tag.trim();
|
|
6
6
|
return trimmed.length > 0 && trimmed.length < 255 && TAGS_REGEX.test(trimmed);
|
package/dist/tags.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tags.cjs.js","sources":["../src/tags.ts"],"sourcesContent":["export const TAGS_REGEX = new RegExp('^[a-z0-9
|
|
1
|
+
{"version":3,"file":"tags.cjs.js","sources":["../src/tags.ts"],"sourcesContent":["export const TAGS_REGEX = new RegExp('^[a-z0-9+]+(([-_])[a-z0-9+]+)*$');\n\nexport const isValidTag = (tag: string) => {\n const trimmed = tag.trim();\n return trimmed.length > 0 && trimmed.length < 255 && TAGS_REGEX.test(trimmed);\n};\n\nexport const filterTags = (input?: null | string | string[]) => {\n if (!input) {\n return [];\n }\n return (Array.isArray(input) ? input : input.split(',')).filter(v =>\n isValidTag(v),\n );\n};\n"],"names":[],"mappings":";;AAAa,MAAA,UAAA,GAAa,IAAI,MAAA,CAAO,iCAAiC;AAEzD,MAAA,UAAA,GAAa,CAAC,GAAgB,KAAA;AACzC,EAAM,MAAA,OAAA,GAAU,IAAI,IAAK,EAAA;AACzB,EAAO,OAAA,OAAA,CAAQ,SAAS,CAAK,IAAA,OAAA,CAAQ,SAAS,GAAO,IAAA,UAAA,CAAW,KAAK,OAAO,CAAA;AAC9E;AAEa,MAAA,UAAA,GAAa,CAAC,KAAqC,KAAA;AAC9D,EAAA,IAAI,CAAC,KAAO,EAAA;AACV,IAAA,OAAO,EAAC;AAAA;AAEV,EAAQ,OAAA,CAAA,KAAA,CAAM,QAAQ,KAAK,CAAA,GAAI,QAAQ,KAAM,CAAA,KAAA,CAAM,GAAG,CAAG,EAAA,MAAA;AAAA,IAAO,CAAA,CAAA,KAC9D,WAAW,CAAC;AAAA,GACd;AACF;;;;;;"}
|
package/dist/tags.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const TAGS_REGEX = new RegExp("^[a-z0-9
|
|
1
|
+
const TAGS_REGEX = new RegExp("^[a-z0-9+]+(([-_])[a-z0-9+]+)*$");
|
|
2
2
|
const isValidTag = (tag) => {
|
|
3
3
|
const trimmed = tag.trim();
|
|
4
4
|
return trimmed.length > 0 && trimmed.length < 255 && TAGS_REGEX.test(trimmed);
|
package/dist/tags.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tags.esm.js","sources":["../src/tags.ts"],"sourcesContent":["export const TAGS_REGEX = new RegExp('^[a-z0-9
|
|
1
|
+
{"version":3,"file":"tags.esm.js","sources":["../src/tags.ts"],"sourcesContent":["export const TAGS_REGEX = new RegExp('^[a-z0-9+]+(([-_])[a-z0-9+]+)*$');\n\nexport const isValidTag = (tag: string) => {\n const trimmed = tag.trim();\n return trimmed.length > 0 && trimmed.length < 255 && TAGS_REGEX.test(trimmed);\n};\n\nexport const filterTags = (input?: null | string | string[]) => {\n if (!input) {\n return [];\n }\n return (Array.isArray(input) ? input : input.split(',')).filter(v =>\n isValidTag(v),\n );\n};\n"],"names":[],"mappings":"AAAa,MAAA,UAAA,GAAa,IAAI,MAAA,CAAO,iCAAiC;AAEzD,MAAA,UAAA,GAAa,CAAC,GAAgB,KAAA;AACzC,EAAM,MAAA,OAAA,GAAU,IAAI,IAAK,EAAA;AACzB,EAAO,OAAA,OAAA,CAAQ,SAAS,CAAK,IAAA,OAAA,CAAQ,SAAS,GAAO,IAAA,UAAA,CAAW,KAAK,OAAO,CAAA;AAC9E;AAEa,MAAA,UAAA,GAAa,CAAC,KAAqC,KAAA;AAC9D,EAAA,IAAI,CAAC,KAAO,EAAA;AACV,IAAA,OAAO,EAAC;AAAA;AAEV,EAAQ,OAAA,CAAA,KAAA,CAAM,QAAQ,KAAK,CAAA,GAAI,QAAQ,KAAM,CAAA,KAAA,CAAM,GAAG,CAAG,EAAA,MAAA;AAAA,IAAO,CAAA,CAAA,KAC9D,WAAW,CAAC;AAAA,GACd;AACF;;;;"}
|
package/dist/utils.cjs.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var catalogModel = require('@backstage/catalog-model');
|
|
4
4
|
var lodash = require('lodash');
|
|
5
|
+
var tags = require('./tags.cjs.js');
|
|
5
6
|
|
|
6
7
|
const truncate = (str, n) => {
|
|
7
8
|
return str.length > n ? `${str.slice(0, n - 1)}...` : str;
|
|
@@ -23,6 +24,15 @@ const findUserMentions = (text) => {
|
|
|
23
24
|
})
|
|
24
25
|
);
|
|
25
26
|
};
|
|
27
|
+
const findTagMentions = (text) => {
|
|
28
|
+
const mentions = text.match(/#(\S+)/g);
|
|
29
|
+
const ret = mentions ? Array.from(new Set(mentions)) : [];
|
|
30
|
+
return lodash.compact(
|
|
31
|
+
ret.filter((tag) => {
|
|
32
|
+
return tags.isValidTag(tag.slice(1));
|
|
33
|
+
})
|
|
34
|
+
);
|
|
35
|
+
};
|
|
26
36
|
const removeMarkdownFormatting = (text) => {
|
|
27
37
|
let fixed = text.replace(/<[^>]*>/g, "");
|
|
28
38
|
fixed = fixed.replace(/```[\s\S]*?```/g, (match) => {
|
|
@@ -34,6 +44,7 @@ const removeMarkdownFormatting = (text) => {
|
|
|
34
44
|
return fixed;
|
|
35
45
|
};
|
|
36
46
|
|
|
47
|
+
exports.findTagMentions = findTagMentions;
|
|
37
48
|
exports.findUserMentions = findUserMentions;
|
|
38
49
|
exports.removeMarkdownFormatting = removeMarkdownFormatting;
|
|
39
50
|
exports.truncate = truncate;
|
package/dist/utils.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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":"
|
|
1
|
+
{"version":3,"file":"utils.cjs.js","sources":["../src/utils.ts"],"sourcesContent":["import { parseEntityRef, stringifyEntityRef } from '@backstage/catalog-model';\nimport { compact } from 'lodash';\nimport { isValidTag } from './tags';\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\nexport const findTagMentions = (text: string): string[] => {\n const mentions = text.match(/#(\\S+)/g);\n const ret = mentions ? Array.from(new Set(mentions)) : [];\n return compact(\n ret.filter(tag => {\n return isValidTag(tag.slice(1));\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","isValidTag"],"mappings":";;;;;;AAIa,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,C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vC,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;AAAA,GACzD,CAAA;AAGD,EAAQ,KAAA,GAAA,KAAA,CAAM,OAAQ,CAAA,sBAAA,EAAwB,IAAI,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;AAG7B,EAAQ,KAAA,GAAA,KAAA,CAAM,OAAQ,CAAA,UAAA,EAAY,EAAE,CAAA;AAEpC,EAAO,OAAA,KAAA;AACT;;;;;;;"}
|
package/dist/utils.esm.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { parseEntityRef, stringifyEntityRef } from '@backstage/catalog-model';
|
|
2
2
|
import { compact } from 'lodash';
|
|
3
|
+
import { isValidTag } from './tags.esm.js';
|
|
3
4
|
|
|
4
5
|
const truncate = (str, n) => {
|
|
5
6
|
return str.length > n ? `${str.slice(0, n - 1)}...` : str;
|
|
@@ -21,6 +22,15 @@ const findUserMentions = (text) => {
|
|
|
21
22
|
})
|
|
22
23
|
);
|
|
23
24
|
};
|
|
25
|
+
const findTagMentions = (text) => {
|
|
26
|
+
const mentions = text.match(/#(\S+)/g);
|
|
27
|
+
const ret = mentions ? Array.from(new Set(mentions)) : [];
|
|
28
|
+
return compact(
|
|
29
|
+
ret.filter((tag) => {
|
|
30
|
+
return isValidTag(tag.slice(1));
|
|
31
|
+
})
|
|
32
|
+
);
|
|
33
|
+
};
|
|
24
34
|
const removeMarkdownFormatting = (text) => {
|
|
25
35
|
let fixed = text.replace(/<[^>]*>/g, "");
|
|
26
36
|
fixed = fixed.replace(/```[\s\S]*?```/g, (match) => {
|
|
@@ -32,5 +42,5 @@ const removeMarkdownFormatting = (text) => {
|
|
|
32
42
|
return fixed;
|
|
33
43
|
};
|
|
34
44
|
|
|
35
|
-
export { findUserMentions, removeMarkdownFormatting, truncate };
|
|
45
|
+
export { findTagMentions, findUserMentions, removeMarkdownFormatting, truncate };
|
|
36
46
|
//# sourceMappingURL=utils.esm.js.map
|
package/dist/utils.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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":"
|
|
1
|
+
{"version":3,"file":"utils.esm.js","sources":["../src/utils.ts"],"sourcesContent":["import { parseEntityRef, stringifyEntityRef } from '@backstage/catalog-model';\nimport { compact } from 'lodash';\nimport { isValidTag } from './tags';\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\nexport const findTagMentions = (text: string): string[] => {\n const mentions = text.match(/#(\\S+)/g);\n const ret = mentions ? Array.from(new Set(mentions)) : [];\n return compact(\n ret.filter(tag => {\n return isValidTag(tag.slice(1));\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":";;;;AAIa,MAAA,QAAA,GAAW,CAAC,GAAA,EAAa,CAAsB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