@ecency/render-helper 2.2.11 → 2.2.12
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/lib/consts/allowed-attributes.const.js +1 -0
- package/lib/consts/allowed-attributes.const.js.map +1 -1
- package/lib/consts/regexes.const.js +1 -1
- package/lib/consts/regexes.const.js.map +1 -1
- package/lib/helper.d.ts +1 -0
- package/lib/helper.js +13 -1
- package/lib/helper.js.map +1 -1
- package/lib/methods/a.method.js +11 -0
- package/lib/methods/a.method.js.map +1 -1
- package/lib/methods/text.method.js +6 -0
- package/lib/methods/text.method.js.map +1 -1
- package/lib/render-helper.js +1 -1
- package/package.json +1 -1
- package/src/consts/allowed-attributes.const.ts +1 -0
- package/src/consts/regexes.const.ts +1 -1
- package/src/helper.ts +11 -0
- package/src/markdown-2-html.spec.ts +14 -2
- package/src/methods/a.method.ts +16 -0
- package/src/methods/text.method.ts +7 -1
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@ export const INTERNAL_TOPIC_REGEX = /^\/(trending|hot|created|promoted|muted|pay
|
|
|
11
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
|
-
export const YOUTUBE_REGEX = /(?:
|
|
14
|
+
export const YOUTUBE_REGEX = /(?:youtube.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu.be\/)([^"&?\/\s]{11})/g
|
|
15
15
|
export const YOUTUBE_EMBED_REGEX = /^(https?:)?\/\/www.youtube.com\/(embed|shorts)\/.*/i
|
|
16
16
|
export const VIMEO_REGEX = /(https?:\/\/)?(www\.)?(?:vimeo)\.com.*(?:videos|video|channels|)\/([\d]+)/i
|
|
17
17
|
export const VIMEO_EMBED_REGEX = /https:\/\/player\.vimeo\.com\/video\/([0-9]+)/
|
package/src/helper.ts
CHANGED
|
@@ -14,3 +14,14 @@ export function makeEntryCacheKey(entry: any): string {
|
|
|
14
14
|
return `${entry.author}-${entry.permlink}-${entry.last_update}`
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
export function extractYtStartTime(url:string):string {
|
|
18
|
+
const urlObj = new URL(url);
|
|
19
|
+
const params = new URLSearchParams(urlObj.search);
|
|
20
|
+
if(params.has('t')){
|
|
21
|
+
return '' + parseInt(params.get('t')); //parsing is important as sometimes t is famated '123s';
|
|
22
|
+
}else if (params.has('start')){
|
|
23
|
+
return params.get('start');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return '';
|
|
27
|
+
}
|
|
@@ -445,9 +445,9 @@ describe('Markdown2Html', () => {
|
|
|
445
445
|
author: 'foo329',
|
|
446
446
|
permlink: 'bar329',
|
|
447
447
|
last_update: '2019-05-10T09:15:21',
|
|
448
|
-
body: 'https://youtu.be/
|
|
448
|
+
body: 'https://youtu.be/UuyS7YAkECA?t=295s'
|
|
449
449
|
}
|
|
450
|
-
const expected = '<p><a class="markdown-video-link markdown-video-link-youtube" data-embed-src="https://www.youtube.com/embed/
|
|
450
|
+
const expected = '<p><a class="markdown-video-link markdown-video-link-youtube" data-embed-src="https://www.youtube.com/embed/UuyS7YAkECA?autoplay=1" data-youtube="UuyS7YAkECA" data-start-time="295"><img class="no-replace video-thumbnail" src="https://images.ecency.com/p/S5Eokt4BcQdk7EHeT1aYjzebg2hC7hkthT45eAMp88bZ44hfAQDm6BtJw2H53aq1Tpn1cu4.png?format=match&mode=fit" /><span class="markdown-video-play"></span></a></p>'
|
|
451
451
|
|
|
452
452
|
expect(markdown2Html(input)).toBe(expected)
|
|
453
453
|
})
|
|
@@ -877,6 +877,18 @@ describe('Markdown2Html', () => {
|
|
|
877
877
|
|
|
878
878
|
expect(markdown2Html(input, false)).toBe(expected)
|
|
879
879
|
})
|
|
880
|
+
|
|
881
|
+
it('65- Should handle youtube.com/embed videos', () => {
|
|
882
|
+
const input = {
|
|
883
|
+
author: 'foo329',
|
|
884
|
+
permlink: 'bar329',
|
|
885
|
+
last_update: '2019-05-10T09:15:21',
|
|
886
|
+
body: 'https://www.youtube.com/embed/UuyS7YAkECA?start=295&autoplay=1'
|
|
887
|
+
}
|
|
888
|
+
const expected = '<p><a class="markdown-video-link markdown-video-link-youtube" data-embed-src="https://www.youtube.com/embed/UuyS7YAkECA?autoplay=1" data-youtube="UuyS7YAkECA" data-start-time="295"><img class="no-replace video-thumbnail" src="https://images.ecency.com/p/S5Eokt4BcQdk7EHeT1aYjzebg2hC7hkthT45eAMp88bZ44hfAQDm6BtJw2H53aq1Tpn1cu4.png?format=match&mode=fit" /><span class="markdown-video-play"></span></a></p>'
|
|
889
|
+
|
|
890
|
+
expect(markdown2Html(input)).toBe(expected)
|
|
891
|
+
})
|
|
880
892
|
})
|
|
881
893
|
|
|
882
894
|
describe("Rumble support", () => {
|
package/src/methods/a.method.ts
CHANGED
|
@@ -28,6 +28,7 @@ import {
|
|
|
28
28
|
import { getSerializedInnerHTML } from './get-inner-html.method'
|
|
29
29
|
import { proxifyImageSrc } from '../proxify-image-src'
|
|
30
30
|
import { removeChildNodes } from './remove-child-nodes.method'
|
|
31
|
+
import { extractYtStartTime } from '../helper'
|
|
31
32
|
|
|
32
33
|
export function a(el: HTMLElement, forApp: boolean, webp: boolean): void {
|
|
33
34
|
let href = el.getAttribute('href')
|
|
@@ -416,6 +417,12 @@ export function a(el: HTMLElement, forApp: boolean, webp: boolean): void {
|
|
|
416
417
|
el.setAttribute('data-embed-src', embedSrc);
|
|
417
418
|
el.setAttribute('data-youtube', vid);
|
|
418
419
|
|
|
420
|
+
//extract start time if available
|
|
421
|
+
const startTime = extractYtStartTime(href);
|
|
422
|
+
if(startTime){
|
|
423
|
+
el.setAttribute('data-start-time', startTime);
|
|
424
|
+
}
|
|
425
|
+
|
|
419
426
|
const thumbImg = el.ownerDocument.createElement('img')
|
|
420
427
|
thumbImg.setAttribute('class', 'no-replace video-thumbnail')
|
|
421
428
|
thumbImg.setAttribute('itemprop', 'thumbnailUrl')
|
|
@@ -671,6 +678,12 @@ export function a(el: HTMLElement, forApp: boolean, webp: boolean): void {
|
|
|
671
678
|
if (e[1]) {
|
|
672
679
|
const vid = e[1]
|
|
673
680
|
el.setAttribute('data-youtube', vid);
|
|
681
|
+
|
|
682
|
+
//extract start time if available
|
|
683
|
+
const startTime = extractYtStartTime(href);
|
|
684
|
+
if(startTime){
|
|
685
|
+
el.setAttribute('data-start-time', startTime);
|
|
686
|
+
}
|
|
674
687
|
}
|
|
675
688
|
}
|
|
676
689
|
el.removeAttribute('href')
|
|
@@ -684,3 +697,6 @@ export function a(el: HTMLElement, forApp: boolean, webp: boolean): void {
|
|
|
684
697
|
}
|
|
685
698
|
}
|
|
686
699
|
}
|
|
700
|
+
|
|
701
|
+
|
|
702
|
+
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { IMG_REGEX, YOUTUBE_REGEX, WHITE_LIST, DOMParser, POST_REGEX, } from '../consts'
|
|
2
|
+
import { extractYtStartTime } from '../helper'
|
|
2
3
|
import { proxifyImageSrc } from '../proxify-image-src'
|
|
3
4
|
import { linkify } from './linkify.method'
|
|
4
5
|
|
|
@@ -34,7 +35,12 @@ export function text(node: HTMLElement, forApp: boolean, webp: boolean): void {
|
|
|
34
35
|
const thumbnail = proxifyImageSrc(`https://img.youtube.com/vi/${vid.split('?')[0]}/hqdefault.jpg`, 0, 0, webp ? 'webp' : 'match')
|
|
35
36
|
const embedSrc = `https://www.youtube.com/embed/${vid}?autoplay=1`
|
|
36
37
|
|
|
37
|
-
|
|
38
|
+
let attrs = `class="markdown-video-link markdown-video-link-youtube" data-embed-src="${embedSrc}" data-youtube="${vid}"`
|
|
39
|
+
//extract start time if available
|
|
40
|
+
const startTime = extractYtStartTime(node.nodeValue);
|
|
41
|
+
if(startTime){
|
|
42
|
+
attrs = attrs.concat(` data-start-time="${startTime}"`);
|
|
43
|
+
}
|
|
38
44
|
|
|
39
45
|
const thumbImg = node.ownerDocument.createElement('img')
|
|
40
46
|
thumbImg.setAttribute('class', 'no-replace video-thumbnail')
|