@ecency/render-helper 2.2.15 → 2.2.16

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ecency/render-helper",
3
- "version": "2.2.15",
3
+ "version": "2.2.16",
4
4
  "description": "Markdown+Html Render helper",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -1,4 +1,5 @@
1
1
  export * from './white-list.const'
2
+ export * from './section-list.const'
2
3
  export * from './regexes.const'
3
4
  export * from './allowed-attributes.const'
4
5
  export * from './dom-parser.const'
@@ -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 = /\/(.*)\/(@[\w.\d-]+)\/(.*)/i
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
@@ -0,0 +1,15 @@
1
+ export const SECTION_LIST = [
2
+ 'wallet',
3
+ 'feed',
4
+ 'followers',
5
+ 'following',
6
+ 'points',
7
+ 'communities',
8
+ 'posts',
9
+ 'blog',
10
+ 'comments',
11
+ 'replies',
12
+ 'settings',
13
+ 'engine',
14
+ 'permissions'
15
+ ]
@@ -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: 'foo329',
908
- permlink: 'bar329',
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,30 @@ 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
+ })
916
940
  })
917
941
 
918
942
  describe("Rumble support", () => {
@@ -23,7 +23,8 @@ import {
23
23
  RUMBLE_REGEX,
24
24
  BRIGHTEON_REGEX,
25
25
  DOMParser,
26
- LOOM_REGEX
26
+ LOOM_REGEX,
27
+ SECTION_LIST
27
28
  } from '../consts'
28
29
  import { getSerializedInnerHTML } from './get-inner-html.method'
29
30
  import { proxifyImageSrc } from '../proxify-image-src'
@@ -139,9 +140,10 @@ export function a(el: HTMLElement, forApp: boolean, webp: boolean): void {
139
140
  // If a tagged post and profile section links
140
141
  const tpostMatch = href.match(INTERNAL_POST_TAG_REGEX)
141
142
  if (
142
- (tpostMatch && WHITE_LIST.includes(tpostMatch[1].substring(1))) || (tpostMatch && tpostMatch.length === 4 && tpostMatch[1].indexOf('/') !== 0)
143
+ (tpostMatch && tpostMatch.length === 4 && WHITE_LIST.some(v => tpostMatch[1].includes(v))) || (tpostMatch && tpostMatch.length === 4 && tpostMatch[1].indexOf('/') == 0)
143
144
  ) {
144
- if (['wallet', 'feed', 'followers', 'following', 'points', 'communities', 'posts', 'blog', 'comments', 'replies', 'settings', 'engine'].includes(tpostMatch[3])) {
145
+ // check if permlink is section or section with params ?q=xyz
146
+ if (SECTION_LIST.some(v => tpostMatch[3].includes(v))) {
145
147
  el.setAttribute('class', 'markdown-profile-link')
146
148
  const author = tpostMatch[2].replace('@', '').toLowerCase()
147
149
  const section = tpostMatch[3]
@@ -158,13 +160,18 @@ export function a(el: HTMLElement, forApp: boolean, webp: boolean): void {
158
160
  }
159
161
  return
160
162
  } else {
161
- el.setAttribute('class', 'markdown-post-link')
162
-
163
+ // check if domain is not whitelist and does contain dot (not tag e.g. `/ecency`)
164
+ if (tpostMatch[1] && tpostMatch[1].includes('.') && !WHITE_LIST.some(v => tpostMatch[1].includes(v))) {
165
+ return
166
+ }
163
167
  let tag = 'post'
164
- if (!WHITE_LIST.includes(tpostMatch[1].substring(1))) {
168
+ // check if tag does exist and doesn't include dot likely word/tag
169
+ if (tpostMatch[1] && !tpostMatch[1].includes('.')) {
165
170
  [, tag] = tpostMatch
171
+ tag = tag.replace('/', '')
166
172
  }
167
173
 
174
+ el.setAttribute('class', 'markdown-post-link')
168
175
  const author = tpostMatch[2].replace('@', '')
169
176
  const permlink = tpostMatch[3]
170
177
  if (el.textContent === href) {
@@ -210,7 +217,7 @@ export function a(el: HTMLElement, forApp: boolean, webp: boolean): void {
210
217
  if (
211
218
  (cpostMatch && cpostMatch.length === 3 && cpostMatch[1].indexOf('@') === 0)
212
219
  ) {
213
- if (['wallet', 'feed', 'followers', 'following', 'points', 'communities', 'posts', 'blog', 'comments', 'replies', 'settings', 'engine'].includes(cpostMatch[2])) {
220
+ if (SECTION_LIST.some(v => cpostMatch[2].includes(v))) {
214
221
  el.setAttribute('class', 'markdown-profile-link')
215
222
  const author = cpostMatch[1].replace('@', '').toLowerCase()
216
223
  const section = cpostMatch[2]
@@ -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 (['wallet', 'feed', 'followers', 'following', 'points', 'communities', 'posts', 'blog', 'comments', 'replies', 'settings', 'engine'].includes(p3)) {
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 {