@circlesac/mack 26.2.1 → 26.2.3
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/build/src/parser/internal.js +17 -4
- package/bun.lock +10 -795
- package/package.json +1 -3
- package/src/parser/internal.ts +18 -4
- package/tests/integration.spec.ts +2 -2
|
@@ -26,11 +26,16 @@ var slack_1 = require("../slack");
|
|
|
26
26
|
var validation_1 = require("../validation");
|
|
27
27
|
var recursionDepth = 0;
|
|
28
28
|
/**
|
|
29
|
-
* Escapes &, <, > for Slack mrkdwn format
|
|
29
|
+
* Escapes &, <, > for Slack mrkdwn format while preserving Slack special
|
|
30
|
+
* patterns: <@U…>, <#C…>, <!here>, <!channel>, <!everyone>, <https://…>.
|
|
30
31
|
* Only used in the section/mrkdwn code path (not rich_text).
|
|
31
32
|
*/
|
|
33
|
+
var SLACK_MRKDWN_PATTERN = /(<(?:@[A-Z0-9]+(?:\|[^>]+)?|#[A-Z0-9]+(?:\|[^>]+)?|![a-z]+(?:\^[^>]+)*(?:\|[^>]+)?|https?:\/\/[^>]+)>)/g;
|
|
32
34
|
function escapeForMrkdwn(text) {
|
|
33
|
-
return text
|
|
35
|
+
return text
|
|
36
|
+
.split(SLACK_MRKDWN_PATTERN)
|
|
37
|
+
.map(function (part, i) { return (i % 2 === 1 ? part : part.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">")); })
|
|
38
|
+
.join("");
|
|
34
39
|
}
|
|
35
40
|
function parsePlainText(element) {
|
|
36
41
|
var _a;
|
|
@@ -59,8 +64,16 @@ function parseMrkdwn(element) {
|
|
|
59
64
|
(0, validation_1.validateRecursionDepth)(recursionDepth);
|
|
60
65
|
switch (element.type) {
|
|
61
66
|
case "link": {
|
|
62
|
-
var href = element.href
|
|
63
|
-
|
|
67
|
+
var href = element.href || "";
|
|
68
|
+
// Handle Slack pipe format: <url|text> parsed as autolink by marked
|
|
69
|
+
var pipeIndex = href.indexOf("|");
|
|
70
|
+
if (pipeIndex > 0) {
|
|
71
|
+
var url = href.slice(0, pipeIndex);
|
|
72
|
+
if ((0, validation_1.validateUrl)(url)) {
|
|
73
|
+
return "<".concat(url, "|").concat(href.slice(pipeIndex + 1), ">");
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (!(0, validation_1.validateUrl)(href)) {
|
|
64
77
|
return element.tokens.flatMap(function (child) { return parseMrkdwn(child); }).join("");
|
|
65
78
|
}
|
|
66
79
|
return "<".concat(href, "|").concat(element.tokens.flatMap(function (child) { return parseMrkdwn(child); }).join(""), "> ");
|