@clearfeed-ai/slack-to-html 1.2.1 → 1.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/.babelrc +1 -1
- package/.mocharc.yml +5 -0
- package/dist/bundle.js +58 -4648
- package/dist/emoji.js +1915 -1
- package/dist/index.js +3 -1
- package/eslint.config.js +39 -0
- package/package.json +18 -86
- package/printBuiltSlackHawkDownRegExps.js +6 -6
- package/src/index.js +177 -178
- package/test/common.js +0 -2
- package/test/markdownTest.js +63 -0
- package/test/mocha.opts +0 -3
package/dist/index.js
CHANGED
|
@@ -1 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";var _index=_interopRequireDefault(require("xregexp/src/index")),_emoji=_interopRequireDefault(require("./emoji"));function _interopRequireDefault(c){return c&&c.__esModule?c:{default:c}}var expandEmoji=function(n){var e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},a=arguments.length>2&&arguments[2]!==void 0?arguments[2]:!1,r=Object.assign({},_emoji.default,e);return n.replace(/:(\S+?):/g,function(s,t){for(var u=/alias:(\S+)/,o=t,l;l=r[o],!(!l||!l.match(u));)o=l.replace(u,"$1");if(o&&l){if(l.match(/https?:\/\/\S+/))return'<img alt="'.concat(t,'" src="').concat(l,'" title=":').concat(t,':" class="slack_emoji" />');var d=l.split("-").map(function(v){return"&#x".concat(v,";")}).join("");return a?d:'<span title=":'.concat(t,':">').concat(d,"</span>")}return s})},closingDivPatternString="</div>",closingSpanPatternString="</span>",codeDivOpeningPatternString='<div class="slack_code">',codeSpanOpeningPatternString='<span class="slack_code">',openingCodePatternString="<code>",closingCodePatternString="</code>",boldOpeningPatternString='<strong class="slack_bold">',boldClosingPatternString="</strong>",strikethroughOpeningPatternString='<s class="slack_strikethrough">',strikethroughClosingPatternString="</s>",italicOpeningPatternString='<em class="slack_italics">',italicClosingPatternString="</em>",blockDivOpeningPatternString='<div class="slack_block">',blockSpanOpeningPatternString='<blockquote class="slack_block">',blockSpanClosingPatternString="</blockquote>",paragraphBreak=_index.default.cache("\\n\\n","nsg"),paragraphBreakTagLiteral='<div class="slack_line_break"></div>',lineBreakTagLiteral="<br>",newlineRegExp=_index.default.cache("\\n","nsg"),whitespaceRegExp=_index.default.cache("\\s","ns"),slackMrkdwnCharactersRegExp=_index.default.cache("(?<mrkdwnCharacter>[\\*\\`\\~\\_]|>)","ng"),slackMrkdwnPercentageCharsMap={"*":"%2A",">":"%26gt;","`":"%27","~":"%7E",_:"%5F"},userMentionRegExp=_index.default.cache("<@(((?<userID>[U|W][^|>]+)(\\|(?<userName>[^>]+))?)|(?<userNameWithoutID>[^>]+))>","ng"),channelMentionRegExp=_index.default.cache("<#(((?<channelID>C[^|>]+)(\\|(?<channelName>[^>]*))?)|(?<channelNameWithoutID>[^>]+))>","ng"),linkRegExp=_index.default.cache("<(?<linkUrl>(https?|s3|ftp):[^|>]+)(\\|(?<linkHtml>[^>]+))?>","ng"),mailToRegExp=_index.default.cache("<mailto:(?<mailTo>[^|>]+)(\\|(?<mailToName>[^>]+))?>","ng"),telRegExp=_index.default.cache("<tel:(?<tel>[^|>]+)(\\|(?<telName>[^>]+))?>","ng"),subteamCommandRegExp=_index.default.cache("<!subteam\\^(?<subteamID>S[^|>]+)(\\|(?<subteamName>[^>]+))?>","ng"),commandRegExp=_index.default.cache("<!(?<commandLiteral>[^|>]+)(\\|(?<commandName>[^>]+))?>","ng"),knownCommands=["here","channel","group","everyone"],escapeTags=function(n){return["<",n.substring(1,n.length-1),">"].join("")},replaceUserName=function(n){return function(e){var a=e.userName||e.userNameWithoutID||e.userID&&n&&n[e.userID];return a?'<span class="user-mention">@'.concat(a,"</span>"):escapeTags(e.toString())}},replaceChannelName=function(n){return function(e){var a=e.channelName||e.channelNameWithoutID||e.channelID&&n&&n[e.channelID];return a?"#".concat(a):escapeTags(e.channelID?"<#".concat(e.channelID,">"):e.toString())}},replaceUserGroupName=function(n){return function(e){var a=e.subteamName||e.subteamID&&n&&n[e.subteamID];return a?"@".concat(a):escapeTags(e.toString())}},buildOpeningDelimiterRegExp=function(n){var e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},a=e.prefixPattern,r=a===void 0?"":a,s=e.spacePadded,t=s===void 0?!1:s,u=e.escapeDelimiter,o=u===void 0?!0:u,l=o?_index.default.escape(n):n,d=t?`(?<openingCapturedWhitespace>^|\\s|["'])`:"";return _index.default.cache("".concat(d).concat(r).concat(l),"ns")},closingDelimiterAllowedChars=`"',.:!?`,buildClosingDelimiterRegExp=function(n){var e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},a=e.spacePadded,r=a===void 0?!1:a,s=e.escapeDelimiter,t=s===void 0?!0:s,u=t?_index.default.escape(n):n,o=r?"(?<closingCapturedWhitespace>\\s|[".concat(closingDelimiterAllowedChars,"]|$)"):"";return _index.default.cache("".concat(u).concat(o),"ns")},incrementWindows=function(n,e){return n.forEach(function(a){a[0]+=e,a[1]+=e}),n},_replaceInWindows=function(n,e,a,r,s){var t=arguments.length>5&&arguments[5]!==void 0?arguments[5]:{},u=arguments.length>6&&arguments[6]!==void 0?arguments[6]:0,o=arguments.length>7&&arguments[7]!==void 0?arguments[7]:0,l=t.partitionWindowOnMatch,d=t.spacePadded,v=t.endingPattern,D=t.replaceNewlines,m=t.maxReplacements,i=buildOpeningDelimiterRegExp(e,{spacePadded:d,prefixPattern:t.prefixPattern}),k=v?buildClosingDelimiterRegExp(t.endingPattern,{escapeDelimiter:!1}):buildClosingDelimiterRegExp(e,{spacePadded:d});if(u>=s.length||m&&m<=0)return{text:n,windows:s};var x=s[u],h=x[0],f=x[1];if(h>=f||h+o>f)return _replaceInWindows(n,e,a,r,s,t,u+1);var g=_index.default.exec(n,i,h+o);if(g&&g.index<f){for(var S=v?0:e.length,b=(u===s.length-1&&f===n.length?f+1:f)-S+1,p=_index.default.exec(n,k,g.index+e.length),P=p&&_index.default.exec(n,k,p.index+1);P;){var N=_index.default.exec(n,whitespaceRegExp,p.index+e.length),I=N&&N.index<b;if(P.index>=b||I)break;p=P,P=_index.default.exec(n,k,p.index+1)}if(p&&p.index<b){var _=p.index+p[0].length,W=n.slice(0,g.index),O=n.slice(_),$="".concat(d?g.openingCapturedWhitespace:"").concat(a),T="".concat(r).concat(d?p.closingCapturedWhitespace:"").concat(v?p[0]:""),E=n.slice(g.index+g[0].length,p.index);if(E.length===0)return _replaceInWindows(n,e,a,r,s,t,u,o+g[0].length);var C=D?_index.default.replace(E,newlineRegExp,lineBreakTagLiteral):E,B=[$,C,T].join(""),F=e.length+S,R=a.length+r.length-F+C.length-E.length,j=f+R,w=l?u+1:u,U=l?0:_+R-h+1;return l?(x[1]=g.index,s.splice(w,0,[p.index+S+R,j])):x[1]=j,incrementWindows(s.slice(w+1),R),m-=1,_replaceInWindows([W,B,O].join(""),e,a,r,s,Object.assign({},t,{maxReplacements:m}),w,U)}}return _replaceInWindows(n,e,a,r,s,t,u+1)},replaceParagraphBreaks=function(n){return _index.default.replace(n,paragraphBreak,paragraphBreakTagLiteral)},replaceBlockQuotes=function(n){var e=n.split(`
|
|
2
|
+
`),a=e.map(function(r){return r.trim().startsWith(">")?_replaceInWindows(r,">",blockSpanOpeningPatternString,blockSpanClosingPatternString,[[0,r.length]],{prefixPattern:"^\\s*",endingPattern:"\\n|$",maxReplacements:1}).text:r});return a.join(`
|
|
3
|
+
`)},expandText=function(n){var e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:!1,a;a={text:n,windows:[[0,n.length]]},a=_replaceInWindows(a.text,"```",codeDivOpeningPatternString+openingCodePatternString,closingCodePatternString+closingDivPatternString,a.windows,{partitionWindowOnMatch:!0,replaceNewlines:!0}),a=_replaceInWindows(a.text,"`",codeSpanOpeningPatternString+openingCodePatternString,closingCodePatternString+closingSpanPatternString,a.windows,{partitionWindowOnMatch:!0}),a=_replaceInWindows(a.text,"*",boldOpeningPatternString,boldClosingPatternString,a.windows,{maxReplacements:100,spacePadded:!0}),a=_replaceInWindows(a.text,"~",strikethroughOpeningPatternString,strikethroughClosingPatternString,a.windows,{maxReplacements:100,spacePadded:!0}),a=_replaceInWindows(a.text,"_",italicOpeningPatternString,italicClosingPatternString,a.windows,{maxReplacements:100,spacePadded:!0}),a=_replaceInWindows(a.text,">>>",blockDivOpeningPatternString,closingDivPatternString,a.windows,{prefixPattern:"^\\s*",endingPattern:"$",replaceNewlines:!0,maxReplacements:100});var r=replaceBlockQuotes(a.text);return e?r:replaceParagraphBreaks(r)},encodeSlackMrkdwnCharactersInLinks=function(n){return _index.default.replace(n,slackMrkdwnCharactersRegExp,function(e){return slackMrkdwnPercentageCharsMap[e.mrkdwnCharacter]||e.mrkdwnCharacter})},escapeForSlack=function(n){var e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},a=e.customEmoji||{},r=e.users||{},s=e.channels||{},t=e.usergroups||{},u=e.markdown||!1,o=e.skipEmojiSpans||!1,l=e.skipParagraphBreaks||!1,d=e.convertNewlinesToBr||!1,v=_index.default.replace(n||"",linkRegExp,function(i){var k=encodeSlackMrkdwnCharactersInLinks(i.linkUrl);return'<a href="'.concat(k,'" target="_blank" rel="noopener noreferrer">').concat(i.linkHtml||k,"</a>")}),D=u?expandText(v,l):v,m=expandEmoji(_index.default.replaceEach(D,[[userMentionRegExp,replaceUserName(r)],[channelMentionRegExp,replaceChannelName(s)],[mailToRegExp,function(i){return'<a href="mailto:'.concat(i.mailTo,'" target="_blank" rel="noopener noreferrer">').concat(i.mailToName||i.mailTo,"</a>")}],[telRegExp,function(i){return'<a href="tel:'.concat(i.tel,'">').concat(i.telName||i.tel,"</a>")}],[subteamCommandRegExp,replaceUserGroupName(t)],[commandRegExp,function(i){return i.commandLiteral&&i.commandLiteral.startsWith("subteam")?i.toString():knownCommands.includes(i.commandLiteral)?"@".concat(i.commandLiteral):i.commandName?"<".concat(i.commandName,">"):"<".concat(i.commandLiteral,">")}]]),a,o);return d?_index.default.replace(m,newlineRegExp,lineBreakTagLiteral):m},escapeForSlackWithMarkdown=function(n){var e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return escapeForSlack(n,Object.assign({},e,{markdown:!0}))},buildSlackHawkDownRegExps=function(){return{userMentionRegExp,channelMentionRegExp,linkRegExp,mailToRegExp,telRegExp,subteamCommandRegExp,boldOpeningDelimiterRegExp:buildOpeningDelimiterRegExp("*"),boldClosingDelimiterRegExp:buildClosingDelimiterRegExp("*"),italicsOpeningDelimiterRegExp:buildOpeningDelimiterRegExp("_",{spacePadded:!0}),italicsClosingDelimiterRegExp:buildClosingDelimiterRegExp("_",{spacePadded:!0}),strikethroughOpeningDelimiterRegExp:buildOpeningDelimiterRegExp("~"),strikethroughClosingDelimiterRegExp:buildClosingDelimiterRegExp("~"),blockDivOpeningDelimiterRegExp:buildOpeningDelimiterRegExp(">>>"),blockDivClosingDelimiterRegExp:buildClosingDelimiterRegExp("$",{escapeDelimiter:!1}),blockSpanOpeningDelimiterRegExp:buildOpeningDelimiterRegExp(">"),blockSpanClosingDelimiterRegExp:buildClosingDelimiterRegExp("\\n|$",{escapeDelimiter:!1})}};module.exports={escapeForSlack,escapeForSlackWithMarkdown,buildSlackHawkDownRegExps};
|
package/eslint.config.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const js = require('@eslint/js');
|
|
2
|
+
const globals = require('globals');
|
|
3
|
+
|
|
4
|
+
module.exports = [
|
|
5
|
+
{
|
|
6
|
+
ignores: [
|
|
7
|
+
'dist/**',
|
|
8
|
+
'test/**',
|
|
9
|
+
],
|
|
10
|
+
},
|
|
11
|
+
js.configs.recommended,
|
|
12
|
+
{
|
|
13
|
+
files: ['src/**/*.js'],
|
|
14
|
+
languageOptions: {
|
|
15
|
+
ecmaVersion: 2020,
|
|
16
|
+
sourceType: 'module',
|
|
17
|
+
globals: {
|
|
18
|
+
...globals.browser,
|
|
19
|
+
...globals.node,
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
rules: {
|
|
23
|
+
'no-console': ['warn', { allow: ['warn', 'error'] }],
|
|
24
|
+
'no-unused-vars': 'warn',
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
files: ['*.js'],
|
|
29
|
+
languageOptions: {
|
|
30
|
+
sourceType: 'commonjs',
|
|
31
|
+
globals: {
|
|
32
|
+
...globals.node,
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
rules: {
|
|
36
|
+
'no-console': 'off',
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
];
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clearfeed-ai/slack-to-html",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.3",
|
|
4
4
|
"description": "Render Slack markdown as HTML",
|
|
5
|
-
"main": "dist/
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"browser": "dist/bundle.js",
|
|
6
7
|
"scripts": {
|
|
7
8
|
"update-emoji": "node updateEmoji.js",
|
|
8
9
|
"print-patterns": "npm run build && node printBuiltSlackHawkDownRegExps.js",
|
|
9
|
-
"compile": "babel src --
|
|
10
|
-
"build": "npm run update-emoji && npm run compile &&
|
|
11
|
-
"test": "npm run update-emoji && mocha
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"prepublish": "npm run precommit && npm test && npm run build"
|
|
10
|
+
"compile": "babel src --out-dir dist",
|
|
11
|
+
"build": "npm run update-emoji && npm run compile && esbuild dist/index.js --bundle --global-name=slackToHtml --outfile=dist/bundle.js --platform=browser --minify --target=es2015 && esbuild dist/index.js --minify --platform=node --outfile=dist/index.js --allow-overwrite --target=es2015",
|
|
12
|
+
"test": "npm run update-emoji && mocha",
|
|
13
|
+
"lint": "eslint .",
|
|
14
|
+
"prepublish": "npm run lint && npm test && npm run build"
|
|
15
15
|
},
|
|
16
16
|
"repository": {
|
|
17
17
|
"type": "git",
|
|
@@ -30,84 +30,16 @@
|
|
|
30
30
|
"xregexp": "^3.2.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"babel
|
|
34
|
-
"babel
|
|
35
|
-
"babel-
|
|
36
|
-
"babel
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"eslint-config-airbnb": "^14.1.0",
|
|
44
|
-
"eslint-plugin-import": "^2.2.0",
|
|
45
|
-
"eslint-plugin-jsx-a11y": "^4.0.0",
|
|
46
|
-
"eslint-plugin-react": "^6.10.0",
|
|
47
|
-
"husky": "^0.13.2",
|
|
48
|
-
"mocha": "^3.4.1"
|
|
49
|
-
},
|
|
50
|
-
"eslintConfig": {
|
|
51
|
-
"extends": "airbnb",
|
|
52
|
-
"env": {
|
|
53
|
-
"browser": true
|
|
54
|
-
},
|
|
55
|
-
"parserOptions": {
|
|
56
|
-
"ecmaVersion": 7,
|
|
57
|
-
"sourceType": "module",
|
|
58
|
-
"ecmaFeatures": {
|
|
59
|
-
"jsx": true,
|
|
60
|
-
"experimentalObjectRestSpread": true
|
|
61
|
-
}
|
|
62
|
-
},
|
|
63
|
-
"settings": {
|
|
64
|
-
"import/resolver": "node"
|
|
65
|
-
},
|
|
66
|
-
"globals": {
|
|
67
|
-
"_": true
|
|
68
|
-
},
|
|
69
|
-
"rules": {
|
|
70
|
-
"comma-dangle": 0,
|
|
71
|
-
"global-require": 0,
|
|
72
|
-
"max-len": 0,
|
|
73
|
-
"import/no-mutable-exports": 0,
|
|
74
|
-
"arrow-body-style": 0,
|
|
75
|
-
"no-return-assign": 0,
|
|
76
|
-
"object-shorthand": 0,
|
|
77
|
-
"linebreak-style": 0,
|
|
78
|
-
"newline-per-chained-call": 0,
|
|
79
|
-
"new-cap": 0,
|
|
80
|
-
"no-multi-spaces": 0,
|
|
81
|
-
"no-mixed-operators": 0,
|
|
82
|
-
"arrow-parens": [
|
|
83
|
-
2,
|
|
84
|
-
"always"
|
|
85
|
-
],
|
|
86
|
-
"semi": [
|
|
87
|
-
2,
|
|
88
|
-
"never"
|
|
89
|
-
],
|
|
90
|
-
"quotes": [
|
|
91
|
-
2,
|
|
92
|
-
"single"
|
|
93
|
-
],
|
|
94
|
-
"no-console": [
|
|
95
|
-
1,
|
|
96
|
-
{
|
|
97
|
-
"allow": [
|
|
98
|
-
"warn",
|
|
99
|
-
"error"
|
|
100
|
-
]
|
|
101
|
-
}
|
|
102
|
-
],
|
|
103
|
-
"no-param-reassign": [
|
|
104
|
-
2,
|
|
105
|
-
{
|
|
106
|
-
"props": false
|
|
107
|
-
}
|
|
108
|
-
],
|
|
109
|
-
"no-continue": 0
|
|
110
|
-
}
|
|
33
|
+
"@babel/cli": "^7.24.0",
|
|
34
|
+
"@babel/core": "^7.24.0",
|
|
35
|
+
"@babel/preset-env": "^7.24.0",
|
|
36
|
+
"@babel/register": "^7.23.7",
|
|
37
|
+
"@eslint/js": "^9.0.0",
|
|
38
|
+
"chai": "^4.4.1",
|
|
39
|
+
"esbuild": "^0.27.3",
|
|
40
|
+
"eslint": "^9.0.0",
|
|
41
|
+
"globals": "^15.0.0",
|
|
42
|
+
"mocha": "^10.4.0"
|
|
111
43
|
},
|
|
112
44
|
"directories": {
|
|
113
45
|
"test": "test"
|
|
@@ -2,10 +2,10 @@ var slackHawkDown = require('./dist/index.js');
|
|
|
2
2
|
|
|
3
3
|
var patterns = slackHawkDown.buildSlackHawkDownRegExps();
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
for (var key in patterns) {
|
|
6
|
+
if (Object.prototype.hasOwnProperty.call(patterns, key)) {
|
|
7
|
+
console.log(`${key}: ${patterns[key].source}`);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
10
|
|
|
11
|
-
console.log('Complete!')
|
|
11
|
+
console.log('Complete!');
|