@ecency/render-helper 2.2.14 → 2.2.15
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/methods/a.method.js +16 -9
- package/lib/methods/a.method.js.map +1 -1
- package/lib/render-helper.js +1 -1
- package/package.json +1 -1
- package/src/markdown-2-html.spec.ts +24 -0
- package/src/methods/a.method.ts +24 -13
package/package.json
CHANGED
|
@@ -99,6 +99,30 @@ describe('Markdown2Html', () => {
|
|
|
99
99
|
expect(markdown2Html(input)).toBe(expected)
|
|
100
100
|
})
|
|
101
101
|
|
|
102
|
+
it('7.1- Should handle raw d.tube videos without thumbnail', () => {
|
|
103
|
+
const input = {
|
|
104
|
+
author: 'foo37.1',
|
|
105
|
+
permlink: 'bar37.1',
|
|
106
|
+
last_update: '2020-05-10T09:15:21',
|
|
107
|
+
body: 'https://d.tube/#!/v/techcoderx/QmVdEYicJwiTxSk2U9ER1Yc8Rumb1Nek4KynqAYGyQs7ga'
|
|
108
|
+
}
|
|
109
|
+
const expected = '<p><a class="markdown-video-link markdown-video-link-dtube" data-embed-src="https://emb.d.tube/#!/techcoderx/QmVdEYicJwiTxSk2U9ER1Yc8Rumb1Nek4KynqAYGyQs7ga"><span class="markdown-video-play"></span></a></p>'
|
|
110
|
+
|
|
111
|
+
expect(markdown2Html(input)).toBe(expected)
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
it('7.2- Should handle raw d.tube videos different format', () => {
|
|
115
|
+
const input = {
|
|
116
|
+
author: 'foo37.2',
|
|
117
|
+
permlink: 'bar37.2',
|
|
118
|
+
last_update: '2020-05-10T09:15:21',
|
|
119
|
+
body: 'https://d.tube/v/techcoderx/QmVdEYicJwiTxSk2U9ER1Yc8Rumb1Nek4KynqAYGyQs7ga'
|
|
120
|
+
}
|
|
121
|
+
const expected = '<p><a class="markdown-video-link markdown-video-link-dtube" data-embed-src="https://emb.d.tube/#!/techcoderx/QmVdEYicJwiTxSk2U9ER1Yc8Rumb1Nek4KynqAYGyQs7ga"><span class="markdown-video-play"></span></a></p>'
|
|
122
|
+
|
|
123
|
+
expect(markdown2Html(input)).toBe(expected)
|
|
124
|
+
})
|
|
125
|
+
|
|
102
126
|
it('9- Should handle witnesses links', () => {
|
|
103
127
|
const input = {
|
|
104
128
|
author: 'foo39',
|
package/src/methods/a.method.ts
CHANGED
|
@@ -539,37 +539,46 @@ export function a(el: HTMLElement, forApp: boolean, webp: boolean): void {
|
|
|
539
539
|
// If a d.tube video
|
|
540
540
|
match = href.match(D_TUBE_REGEX)
|
|
541
541
|
if (match) {
|
|
542
|
-
// Only d.tube links contains an image
|
|
543
|
-
const imgEls = el.getElementsByTagName('img')
|
|
544
542
|
|
|
545
|
-
|
|
543
|
+
// Only d.tube links contains an image
|
|
544
|
+
const imgEls = el.getElementsByTagName('img')
|
|
545
|
+
|
|
546
|
+
if (imgEls.length === 1 || el.textContent.trim() === href) {
|
|
546
547
|
const e = D_TUBE_REGEX.exec(href)
|
|
547
548
|
// e[2] = username, e[3] object id
|
|
548
549
|
if (e[2] && e[3]) {
|
|
549
550
|
el.setAttribute('class', 'markdown-video-link markdown-video-link-dtube')
|
|
550
551
|
el.removeAttribute('href')
|
|
552
|
+
|
|
551
553
|
|
|
552
|
-
const thumbnail = proxifyImageSrc(imgEls[0].getAttribute('src').replace(/\s+/g, ''), 0, 0, webp ? 'webp' : 'match')
|
|
553
554
|
const videoHref = `https://emb.d.tube/#!/${e[2]}/${e[3]}`
|
|
554
555
|
|
|
555
556
|
// el.setAttribute('data-video-href', videoHref)
|
|
556
557
|
el.setAttribute('data-embed-src', videoHref)
|
|
557
558
|
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
559
|
+
//process thumb img element
|
|
560
|
+
if (imgEls.length === 1) {
|
|
561
|
+
const thumbnail = proxifyImageSrc(imgEls[0].getAttribute('src').replace(/\s+/g, ''), 0, 0, webp ? 'webp' : 'match')
|
|
562
|
+
const thumbImg = el.ownerDocument.createElement('img')
|
|
563
|
+
|
|
564
|
+
thumbImg.setAttribute('class', 'no-replace video-thumbnail')
|
|
565
|
+
thumbImg.setAttribute('itemprop', 'thumbnailUrl')
|
|
566
|
+
|
|
567
|
+
thumbImg.setAttribute('src', thumbnail)
|
|
568
|
+
el.appendChild(thumbImg)
|
|
569
|
+
|
|
570
|
+
// Remove image.
|
|
571
|
+
el.removeChild(imgEls[0])
|
|
572
|
+
} else {
|
|
573
|
+
el.textContent = '';
|
|
574
|
+
}
|
|
563
575
|
|
|
564
576
|
const play = el.ownerDocument.createElement('span')
|
|
565
577
|
play.setAttribute('class', 'markdown-video-play')
|
|
566
578
|
|
|
567
|
-
|
|
579
|
+
|
|
568
580
|
el.appendChild(play)
|
|
569
581
|
|
|
570
|
-
// Remove image.
|
|
571
|
-
el.removeChild(imgEls[0])
|
|
572
|
-
|
|
573
582
|
return
|
|
574
583
|
}
|
|
575
584
|
}
|
|
@@ -581,6 +590,7 @@ export function a(el: HTMLElement, forApp: boolean, webp: boolean): void {
|
|
|
581
590
|
if (e[2] && e[3]) {
|
|
582
591
|
el.setAttribute('class', 'markdown-video-link markdown-video-link-dtube')
|
|
583
592
|
el.removeAttribute('href')
|
|
593
|
+
el.textContent = '';
|
|
584
594
|
|
|
585
595
|
const videoHref = `https://emb.d.tube/#!/${e[2]}/${e[3]}`
|
|
586
596
|
|
|
@@ -590,6 +600,7 @@ export function a(el: HTMLElement, forApp: boolean, webp: boolean): void {
|
|
|
590
600
|
play.setAttribute('class', 'markdown-video-play')
|
|
591
601
|
|
|
592
602
|
el.appendChild(play)
|
|
603
|
+
|
|
593
604
|
|
|
594
605
|
return
|
|
595
606
|
}
|