@ecency/render-helper 2.3.14 → 2.3.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.3.14",
3
+ "version": "2.3.16",
4
4
  "description": "Markdown+Html Render helper",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -424,7 +424,7 @@ describe('Markdown2Html', () => {
424
424
  last_update: '2019-05-10T09:15:21',
425
425
  body: '[![](https://img.3speakcontent.online/xrhjxocx/post.png?v2)](https://3speak.online/watch?v=wehmoen/xrhjxocx)'
426
426
  }
427
- const expected = '<p dir=\"auto\"><a class="markdown-video-link markdown-video-link-speak" data-embed-src="https://3speak.online/embed?v=wehmoen/xrhjxocx"><img class="no-replace video-thumbnail" itemprop="image" src="https://images.ecency.com/p/2ufhwNgM3qHKBGVeU2TMMqPBjdB17MRuf4Q7vGrmGMtTn6yFtvW3Lt9t5v1c3so7UFhWDYh9B.png?format=match&amp;mode=fit" loading="eager" fetchpriority="high" /><span class="markdown-video-play"></span></a></p>'
427
+ const expected = '<p dir=\"auto\"><a class="markdown-video-link markdown-video-link-speak" data-embed-src="https://3speak.tv/embed?v=wehmoen/xrhjxocx"><img class="no-replace video-thumbnail" itemprop="image" src="https://images.ecency.com/p/2ufhwNgM3qHKBGVeU2TMMqPBjdB17MRuf4Q7vGrmGMtTn6yFtvW3Lt9t5v1c3so7UFhWDYh9B.png?format=match&amp;mode=fit" loading="eager" fetchpriority="high" /><span class="markdown-video-play"></span></a></p>'
428
428
 
429
429
  expect(markdown2Html(input)).toBe(expected)
430
430
  })
@@ -436,7 +436,7 @@ describe('Markdown2Html', () => {
436
436
  last_update: '2029-05-10T09:15:21',
437
437
  body: '[![](https://img.3speakcontent.co/blnmdkjt/post.png)](https://3speak.co/watch?v=theycallmedan/blnmdkjt) [Watch on 3Speak](https://3speak.co/watch?v=theycallmedan/blnmdkjt)'
438
438
  }
439
- const expected = '<p dir=\"auto\"><a class="markdown-video-link markdown-video-link-speak" data-embed-src="https://3speak.co/embed?v=theycallmedan/blnmdkjt"><img class="no-replace video-thumbnail" itemprop="image" src="https://images.ecency.com/p/CQdwDW6BZfWWtctopKyTJuDRdBH4KXwm9ijE6sZXe5MveWF3nUu4zXXBFUau8NS.png?format=match&amp;mode=fit" loading="eager" fetchpriority="high" /><span class="markdown-video-play"></span></a> <a class="markdown-external-link" data-href="https://3speak.co/watch?v=theycallmedan/blnmdkjt">Watch on 3Speak</a></p>'
439
+ const expected = '<p dir=\"auto\"><a class="markdown-video-link markdown-video-link-speak" data-embed-src="https://3speak.tv/embed?v=theycallmedan/blnmdkjt"><img class="no-replace video-thumbnail" itemprop="image" src="https://images.ecency.com/p/CQdwDW6BZfWWtctopKyTJuDRdBH4KXwm9ijE6sZXe5MveWF3nUu4zXXBFUau8NS.png?format=match&amp;mode=fit" loading="eager" fetchpriority="high" /><span class="markdown-video-play"></span></a> <a class="markdown-external-link" data-href="https://3speak.co/watch?v=theycallmedan/blnmdkjt">Watch on 3Speak</a></p>'
440
440
 
441
441
  expect(markdown2Html(input)).toBe(expected)
442
442
  })
@@ -501,6 +501,18 @@ describe('Markdown2Html', () => {
501
501
  expect(markdown2Html(input)).toBe(expected)
502
502
  })
503
503
 
