@ecency/render-helper 2.3.17 → 2.4.2

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.
Files changed (155) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +171 -17
  3. package/dist/browser/index.d.ts +32 -0
  4. package/dist/browser/index.js +1556 -0
  5. package/dist/browser/index.js.map +1 -0
  6. package/dist/node/index.cjs +1575 -0
  7. package/dist/node/index.cjs.map +1 -0
  8. package/dist/node/index.mjs +1559 -0
  9. package/dist/node/index.mjs.map +1 -0
  10. package/package.json +49 -47
  11. package/lib/cache.d.ts +0 -3
  12. package/lib/cache.js +0 -21
  13. package/lib/cache.js.map +0 -1
  14. package/lib/catch-post-image.d.ts +0 -2
  15. package/lib/catch-post-image.js +0 -76
  16. package/lib/catch-post-image.js.map +0 -1
  17. package/lib/consts/allowed-attributes.const.d.ts +0 -2
  18. package/lib/consts/allowed-attributes.const.js +0 -71
  19. package/lib/consts/allowed-attributes.const.js.map +0 -1
  20. package/lib/consts/dom-parser.const.d.ts +0 -2
  21. package/lib/consts/dom-parser.const.js +0 -12
  22. package/lib/consts/dom-parser.const.js.map +0 -1
  23. package/lib/consts/index.d.ts +0 -5
  24. package/lib/consts/index.js +0 -22
  25. package/lib/consts/index.js.map +0 -1
  26. package/lib/consts/regexes.const.d.ts +0 -44
  27. package/lib/consts/regexes.const.js +0 -49
  28. package/lib/consts/regexes.const.js.map +0 -1
  29. package/lib/consts/section-list.const.d.ts +0 -1
  30. package/lib/consts/section-list.const.js +0 -24
  31. package/lib/consts/section-list.const.js.map +0 -1
  32. package/lib/consts/white-list.const.d.ts +0 -2
  33. package/lib/consts/white-list.const.js +0 -37
  34. package/lib/consts/white-list.const.js.map +0 -1
  35. package/lib/helper.d.ts +0 -6
  36. package/lib/helper.js +0 -72
  37. package/lib/helper.js.map +0 -1
  38. package/lib/index.d.ts +0 -8
  39. package/lib/index.js +0 -19
  40. package/lib/index.js.map +0 -1
  41. package/lib/markdown-2-html.d.ts +0 -2
  42. package/lib/markdown-2-html.js +0 -25
  43. package/lib/markdown-2-html.js.map +0 -1
  44. package/lib/methods/a.method.d.ts +0 -1
  45. package/lib/methods/a.method.js +0 -647
  46. package/lib/methods/a.method.js.map +0 -1
  47. package/lib/methods/clean-reply.method.d.ts +0 -1
  48. package/lib/methods/clean-reply.method.js +0 -37
  49. package/lib/methods/clean-reply.method.js.map +0 -1
  50. package/lib/methods/get-inner-html.method.d.ts +0 -1
  51. package/lib/methods/get-inner-html.method.js +0 -16
  52. package/lib/methods/get-inner-html.method.js.map +0 -1
  53. package/lib/methods/iframe.method.d.ts +0 -1
  54. package/lib/methods/iframe.method.js +0 -159
  55. package/lib/methods/iframe.method.js.map +0 -1
  56. package/lib/methods/img.method.d.ts +0 -4
  57. package/lib/methods/img.method.js +0 -50
  58. package/lib/methods/img.method.js.map +0 -1
  59. package/lib/methods/index.d.ts +0 -7
  60. package/lib/methods/index.js +0 -24
  61. package/lib/methods/index.js.map +0 -1
  62. package/lib/methods/linkify.method.d.ts +0 -1
  63. package/lib/methods/linkify.method.js +0 -56
  64. package/lib/methods/linkify.method.js.map +0 -1
  65. package/lib/methods/markdown-to-html.method.d.ts +0 -1
  66. package/lib/methods/markdown-to-html.method.js +0 -98
  67. package/lib/methods/markdown-to-html.method.js.map +0 -1
  68. package/lib/methods/noop.method.d.ts +0 -1
  69. package/lib/methods/noop.method.js +0 -6
  70. package/lib/methods/noop.method.js.map +0 -1
  71. package/lib/methods/p.method.d.ts +0 -1
  72. package/lib/methods/p.method.js +0 -11
  73. package/lib/methods/p.method.js.map +0 -1
  74. package/lib/methods/remove-child-nodes.method.d.ts +0 -1
  75. package/lib/methods/remove-child-nodes.method.js +0 -10
  76. package/lib/methods/remove-child-nodes.method.js.map +0 -1
  77. package/lib/methods/sanitize-html.method.d.ts +0 -1
  78. package/lib/methods/sanitize-html.method.js +0 -42
  79. package/lib/methods/sanitize-html.method.js.map +0 -1
  80. package/lib/methods/text.method.d.ts +0 -1
  81. package/lib/methods/text.method.js +0 -69
  82. package/lib/methods/text.method.js.map +0 -1
  83. package/lib/methods/traverse.method.d.ts +0 -3
  84. package/lib/methods/traverse.method.js +0 -38
  85. package/lib/methods/traverse.method.js.map +0 -1
  86. package/lib/post-body-summary.d.ts +0 -2
  87. package/lib/post-body-summary.js +0 -123
  88. package/lib/post-body-summary.js.map +0 -1
  89. package/lib/proxify-image-src.d.ts +0 -5
  90. package/lib/proxify-image-src.js +0 -86
  91. package/lib/proxify-image-src.js.map +0 -1
  92. package/lib/render-helper.js +0 -1
  93. package/lib/types/entry.interface.d.ts +0 -7
  94. package/lib/types/entry.interface.js +0 -3
  95. package/lib/types/entry.interface.js.map +0 -1
  96. package/lib/types/index.d.ts +0 -2
  97. package/lib/types/index.js +0 -19
  98. package/lib/types/index.js.map +0 -1
  99. package/lib/types/xss-white-list.interface.d.ts +0 -6
  100. package/lib/types/xss-white-list.interface.js +0 -3
  101. package/lib/types/xss-white-list.interface.js.map +0 -1
  102. package/src/cache.ts +0 -15
  103. package/src/catch-post-image.spec.ts +0 -144
  104. package/src/catch-post-image.ts +0 -78
  105. package/src/consts/allowed-attributes.const.ts +0 -69
  106. package/src/consts/dom-parser.const.ts +0 -6
  107. package/src/consts/index.ts +0 -5
  108. package/src/consts/regexes.const.ts +0 -46
  109. package/src/consts/section-list.const.ts +0 -20
  110. package/src/consts/white-list.const.ts +0 -33
  111. package/src/external-types/multihashes.d.ts +0 -3
  112. package/src/helper.spec.ts +0 -16
  113. package/src/helper.ts +0 -77
  114. package/src/index.ts +0 -18
  115. package/src/markdown-2-html.spec.ts +0 -1251
  116. package/src/markdown-2-html.ts +0 -25
  117. package/src/methods/a.method.ts +0 -791
  118. package/src/methods/clean-reply.method.ts +0 -32
  119. package/src/methods/get-inner-html.method.ts +0 -11
  120. package/src/methods/iframe.method.ts +0 -176
  121. package/src/methods/img.method.ts +0 -62
  122. package/src/methods/index.ts +0 -7
  123. package/src/methods/linkify.method.ts +0 -61
  124. package/src/methods/markdown-to-html.method.ts +0 -104
  125. package/src/methods/noop.method.ts +0 -1
  126. package/src/methods/p.method.ts +0 -6
  127. package/src/methods/remove-child-nodes.method.ts +0 -5
  128. package/src/methods/sanitize-html.method.ts +0 -32
  129. package/src/methods/text.method.ts +0 -77
  130. package/src/methods/traverse.method.ts +0 -33
  131. package/src/post-body-summary.spec.ts +0 -150
  132. package/src/post-body-summary.ts +0 -130
  133. package/src/proxify-image-src.spec.ts +0 -76
  134. package/src/proxify-image-src.ts +0 -77
  135. package/src/sanitize-html.spec.ts +0 -15
  136. package/src/test/data/index.ts +0 -12
  137. package/src/test/data/json/muratkbesiroglu____sci-fi-novel-underground-city-part-13.json +0 -2120
  138. package/src/test/data/json/steemitboard____steemitboard-notify-dunsky-20181210t153450000z.json +0 -47
  139. package/src/test/data/legacy/10.json +0 -5
  140. package/src/test/data/legacy/20.json +0 -5
  141. package/src/test/data/legacy/21.json +0 -5
  142. package/src/test/data/legacy/2112524.json +0 -5
  143. package/src/test/data/legacy/22.json +0 -5
  144. package/src/test/data/legacy/23.json +0 -5
  145. package/src/test/data/legacy/24.json +0 -5
  146. package/src/test/data/legacy/25.json +0 -5
  147. package/src/test/data/legacy/26.json +0 -5
  148. package/src/test/data/legacy/27.JSON +0 -5
  149. package/src/test/data/legacy/28.json +0 -5
  150. package/src/test/data/legacy/29.json +0 -5
  151. package/src/test/data/legacy/31.json +0 -5
  152. package/src/test/snaps.json +0 -8
  153. package/src/types/entry.interface.ts +0 -7
  154. package/src/types/index.ts +0 -2
  155. package/src/types/xss-white-list.interface.ts +0 -7
