@ecency/render-helper 2.2.15 → 2.2.18
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/README.md +8 -0
- package/lib/consts/index.d.ts +1 -0
- package/lib/consts/index.js +6 -1
- package/lib/consts/index.js.map +1 -1
- package/lib/consts/regexes.const.d.ts +1 -0
- package/lib/consts/regexes.const.js +3 -2
- package/lib/consts/regexes.const.js.map +1 -1
- package/lib/consts/section-list.const.d.ts +1 -0
- package/lib/consts/section-list.const.js +19 -0
- package/lib/consts/section-list.const.js.map +1 -0
- package/lib/helper.js +11 -7
- package/lib/helper.js.map +1 -1
- package/lib/methods/a.method.js +17 -10
- package/lib/methods/a.method.js.map +1 -1
- package/lib/methods/index.js +5 -1
- package/lib/methods/index.js.map +1 -1
- package/lib/methods/linkify.method.js +1 -1
- package/lib/methods/linkify.method.js.map +1 -1
- package/lib/render-helper.js +1 -1
- package/lib/types/index.js +5 -1
- package/lib/types/index.js.map +1 -1
- package/package.json +1 -1
- package/src/consts/index.ts +1 -0
- package/src/consts/regexes.const.ts +3 -2
- package/src/consts/section-list.const.ts +15 -0
- package/src/helper.ts +10 -8
- package/src/markdown-2-html.spec.ts +43 -7
- package/src/methods/a.method.ts +19 -11
- package/src/methods/linkify.method.ts +2 -2
package/lib/types/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
package/lib/types/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAiC;AACjC,6DAA0C"}
|
package/package.json
CHANGED
package/src/consts/index.ts
CHANGED
|
@@ -8,7 +8,7 @@ export const MENTION_REGEX = /^https?:\/\/(.*)\/(@[\w.\d-]+)$/i
|
|
|
8
8
|
export const TOPIC_REGEX = /^https?:\/\/(.*)\/(trending|hot|created|promoted|muted|payout)\/(.*)$/i
|
|
9
9
|
export const INTERNAL_MENTION_REGEX = /^\/@[\w.\d-]+$/i
|
|
10
10
|
export const INTERNAL_TOPIC_REGEX = /^\/(trending|hot|created|promoted|muted|payout)\/(.*)$/i
|
|
11
|
-
export const INTERNAL_POST_TAG_REGEX =
|
|
11
|
+
export const INTERNAL_POST_TAG_REGEX = /(.*)\/(@[\w.\d-]+)\/(.*)/i
|
|
12
12
|
export const INTERNAL_POST_REGEX = /^\/(@[\w.\d-]+)\/(.*)$/i
|
|
13
13
|
export const CUSTOM_COMMUNITY_REGEX = /^https?:\/\/(.*)\/c\/(hive-\d+)(.*)/i
|
|
14
14
|
export const YOUTUBE_REGEX = /(?:youtube.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu.be\/)([^"&?\/\s]{11})/g
|
|
@@ -39,4 +39,5 @@ export const BRAND_NEW_TUBE_REGEX = /^https:\/\/brandnewtube\.com\/embed\/[a-z0-
|
|
|
39
39
|
export const LOOM_REGEX = /^(https?:)?\/\/www.loom.com\/share\/(.*)/i
|
|
40
40
|
export const LOOM_EMBED_REGEX = /^(https?:)?\/\/www.loom.com\/embed\/(.*)/i
|
|
41
41
|
export const AUREAL_EMBED_REGEX = /^(https?:\/\/)?(www\.)?(?:aureal-embed)\.web\.app\/([0-9]+)/i
|
|
42
|
-
export const ENTITY_REGEX = /&([a-z0-9]+|#[0-9]{1,6}|#x[0-9a-fA-F]{1,6});/ig
|
|
42
|
+
export const ENTITY_REGEX = /&([a-z0-9]+|#[0-9]{1,6}|#x[0-9a-fA-F]{1,6});/ig
|
|
43
|
+
export const SECTION_REGEX = /\B(\#[\da-zA-Z-_]+\b)(?!;)/i
|
package/src/helper.ts
CHANGED
|
@@ -15,13 +15,15 @@ export function makeEntryCacheKey(entry: any): string {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
export function extractYtStartTime(url:string):string {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
try {
|
|
19
|
+
const urlObj = new URL(url);
|
|
20
|
+
const params = new URLSearchParams(urlObj.search);
|
|
21
|
+
if(params.has('t')){
|
|
22
|
+
return '' + parseInt(params.get('t')); //parsing is important as sometimes t is famated '123s';
|
|
23
|
+
}else if (params.has('start')){
|
|
24
|
+
return params.get('start');
|
|
25
|
+
}
|
|
26
|
+
} catch (error) {
|
|
27
|
+
return '';
|
|
24
28
|
}
|
|
25
|
-
|
|
26
|
-
return '';
|
|
27
29
|
}
|
|
@@ -644,7 +644,7 @@ describe('Markdown2Html', () => {
|
|
|
644
644
|
expect(markdown2Html(input)).toBe(expected)
|
|
645
645
|
})
|
|
646
646
|
|
|
647
|
-
it('43- Should handle dtube iframe', () => {
|
|
647
|
+
it('43 - Should handle dtube iframe', () => {
|
|
648
648
|
const input = {
|
|
649
649
|
author: 'foo343',
|
|
650
650
|
permlink: 'bar343',
|
|
@@ -656,7 +656,7 @@ describe('Markdown2Html', () => {
|
|
|
656
656
|
expect(markdown2Html(input)).toBe(expected)
|
|
657
657
|
})
|
|
658
658
|
|
|
659
|
-
it('44- Should handle vimm iframe', () => {
|
|
659
|
+
it('44 - Should handle vimm iframe', () => {
|
|
660
660
|
const input = {
|
|
661
661
|
author: 'foo344',
|
|
662
662
|
permlink: 'bar344',
|
|
@@ -680,7 +680,7 @@ describe('Markdown2Html', () => {
|
|
|
680
680
|
expect(markdown2Html(input)).toBe(expected)
|
|
681
681
|
})
|
|
682
682
|
|
|
683
|
-
it('46- Should handle copied md links', () => {
|
|
683
|
+
it('46 - Should handle copied md links', () => {
|
|
684
684
|
const input = {
|
|
685
685
|
author: 'foo346',
|
|
686
686
|
permlink: 'bar346',
|
|
@@ -692,7 +692,7 @@ describe('Markdown2Html', () => {
|
|
|
692
692
|
expect(markdown2Html(input)).toBe(expected)
|
|
693
693
|
})
|
|
694
694
|
|
|
695
|
-
it('47- Should handle internal links', () => {
|
|
695
|
+
it('47 - Should handle internal links', () => {
|
|
696
696
|
const input = {
|
|
697
697
|
author: 'foo347',
|
|
698
698
|
permlink: 'bar347',
|
|
@@ -902,10 +902,10 @@ describe('Markdown2Html', () => {
|
|
|
902
902
|
expect(markdown2Html(input, false)).toBe(expected)
|
|
903
903
|
})
|
|
904
904
|
|
|
905
|
-
it('65- Should handle youtube.com/embed videos', () => {
|
|
905
|
+
it('65 - Should handle youtube.com/embed videos', () => {
|
|
906
906
|
const input = {
|
|
907
|
-
author: '
|
|
908
|
-
permlink: '
|
|
907
|
+
author: 'foo365',
|
|
908
|
+
permlink: 'bar365',
|
|
909
909
|
last_update: '2019-05-10T09:15:21',
|
|
910
910
|
body: 'https://www.youtube.com/embed/UuyS7YAkECA?start=295&autoplay=1'
|
|
911
911
|
}
|
|
@@ -913,6 +913,42 @@ describe('Markdown2Html', () => {
|
|
|
913
913
|
|
|
914
914
|
expect(markdown2Html(input)).toBe(expected)
|
|
915
915
|
})
|
|
916
|
+
|
|
917
|
+
it('66 - Should handle internal links with params', () => {
|
|
918
|
+
const input = {
|
|
919
|
+
author: 'foo366',
|
|
920
|
+
permlink: 'bar366',
|
|
921
|
+
last_update: '2019-05-10T09:15:21',
|
|
922
|
+
body: 'direct link https://ecency.com/@ecency/faq?history'
|
|
923
|
+
}
|
|
924
|
+
const expected = '<p>direct link <a class=\"markdown-post-link\" data-tag=\"post\" data-author=\"ecency\" data-permlink=\"faq?history\">@ecency/faq?history</a></p>'
|
|
925
|
+
|
|
926
|
+
expect(markdown2Html(input)).toBe(expected)
|
|
927
|
+
})
|
|
928
|
+
|
|
929
|
+
it('67 - Should handle section links with params', () => {
|
|
930
|
+
const input = {
|
|
931
|
+
author: 'foo367',
|
|
932
|
+
permlink: 'bar367',
|
|
933
|
+
last_update: '2019-05-10T09:15:21',
|
|
934
|
+
body: 'direct link https://ecency.com/@ecency/posts?q=games'
|
|
935
|
+
}
|
|
936
|
+
const expected = '<p>direct link <a href=\"https://ecency.com/@ecency/posts?q=games\" class=\"markdown-profile-link\">@ecency/posts?q=games</a></p>'
|
|
937
|
+
|
|
938
|
+
expect(markdown2Html(input)).toBe(expected)
|
|
939
|
+
})
|
|
940
|
+
|
|
941
|
+
it('68 - Should handle section links', () => {
|
|
942
|
+
const input = {
|
|
943
|
+
author: 'foo368',
|
|
944
|
+
permlink: 'bar368',
|
|
945
|
+
last_update: '2019-05-10T09:15:21',
|
|
946
|
+
body: 'this is link [What is HIVE](#WhatHive) and locatino ## 1 <a data-id="WhatHive"></a>What is HIVE?'
|
|
947
|
+
}
|
|
948
|
+
const expected = '<p>this is link <a href=\"#WhatHive\" class=\"markdown-internal-link\">What is HIVE</a> and locatino ## 1 <a data-id=\"WhatHive\"></a>What is HIVE?</p>'
|
|
949
|
+
|
|
950
|
+
expect(markdown2Html(input, false)).toBe(expected)
|
|
951
|
+
})
|
|
916
952
|
})
|
|
917
953
|
|
|
918
954
|
describe("Rumble support", () => {
|
package/src/methods/a.method.ts
CHANGED
|
@@ -23,7 +23,9 @@ import {
|
|
|
23
23
|
RUMBLE_REGEX,
|
|
24
24
|
BRIGHTEON_REGEX,
|
|
25
25
|
DOMParser,
|
|
26
|
-
LOOM_REGEX
|
|
26
|
+
LOOM_REGEX,
|
|
27
|
+
SECTION_REGEX,
|
|
28
|
+
SECTION_LIST
|
|
27
29
|
} from '../consts'
|
|
28
30
|
import { getSerializedInnerHTML } from './get-inner-html.method'
|
|
29
31
|
import { proxifyImageSrc } from '../proxify-image-src'
|
|
@@ -139,9 +141,10 @@ export function a(el: HTMLElement, forApp: boolean, webp: boolean): void {
|
|
|
139
141
|
// If a tagged post and profile section links
|
|
140
142
|
const tpostMatch = href.match(INTERNAL_POST_TAG_REGEX)
|
|
141
143
|
if (
|
|
142
|
-
(tpostMatch && WHITE_LIST.
|
|
144
|
+
(tpostMatch && tpostMatch.length === 4 && WHITE_LIST.some(v => tpostMatch[1].includes(v))) || (tpostMatch && tpostMatch.length === 4 && tpostMatch[1].indexOf('/') == 0)
|
|
143
145
|
) {
|
|
144
|
-
|
|
146
|
+
// check if permlink is section or section with params ?q=xyz
|
|
147
|
+
if (SECTION_LIST.some(v => tpostMatch[3].includes(v))) {
|
|
145
148
|
el.setAttribute('class', 'markdown-profile-link')
|
|
146
149
|
const author = tpostMatch[2].replace('@', '').toLowerCase()
|
|
147
150
|
const section = tpostMatch[3]
|
|
@@ -158,13 +161,18 @@ export function a(el: HTMLElement, forApp: boolean, webp: boolean): void {
|
|
|
158
161
|
}
|
|
159
162
|
return
|
|
160
163
|
} else {
|
|
161
|
-
|
|
162
|
-
|
|
164
|
+
// check if domain is not whitelist and does contain dot (not tag e.g. `/ecency`)
|
|
165
|
+
if (tpostMatch[1] && tpostMatch[1].includes('.') && !WHITE_LIST.some(v => tpostMatch[1].includes(v))) {
|
|
166
|
+
return
|
|
167
|
+
}
|
|
163
168
|
let tag = 'post'
|
|
164
|
-
if
|
|
169
|
+
// check if tag does exist and doesn't include dot likely word/tag
|
|
170
|
+
if (tpostMatch[1] && !tpostMatch[1].includes('.')) {
|
|
165
171
|
[, tag] = tpostMatch
|
|
172
|
+
tag = tag.replace('/', '')
|
|
166
173
|
}
|
|
167
174
|
|
|
175
|
+
el.setAttribute('class', 'markdown-post-link')
|
|
168
176
|
const author = tpostMatch[2].replace('@', '')
|
|
169
177
|
const permlink = tpostMatch[3]
|
|
170
178
|
if (el.textContent === href) {
|
|
@@ -210,7 +218,7 @@ export function a(el: HTMLElement, forApp: boolean, webp: boolean): void {
|
|
|
210
218
|
if (
|
|
211
219
|
(cpostMatch && cpostMatch.length === 3 && cpostMatch[1].indexOf('@') === 0)
|
|
212
220
|
) {
|
|
213
|
-
if (
|
|
221
|
+
if (SECTION_LIST.some(v => cpostMatch[2].includes(v))) {
|
|
214
222
|
el.setAttribute('class', 'markdown-profile-link')
|
|
215
223
|
const author = cpostMatch[1].replace('@', '').toLowerCase()
|
|
216
224
|
const section = cpostMatch[2]
|
|
@@ -699,12 +707,12 @@ export function a(el: HTMLElement, forApp: boolean, webp: boolean): void {
|
|
|
699
707
|
}
|
|
700
708
|
el.removeAttribute('href')
|
|
701
709
|
} else {
|
|
702
|
-
const
|
|
703
|
-
if(
|
|
710
|
+
const matchS = href.match(SECTION_REGEX)
|
|
711
|
+
if(matchS) {
|
|
712
|
+
el.setAttribute('class', 'markdown-internal-link');
|
|
713
|
+
} else {
|
|
704
714
|
el.setAttribute('target', '_blank');
|
|
705
715
|
el.setAttribute('rel', 'noopener');
|
|
706
|
-
} else {
|
|
707
|
-
el.setAttribute('class', 'markdown-internal-link')
|
|
708
716
|
}
|
|
709
717
|
}
|
|
710
718
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IMG_REGEX } from '../consts'
|
|
1
|
+
import { IMG_REGEX, SECTION_LIST } from '../consts'
|
|
2
2
|
import { proxifyImageSrc } from '../proxify-image-src'
|
|
3
3
|
|
|
4
4
|
export function linkify(content: string, forApp: boolean, webp: boolean): string {
|
|
@@ -34,7 +34,7 @@ export function linkify(content: string, forApp: boolean, webp: boolean): string
|
|
|
34
34
|
/((^|\s)(\/|)@[\w.\d-]+)\/(\S+)/gi, (match, u, p1, p2, p3) => {
|
|
35
35
|
const uu = u.trim().toLowerCase().replace('/@','').replace('@','');
|
|
36
36
|
const perm = p3;
|
|
37
|
-
if (
|
|
37
|
+
if (SECTION_LIST.some(v => p3.includes(v))) {
|
|
38
38
|
const attrs = forApp ? `https://ecency.com/@${uu}/${perm}` : `href="/@${uu}/${perm}"`
|
|
39
39
|
return ` <a class="markdown-profile-link" ${attrs}>@${uu}/${perm}</a>`
|
|
40
40
|
} else {
|