504
+ it('32b - Should treat titled Hive links as non-inline', () => {
505
+ const input = {
506
+ author: 'foo33436',
507
+ permlink: 'bar32436',
508
+ last_update: '2019-05-10T09:15:21',
509
+ body: '[Waves mobile app](https://ecency.com/hive-125125/@ecency/waves-mobile-app-update-explore "https://ecency.com/hive-125125/@ecency/waves-mobile-app-update-explore")'
510
+ }
511
+ const expected = '<p dir=\"auto\"><a title=\"https://ecency.com/hive-125125/@ecency/waves-mobile-app-update-explore\" class=\"markdown-post-link\" data-href=\"https://ecency.com/hive-125125/@ecency/waves-mobile-app-update-explore\" data-is-inline=\"false\" data-tag=\"hive-125125\" data-author=\"ecency\" data-permlink=\"waves-mobile-app-update-explore\">Waves mobile app</a></p>'
512
+
513
+ expect(markdown2Html(input)).toBe(expected)
514
+ })
515
+
504
516
  it('33- Should handle whitelisted user links', () => {
505
517
  const input = {
506
518
  author: 'foo334352',
@@ -33,6 +33,27 @@ import { removeChildNodes } from './remove-child-nodes.method'
33
33
  import { extractYtStartTime, isValidPermlink, isValidUsername } from '../helper'
34
34
  import { createImageHTML } from "./img.method";
35
35
 
36
+ const normalizeValue = (value?: string | null): string => (value ? value.trim() : '')
37
+
38
+ const matchesHref = (href: string, value?: string | null): boolean => {
39
+ const normalizedHref = normalizeValue(href)
40
+ if (!normalizedHref) {
41
+ return false
42
+ }
43
+
44
+ return normalizeValue(value) === normalizedHref
45
+ }
46
+
47
+ const getInlineMeta = (el: HTMLElement, href: string) => {
48
+ const textMatches = matchesHref(href, el.textContent)
49
+ const titleMatches = matchesHref(href, el.getAttribute('title'))
50
+
51
+ return {
52
+ textMatches,
53
+ nonInline: textMatches || titleMatches
54
+ }
55
+ }
56
+
36
57
 
37
58
  export function a(el: HTMLElement | null, forApp: boolean, webp: boolean): void {
38
59
  if (!el || !el.parentNode) {
@@ -107,11 +128,11 @@ export function a(el: HTMLElement | null, forApp: boolean, webp: boolean): void
107
128
 
108
129
  if (!isValidPermlink(permlink)) return;
109
130
 
110
- let isInline = true;
111
- if (el.textContent === href) {
131
+ const inlineMeta = getInlineMeta(el, href)
132
+ if (inlineMeta.textMatches) {
112
133
  el.textContent = `@${author}/${permlink}`
113
- isInline = false;
114
134
  }
135
+ const isInline = !inlineMeta.nonInline
115
136
  if (forApp) {
116
137
  el.removeAttribute('href')
117
138
 
@@ -195,11 +216,11 @@ export function a(el: HTMLElement | null, forApp: boolean, webp: boolean): void
195
216
 
196
217
  if (!isValidPermlink(permlink)) return;
197
218
 
198
- let isInline = true;
199
- if (el.textContent === href) {
219
+ const inlineMeta = getInlineMeta(el, href)
220
+ if (inlineMeta.textMatches) {
200
221
  el.textContent = `@${author}/${permlink}`
201
- isInline = false;
202
222
  }
223
+ const isInline = !inlineMeta.nonInline
203
224
  if (forApp) {
204
225
  el.removeAttribute('href')
205
226
 
@@ -274,12 +295,12 @@ export function a(el: HTMLElement | null, forApp: boolean, webp: boolean): void
274
295
 
275
296
  if (!isValidPermlink(permlink)) return;
276
297
 
277
- let isInline = true;
298
+ const inlineMeta = getInlineMeta(el, href)
278
299
 
279
- if (el.textContent === href) {
300
+ if (inlineMeta.textMatches) {
280
301
  el.textContent = `@${author}/${permlink}`
281
- isInline = false;
282
302
  }
303
+ const isInline = !inlineMeta.nonInline
283
304
  if (forApp) {
284
305
  el.removeAttribute('href')
285
306
 
@@ -380,12 +401,12 @@ export function a(el: HTMLElement | null, forApp: boolean, webp: boolean): void
380
401
 
381
402
  if (!isValidPermlink(permlink)) return;
382
403
 
383
- let isInline = true;
404
+ const inlineMeta = getInlineMeta(el, href)
384
405
 
385
- if (el.textContent === href) {
406
+ if (inlineMeta.textMatches) {
386
407
  el.textContent = `@${author}/${permlink}`
387
- isInline = false;
388
408
  }
409
+ const isInline = !inlineMeta.nonInline
389
410
  if (forApp) {
390
411
  el.removeAttribute('href')
391
412
 
@@ -669,9 +690,9 @@ export function a(el: HTMLElement | null, forApp: boolean, webp: boolean): void
669
690
  const imgEls = el.getElementsByTagName('img')
670
691
  if (imgEls.length === 1 || el.textContent.trim() === href) {
671
692
  const e = SPEAK_REGEX.exec(href)
672
- // e[1] = tld , e[3] = embed address
673
- if (e[1] && e[3]) {
674
- const videoHref = `https://3speak.${e[1]}/embed?v=${e[3]}`
693
+ // e[1] / e[2] = tld , e[3] = embed address
694
+ if ((e[1] || e[2]) && e[3]) {
695
+ const videoHref = `https://3speak.tv/embed?v=${e[3]}`
675
696
  el.setAttribute('class', 'markdown-video-link markdown-video-link-speak')
676
697
  el.removeAttribute('href')
677
698
  el.setAttribute('data-embed-src', videoHref)
@@ -40,7 +40,11 @@ export function iframe(el: HTMLElement | null): void {
40
40
 
41
41
  // 3Speak
42
42
  if (src.match(SPEAK_EMBED_REGEX)) {
43
- const s = `${src}&autoplay=true`;
43
+ const normalizedSrc = src.replace(/3speak\.[a-z]+/i, '3speak.tv');
44
+ const hasAutoplay = /[?&]autoplay=/.test(normalizedSrc);
45
+ const s = hasAutoplay
46
+ ? normalizedSrc
47
+ : `${normalizedSrc}${normalizedSrc.includes('?') ? '&' : '?'}autoplay=true`;
44
48
  el.setAttribute('src', s);
45
49
  return;
46
50
  }