@@ -1,647 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.a = void 0;
4
- var consts_1 = require("../consts");
5
- var get_inner_html_method_1 = require("./get-inner-html.method");
6
- var proxify_image_src_1 = require("../proxify-image-src");
7
- var remove_child_nodes_method_1 = require("./remove-child-nodes.method");
8
- var helper_1 = require("../helper");
9
- var img_method_1 = require("./img.method");
10
- var normalizeValue = function (value) { return (value ? value.trim() : ''); };
11
- var matchesHref = function (href, value) {
12
- var normalizedHref = normalizeValue(href);
13
- if (!normalizedHref) {
14
- return false;
15
- }
16
- return normalizeValue(value) === normalizedHref;
17
- };
18
- var getInlineMeta = function (el, href) {
19
- var textMatches = matchesHref(href, el.textContent);
20
- var titleMatches = matchesHref(href, el.getAttribute('title'));
21
- return {
22
- textMatches: textMatches,
23
- nonInline: textMatches || titleMatches
24
- };
25
- };
26
- function a(el, forApp, webp) {
27
- if (!el || !el.parentNode) {
28
- return;
29
- }
30
- var href = el.getAttribute('href');
31
- // Continue if href has no value
32
- if (!href) {
33
- return;
34
- }
35
- var className = el.getAttribute('class');
36
- // Don't touch user and hashtag links
37
- if (['markdown-author-link', 'markdown-tag-link'].indexOf(className) !== -1) {
38
- return;
39
- }
40
- // Do not allow js hrefs
41
- if (href.startsWith('javascript')) {
42
- el.removeAttribute('href');
43
- return;
44
- }
45
- // if href is an image url and innerHTML same with href then mark it as image
46
- // & => & can break equality
47
- if (href.match(consts_1.IMG_REGEX) &&
48
- href.trim().replace(/&/g, '&') ===
49
- (0, get_inner_html_method_1.getSerializedInnerHTML)(el).trim().replace(/&/g, '&')) {
50
- var isLCP = false; // LCP handled elsewhere
51
- var imgHTML = (0, img_method_1.createImageHTML)(href, isLCP, webp);
52
- var replaceNode = consts_1.DOMParser.parseFromString(imgHTML);
53
- el.parentNode.replaceChild(replaceNode, el);
54
- return;
55
- }
56
- if (href.match(consts_1.IPFS_REGEX) &&
57
- href.trim().replace(/&/g, '&') ===
58
- (0, get_inner_html_method_1.getSerializedInnerHTML)(el).trim().replace(/&/g, '&') &&
59
- href.indexOf('#') === -1) {
60
- if (forApp) {
61
- el.setAttribute('data-href', href);
62
- el.removeAttribute('href');
63
- }
64
- el.setAttribute('class', 'markdown-img-link');
65
- (0, remove_child_nodes_method_1.removeChildNodes)(el);
66
- var img = el.ownerDocument.createElement('img');
67
- img.setAttribute('src', href);
68
- el.appendChild(img);
69
- return;
70
- }
71
- // If a hive post
72
- var postMatch = href.match(consts_1.POST_REGEX);
73
- if (postMatch && consts_1.WHITE_LIST.includes(postMatch[1].replace(/www./, ''))) {
74
- el.setAttribute('class', 'markdown-post-link');
75
- var tag = postMatch[2];
76
- var author = postMatch[3].replace('@', '');
77
- var permlink = (0, helper_1.sanitizePermlink)(postMatch[4]);
78
- if (!(0, helper_1.isValidPermlink)(permlink))
79
- return;
80
- var inlineMeta = getInlineMeta(el, href);
81
- if (inlineMeta.textMatches) {
82
- el.textContent = "@".concat(author, "/").concat(permlink);
83
- }
84
- var isInline = !inlineMeta.nonInline;
85
- if (forApp) {
86
- el.removeAttribute('href');
87
- el.setAttribute('data-href', href);
88
- el.setAttribute('data-is-inline', '' + isInline);
89
- el.setAttribute('data-tag', tag);
90
- el.setAttribute('data-author', author);
91
- el.setAttribute('data-permlink', permlink);
92
- }
93
- else {
94
- var h = "/".concat(tag, "/@").concat(author, "/").concat(permlink);
95
- el.setAttribute('href', h);
96
- el.setAttribute('data-is-inline', '' + isInline);
97
- }
98
- return;
99
- }
100
- // If a hive user with url
101
- var mentionMatch = href.match(consts_1.MENTION_REGEX);
102
- if (mentionMatch && consts_1.WHITE_LIST.includes(mentionMatch[1].replace(/www./, '')) && mentionMatch.length === 3) {
103
- var _author = mentionMatch[2].replace('@', '');
104
- if (!(0, helper_1.isValidUsername)(_author))
105
- return;
106
- var author = _author.toLowerCase();
107
- el.setAttribute('class', 'markdown-author-link');
108
- if (author.indexOf('/') === -1) {
109
- if (el.textContent === href) {
110
- el.textContent = "@".concat(author);
111
- }
112
- if (forApp) {
113
- el.removeAttribute('href');
114
- el.setAttribute('data-author', author);
115
- }
116
- else {
117
- var h = "/@".concat(author);
118
- el.setAttribute('href', h);
119
- }
120
- }
121
- return;
122
- }
123
- // If a tagged post and profile section links
124
- var tpostMatch = href.match(consts_1.INTERNAL_POST_TAG_REGEX);
125
- if ((tpostMatch && tpostMatch.length === 4 && consts_1.WHITE_LIST.some(function (v) { return tpostMatch[1].includes(v); })) || (tpostMatch && tpostMatch.length === 4 && tpostMatch[1].indexOf('/') == 0)) {
126
- // check if permlink is section or section with params ?q=xyz
127
- if (consts_1.SECTION_LIST.some(function (v) { return tpostMatch[3].includes(v); })) {
128
- el.setAttribute('class', 'markdown-profile-link');
129
- var author = tpostMatch[2].replace('@', '').toLowerCase();
130
- var section = tpostMatch[3];
131
- if (!(0, helper_1.isValidPermlink)(section))
132
- return;
133
- if (el.textContent === href) {
134
- el.textContent = "@".concat(author, "/").concat(section);
135
- }
136
- if (forApp) {
137
- var ha = "https://ecency.com/@".concat(author, "/").concat(section);
138
- el.setAttribute('href', ha);
139
- }
140
- else {
141
- var h = "/@".concat(author, "/").concat(section);
142
- el.setAttribute('href', h);
143
- }
144
- return;
145
- }
146
- else {
147
- // check if domain is not whitelist and does contain dot (not tag e.g. `/ecency`)
148
- if (tpostMatch[1] && tpostMatch[1].includes('.') && !consts_1.WHITE_LIST.some(function (v) { return tpostMatch[1].includes(v); })) {
149
- return;
150
- }
151
- var tag = 'post';
152
- // check if tag does exist and doesn't include dot likely word/tag
153
- if (tpostMatch[1] && !tpostMatch[1].includes('.')) {
154
- tag = tpostMatch[1];
155
- tag = tag.replace('/', '');
156
- }
157
- el.setAttribute('class', 'markdown-post-link');
158
- var author = tpostMatch[2].replace('@', '');
159
- var permlink = (0, helper_1.sanitizePermlink)(tpostMatch[3]);
160
- if (!(0, helper_1.isValidPermlink)(permlink))
161
- return;
162
- var inlineMeta = getInlineMeta(el, href);
163
- if (inlineMeta.textMatches) {
164
- el.textContent = "@".concat(author, "/").concat(permlink);
165
- }
166
- var isInline = !inlineMeta.nonInline;
167
- if (forApp) {
168
- el.removeAttribute('href');
169
- el.setAttribute('data-href', href);
170
- el.setAttribute('data-is-inline', '' + isInline);
171
- el.setAttribute('data-tag', tag);
172
- el.setAttribute('data-author', author);
173
- el.setAttribute('data-permlink', permlink);
174
- }
175
- else {
176
- var h = "/".concat(tag, "/@").concat(author, "/").concat(permlink);
177
- el.setAttribute('href', h);
178
- el.setAttribute('data-is-inline', '' + isInline);
179
- }
180
- return;
181
- }
182
- }
183
- // If a hive user with internal url
184
- var imentionMatch = href.match(consts_1.INTERNAL_MENTION_REGEX);
185
- if (imentionMatch) {
186
- var _author = imentionMatch[0].replace('/@', '');
187
- if (!(0, helper_1.isValidUsername)(_author))
188
- return;
189
- var author = _author.toLowerCase();
190
- el.setAttribute('class', 'markdown-author-link');
191
- if (author.indexOf('/') === -1) {
192
- if (el.textContent === href) {
193
- el.textContent = "@".concat(author);
194
- }
195
- if (forApp) {
196
- el.removeAttribute('href');
197
- el.setAttribute('data-author', author);
198
- }
199
- else {
200
- var h = "/@".concat(author);
201
- el.setAttribute('href', h);
202
- }
203
- }
204
- return;
205
- }
206
- // If a copied post and profile section links
207
- var cpostMatch = href.match(consts_1.INTERNAL_POST_REGEX);
208
- if ((cpostMatch && cpostMatch.length === 3 && cpostMatch[1].indexOf('@') === 0)) {
209
- if (consts_1.SECTION_LIST.some(function (v) { return cpostMatch[2].includes(v); })) {
210
- el.setAttribute('class', 'markdown-profile-link');
211
- var author = cpostMatch[1].replace('@', '').toLowerCase();
212
- var section = cpostMatch[2];
213
- if (el.textContent === href) {
214
- el.textContent = "@".concat(author, "/").concat(section);
215
- }
216
- if (forApp) {
217
- var ha = "https://ecency.com/@".concat(author, "/").concat(section);
218
- el.setAttribute('href', ha);
219
- }
220
- else {
221
- var h = "/@".concat(author, "/").concat(section);
222
- el.setAttribute('href', h);
223
- }
224
- return;
225
- }
226
- else {
227
- el.setAttribute('class', 'markdown-post-link');
228
- var tag = 'post';
229
- var author = cpostMatch[1].replace('@', '');
230
- var permlink = (0, helper_1.sanitizePermlink)(cpostMatch[2]);
231
- if (!(0, helper_1.isValidPermlink)(permlink))
232
- return;
233
- var inlineMeta = getInlineMeta(el, href);
234
- if (inlineMeta.textMatches) {
235
- el.textContent = "@".concat(author, "/").concat(permlink);
236
- }
237
- var isInline = !inlineMeta.nonInline;
238
- if (forApp) {
239
- el.removeAttribute('href');
240
- el.setAttribute('data-href', href);
241
- el.setAttribute('data-is-inline', '' + isInline);
242
- el.setAttribute('data-tag', tag);
243
- el.setAttribute('data-author', author);
244
- el.setAttribute('data-permlink', permlink);
245
- }
246
- else {
247
- var h = "/".concat(tag, "/@").concat(author, "/").concat(permlink);
248
- el.setAttribute('href', h);
249
- el.setAttribute('data-is-inline', '' + isInline);
250
- }
251
- return;
252
- }
253
- }
254
- // If topic with filters url
255
- var topicMatch = href.match(consts_1.TOPIC_REGEX);
256
- if (topicMatch && consts_1.WHITE_LIST.includes(topicMatch[1].replace(/www./, '')) && topicMatch.length === 4) {
257
- el.setAttribute('class', 'markdown-tag-link');
258
- var filter = topicMatch[2];
259
- var tag = topicMatch[3];
260
- if (el.textContent === href) {
261
- el.textContent = "/".concat(filter, "/").concat(tag);
262
- }
263
- if (forApp) {
264
- el.removeAttribute('href');
265
- el.setAttribute('data-filter', filter);
266
- el.setAttribute('data-tag', tag);
267
- }
268
- else {
269
- var h = "/".concat(filter, "/").concat(tag);
270
- el.setAttribute('href', h);
271
- }
272
- return;
273
- }
274
- // If topic with filters internal url
275
- var itopicMatch = href.match(consts_1.INTERNAL_TOPIC_REGEX);
276
- if (itopicMatch && itopicMatch.length === 3) {
277
- el.setAttribute('class', 'markdown-tag-link');
278
- var filter = itopicMatch[1];
279
- var tag = itopicMatch[2];
280
- if (el.textContent === href) {
281
- el.textContent = "/".concat(filter, "/").concat(tag);
282
- }
283
- if (forApp) {
284
- el.removeAttribute('href');
285
- el.setAttribute('data-filter', filter);
286
- el.setAttribute('data-tag', tag);
287
- }
288
- else {
289
- var h = "/".concat(filter, "/").concat(tag);
290
- el.setAttribute('href', h);
291
- }
292
- return;
293
- }
294
- // If a custom hive community link
295
- var comMatch = href.match(consts_1.CUSTOM_COMMUNITY_REGEX);
296
- if (comMatch && consts_1.WHITE_LIST.includes(comMatch[1])) {
297
- el.setAttribute('class', 'markdown-community-link');
298
- var community = comMatch[2];
299
- var filter = comMatch[3].substring(1);
300
- if (!filter)
301
- filter = 'created';
302
- if (filter === 'about' || filter === 'discord') {
303
- filter = 'created';
304
- }
305
- if (el.textContent === href) {
306
- el.textContent = "".concat(filter, "/").concat(community);
307
- }
308
- if (forApp) {
309
- el.removeAttribute('href');
310
- el.setAttribute('data-community', community);
311
- el.setAttribute('data-filter', filter);
312
- }
313
- else {
314
- var h = "/".concat(filter, "/").concat(community);
315
- el.setAttribute('href', h);
316
- }
317
- return;
318
- }
319
- // If a collections post
320
- var cccMatch = href.match(consts_1.CCC_REGEX);
321
- if (cccMatch && consts_1.WHITE_LIST.includes(cccMatch[1])) {
322
- el.setAttribute('class', 'markdown-post-link');
323
- var tag = 'ccc';
324
- var author = cccMatch[2].replace('@', '');
325
- var permlink = (0, helper_1.sanitizePermlink)(cccMatch[3]);
326
- if (!(0, helper_1.isValidPermlink)(permlink))
327
- return;
328
- var inlineMeta = getInlineMeta(el, href);
329
- if (inlineMeta.textMatches) {
330
- el.textContent = "@".concat(author, "/").concat(permlink);
331
- }
332
- var isInline = !inlineMeta.nonInline;
333
- if (forApp) {
334
- el.removeAttribute('href');
335
- el.setAttribute('data-href', href);
336
- el.setAttribute('data-is-inline', '' + isInline);
337
- el.setAttribute('data-tag', tag);
338
- el.setAttribute('data-author', author);
339
- el.setAttribute('data-permlink', permlink);
340
- }
341
- else {
342
- var h = "/".concat(tag, "/@").concat(author, "/").concat(permlink);
343
- el.setAttribute('href', h);
344
- el.setAttribute('data-is-inline', '' + isInline);
345
- }
346
- return;
347
- }
348
- var BCmatch = href.match(consts_1.BITCHUTE_REGEX);
349
- if (BCmatch && el.textContent.trim() === href) {
350
- var e = consts_1.BITCHUTE_REGEX.exec(href);
351
- var vid = e[1];
352
- el.setAttribute('class', 'markdown-video-link');
353
- el.removeAttribute('href');
354
- var embedSrc = "https://www.bitchute.com/embed/".concat(vid, "/");
355
- el.textContent = '';
356
- el.setAttribute('data-embed-src', embedSrc);
357
- var play = el.ownerDocument.createElement('span');
358
- play.setAttribute('class', 'markdown-video-play');
359
- el.appendChild(play);
360
- return;
361
- }
362
- var RBmatch = href.match(consts_1.RUMBLE_REGEX);
363
- if (RBmatch && el.textContent.trim() === href) {
364
- var e = consts_1.RUMBLE_REGEX.exec(href);
365
- if (e[1]) {
366
- var vid = e[1];
367
- var embedSrc = "https://www.rumble.com/embed/".concat(vid, "/?pub=4");
368
- el.setAttribute('class', 'markdown-video-link');
369
- el.removeAttribute('href');
370
- el.textContent = '';
371
- el.setAttribute('data-embed-src', embedSrc);
372
- var play = el.ownerDocument.createElement('span');
373
- play.setAttribute('class', 'markdown-video-play');
374
- el.appendChild(play);
375
- return;
376
- }
377
- }
378
- var BNmatch = href.match(consts_1.BRIGHTEON_REGEX);
379
- if (BNmatch && el.textContent.trim() === href) {
380
- var e = consts_1.BRIGHTEON_REGEX.exec(href);
381
- if (e[2]) {
382
- var vid = e[2];
383
- var embedSrc = "https://www.brighteon.com/embed/".concat(vid);
384
- el.setAttribute('class', 'markdown-video-link');
385
- el.removeAttribute('href');
386
- el.textContent = '';
387
- el.setAttribute('data-embed-src', embedSrc);
388
- var play = el.ownerDocument.createElement('span');
389
- play.setAttribute('class', 'markdown-video-play');
390
- el.appendChild(play);
391
- return;
392
- }
393
- }
394
- // If a youtube video
395
- var match = href.match(consts_1.YOUTUBE_REGEX);
396
- if (match && el.textContent.trim() === href) {
397
- var e = consts_1.YOUTUBE_REGEX.exec(href);
398
- if (e[1]) {
399
- el.setAttribute('class', 'markdown-video-link markdown-video-link-youtube');
400
- el.removeAttribute('href');
401
- var vid = e[1];
402
- var thumbnail = (0, proxify_image_src_1.proxifyImageSrc)("https://img.youtube.com/vi/".concat(vid.split('?')[0], "/hqdefault.jpg"), 0, 0, webp ? 'webp' : 'match');
403
- var embedSrc = "https://www.youtube.com/embed/".concat(vid, "?autoplay=1");
404
- el.textContent = '';
405
- el.setAttribute('data-embed-src', embedSrc);
406
- el.setAttribute('data-youtube', vid);
407
- //extract start time if available
408
- var startTime = (0, helper_1.extractYtStartTime)(href);
409
- if (startTime) {
410
- el.setAttribute('data-start-time', startTime);
411
- }
412
- var thumbImg = el.ownerDocument.createElement('img');
413
- thumbImg.setAttribute('class', 'no-replace video-thumbnail');
414
- thumbImg.setAttribute('itemprop', 'thumbnailUrl');
415
- thumbImg.setAttribute('src', thumbnail);
416
- var play = el.ownerDocument.createElement('span');
417
- play.setAttribute('class', 'markdown-video-play');
418
- el.appendChild(thumbImg);
419
- el.appendChild(play);
420
- return;
421
- }
422
- }
423
- // If vimeo video
424
- match = href.match(consts_1.VIMEO_REGEX);
425
- if (match && href === el.textContent) {
426
- var e = consts_1.VIMEO_REGEX.exec(href);
427
- if (e[3]) {
428
- el.setAttribute('class', 'markdown-video-link markdown-video-link-vimeo');
429
- el.removeAttribute('href');
430
- var embedSrc = "https://player.vimeo.com/video/".concat(e[3]);
431
- el.textContent = '';
432
- var ifr = el.ownerDocument.createElement('iframe');
433
- ifr.setAttribute('frameborder', '0');
434
- ifr.setAttribute('allowfullscreen', 'true');
435
- ifr.setAttribute('src', embedSrc);
436
- el.appendChild(ifr);
437
- return;
438
- }
439
- }
440
- // If twitch video
441
- match = href.match(consts_1.TWITCH_REGEX);
442
- if (match && href === el.textContent) {
443
- var e = consts_1.TWITCH_REGEX.exec(href);
444
- if (e[2]) {
445
- el.setAttribute('class', 'markdown-video-link markdown-video-link-twitch');
446
- el.removeAttribute('href');
447
- var embedSrc = '';
448
- if (e[1] === undefined) {
449
- embedSrc = "https://player.twitch.tv/?channel=".concat(e[2]);
450
- }
451
- else {
452
- embedSrc = "https://player.twitch.tv/?video=".concat(e[1]);
453
- }
454
- el.textContent = '';
455
- var ifr = el.ownerDocument.createElement('iframe');
456
- ifr.setAttribute('frameborder', '0');
457
- ifr.setAttribute('allowfullscreen', 'true');
458
- ifr.setAttribute('src', embedSrc);
459
- el.appendChild(ifr);
460
- return;
461
- }
462
- }
463
- // If a spotify audio
464
- match = href.match(consts_1.SPOTIFY_REGEX);
465
- if (match && el.textContent.trim() === href) {
466
- var e = consts_1.SPOTIFY_REGEX.exec(href);
467
- if (e[1]) {
468
- el.setAttribute('class', 'markdown-audio-link markdown-audio-link-spotify');
469
- el.removeAttribute('href');
470
- var embedSrc = "https://open.spotify.com/embed/playlist/".concat(e[1]);
471
- el.textContent = '';
472
- var ifr = el.ownerDocument.createElement('iframe');
473
- ifr.setAttribute('frameborder', '0');
474
- ifr.setAttribute('allowfullscreen', 'true');
475
- ifr.setAttribute('src', embedSrc);
476
- ifr.setAttribute('sandbox', 'allow-scripts allow-same-origin allow-popups');
477
- el.appendChild(ifr);
478
- return;
479
- }
480
- }
481
- // If a spotify audio
482
- match = href.match(consts_1.LOOM_REGEX);
483
- if (match && el.textContent.trim() === href) {
484
- var e = consts_1.LOOM_REGEX.exec(href);
485
- if (e[2]) {
486
- el.setAttribute('class', 'markdown-video-link markdown-video-link-loom');
487
- el.removeAttribute('href');
488
- var embedSrc = "https://www.loom.com/embed/".concat(e[2]);
489
- el.textContent = '';
490
- var ifr = el.ownerDocument.createElement('iframe');
491
- ifr.setAttribute('frameborder', '0');
492
- ifr.setAttribute('allowfullscreen', 'true');
493
- ifr.setAttribute('src', embedSrc);
494
- ifr.setAttribute('sandbox', 'allow-scripts allow-same-origin allow-popups');
495
- el.appendChild(ifr);
496
- return;
497
- }
498
- }
499
- // If a d.tube video
500
- match = href.match(consts_1.D_TUBE_REGEX);
501
- if (match) {
502
- // Only d.tube links contains an image
503
- var imgEls = el.getElementsByTagName('img');
504
- if (imgEls.length === 1 || el.textContent.trim() === href) {
505
- var e = consts_1.D_TUBE_REGEX.exec(href);
506
- // e[2] = username, e[3] object id
507
- if (e[2] && e[3]) {
508
- el.setAttribute('class', 'markdown-video-link markdown-video-link-dtube');
509
- el.removeAttribute('href');
510
- var videoHref = "https://emb.d.tube/#!/".concat(e[2], "/").concat(e[3]);
511
- // el.setAttribute('data-video-href', videoHref)
512
- el.setAttribute('data-embed-src', videoHref);
513
- //process thumb img element
514
- if (imgEls.length === 1) {
515
- var thumbnail = (0, proxify_image_src_1.proxifyImageSrc)(imgEls[0].getAttribute('src').replace(/\s+/g, ''), 0, 0, webp ? 'webp' : 'match');
516
- var thumbImg = el.ownerDocument.createElement('img');
517
- thumbImg.setAttribute('class', 'no-replace video-thumbnail');
518
- thumbImg.setAttribute('itemprop', 'thumbnailUrl');
519
- thumbImg.setAttribute('src', thumbnail);
520
- el.appendChild(thumbImg);
521
- // Remove image.
522
- el.removeChild(imgEls[0]);
523
- }
524
- else {
525
- el.textContent = '';
526
- }
527
- var play = el.ownerDocument.createElement('span');
528
- play.setAttribute('class', 'markdown-video-play');
529
- el.appendChild(play);
530
- return;
531
- }
532
- }
533
- }
534
- match = href.match(consts_1.D_TUBE_REGEX2);
535
- if (match) {
536
- var e = consts_1.D_TUBE_REGEX2.exec(href);
537
- // e[2] = username, e[3] object id
538
- if (e[2] && e[3]) {
539
- el.setAttribute('class', 'markdown-video-link markdown-video-link-dtube');
540
- el.removeAttribute('href');
541
- el.textContent = '';
542
- var videoHref = "https://emb.d.tube/#!/".concat(e[2], "/").concat(e[3]);
543
- // el.setAttribute('data-video-href', videoHref);
544
- el.setAttribute('data-embed-src', videoHref);
545
- var play = el.ownerDocument.createElement('span');
546
- play.setAttribute('class', 'markdown-video-play');
547
- el.appendChild(play);
548
- return;
549
- }
550
- }
551
- // Detect 3Speak
552
- match = href.match(consts_1.SPEAK_REGEX);
553
- if (match) {
554
- var imgEls = el.getElementsByTagName('img');
555
- if (imgEls.length === 1 || el.textContent.trim() === href) {
556
- var e = consts_1.SPEAK_REGEX.exec(href);
557
- // e[1] / e[2] = tld , e[3] = embed address
558
- if ((e[1] || e[2]) && e[3]) {
559
- var videoHref = "https://3speak.tv/embed?v=".concat(e[3]);
560
- el.setAttribute('class', 'markdown-video-link markdown-video-link-speak');
561
- el.removeAttribute('href');
562
- el.setAttribute('data-embed-src', videoHref);
563
- if (el.textContent.trim() === href) {
564
- el.textContent = '';
565
- }
566
- if (imgEls.length === 1) {
567
- var thumbnail = (0, proxify_image_src_1.proxifyImageSrc)(imgEls[0].getAttribute('src').replace(/\s+/g, ''), 0, 0, webp ? 'webp' : 'match');
568
- var thumbImg = el.ownerDocument.createElement('img');
569
- thumbImg.setAttribute('class', 'no-replace video-thumbnail');
570
- thumbImg.setAttribute('itemprop', 'thumbnailUrl');
571
- thumbImg.setAttribute('src', thumbnail);
572
- el.appendChild(thumbImg);
573
- // Remove image.
574
- el.removeChild(imgEls[0]);
575
- }
576
- var play = el.ownerDocument.createElement('span');
577
- play.setAttribute('class', 'markdown-video-play');
578
- el.appendChild(play);
579
- return;
580
- }
581
- }
582
- }
583
- // If tweets
584
- var matchT = href.match(consts_1.TWITTER_REGEX);
585
- if (matchT && el.textContent.trim() === href) {
586
- var e = consts_1.TWITTER_REGEX.exec(href);
587
- if (e) {
588
- var url = e[0].replace(/(<([^>]+)>)/gi, '');
589
- var author = e[1].replace(/(<([^>]+)>)/gi, '');
590
- var twitterCode = "<blockquote class=\"twitter-tweet\"><p>".concat(url, "</p>- <a href=\"").concat(url, "\">").concat(author, "</a></blockquote>");
591
- var replaceNode = consts_1.DOMParser.parseFromString(twitterCode);
592
- el.parentNode.replaceChild(replaceNode, el);
593
- return;
594
- }
595
- }
596
- if (href.indexOf('https://hivesigner.com/sign/account-witness-vote?witness=') === 0 && forApp) {
597
- el.setAttribute('class', 'markdown-witnesses-link');
598
- el.setAttribute('data-href', href);
599
- el.removeAttribute('href');
600
- return;
601
- }
602
- if (href.indexOf('hivesigner.com/sign/update-proposal-votes?proposal_ids') > 0 && forApp) {
603
- var m = decodeURI(href).match(/proposal_ids=\[(\d+)]/);
604
- if (m) {
605
- el.setAttribute('class', 'markdown-proposal-link');
606
- el.setAttribute('data-href', href);
607
- el.setAttribute('data-proposal', m[1]);
608
- el.removeAttribute('href');
609
- return;
610
- }
611
- }
612
- // If nothing matched element as external link so it will be opened in external window
613
- el.setAttribute('class', 'markdown-external-link');
614
- // Prepend https if no scheme provided
615
- if (!(/^((#)|(mailto:)|(\/(?!\/))|(((steem|hive|esteem|ecency|https?):)?\/\/))/.test(href))) {
616
- href = "https://".concat(href);
617
- }
618
- if (forApp) {
619
- el.setAttribute('data-href', href);
620
- var match_1 = href.match(consts_1.YOUTUBE_REGEX);
621
- if (match_1) {
622
- var e = consts_1.YOUTUBE_REGEX.exec(href);
623
- if (e[1]) {
624
- var vid = e[1];
625
- el.setAttribute('data-youtube', vid);
626
- //extract start time if available
627
- var startTime = (0, helper_1.extractYtStartTime)(href);
628
- if (startTime) {
629
- el.setAttribute('data-start-time', startTime);
630
- }
631
- }
632
- }
633
- el.removeAttribute('href');
634
- }
635
- else {
636
- var matchS = href.match(consts_1.SECTION_REGEX);
637
- if (matchS) {
638
- el.setAttribute('class', 'markdown-internal-link');
639
- }
640
- else {
641
- el.setAttribute('target', '_blank');
642
- el.setAttribute('rel', 'noopener');
643
- }
644
- }
645
- }
646
- exports.a = a;
647
- //# sourceMappingURL=a.method.js.map