@ecency/render-helper 2.2.0 → 2.2.4
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/regexes.const.d.ts +1 -0
- package/lib/consts/regexes.const.js +2 -1
- package/lib/consts/regexes.const.js.map +1 -1
- package/lib/methods/a.method.js +2 -2
- package/lib/methods/a.method.js.map +1 -1
- package/lib/methods/clean-reply.method.js +18 -17
- package/lib/methods/clean-reply.method.js.map +1 -1
- package/lib/methods/iframe.method.js +6 -0
- package/lib/methods/iframe.method.js.map +1 -1
- package/lib/methods/markdown-to-html.method.js +14 -0
- package/lib/methods/markdown-to-html.method.js.map +1 -1
- package/lib/post-body-summary.js +46 -29
- package/lib/post-body-summary.js.map +1 -1
- package/lib/render-helper.js +1 -1
- package/package.json +2 -2
- package/src/consts/regexes.const.ts +1 -0
- package/src/markdown-2-html.spec.ts +13 -1
- package/src/methods/a.method.ts +2 -2
- package/src/methods/clean-reply.method.ts +18 -17
- package/src/methods/iframe.method.ts +8 -1
- package/src/methods/markdown-to-html.method.ts +14 -0
- package/src/post-body-summary.ts +44 -27
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ecency/render-helper",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.4",
|
|
4
4
|
"description": "Markdown+Html Render helper",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"dependencies": {
|
|
60
60
|
"he": "^1.2.0",
|
|
61
61
|
"lolight": "^1.4.0",
|
|
62
|
-
"lru-cache": "^
|
|
62
|
+
"lru-cache": "^6.0.0",
|
|
63
63
|
"multihashes": "0.4.13",
|
|
64
64
|
"path": "^0.12.7",
|
|
65
65
|
"querystring": "^0.2.0",
|
|
@@ -38,3 +38,4 @@ export const TWITCH_EMBED_REGEX = /^(https?:)?\/\/player.twitch.tv\/.*/i
|
|
|
38
38
|
export const BRAND_NEW_TUBE_REGEX = /^https:\/\/brandnewtube\.com\/embed\/[a-z0-9]+$/i
|
|
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
|
+
export const AUREAL_EMBED_REGEX = /^(https?:\/\/)?(www\.)?(?:aureal-embed)\.web\.app\/([0-9]+)/i
|
|
@@ -805,6 +805,18 @@ describe('Markdown2Html', () => {
|
|
|
805
805
|
const expected = '<p><strong>It\'s a Secret, But is it good to have secrets?</strong><br /><a data-tag=\"hive-123046\" data-author=\"ecotrain\" data-permlink=\"ecotrain-question-of-the-week-season-5-1tie-up-post-it-s-a-secret-but-is-it-good-to-have-secrets\" class=\"markdown-post-link\">/@ecotrain/ecotrain-question-of-the-week-season-5-1tie-up-post-it-s-a-secret-but-is-it-good-to-have-secrets</a></p>'
|
|
806
806
|
expect(markdown2Html(input)).toBe(expected)
|
|
807
807
|
})
|
|
808
|
+
|
|
809
|
+
it('59 - Should handle Aureal iframe', () => {
|
|
810
|
+
const input = {
|
|
811
|
+
author: 'foo359',
|
|
812
|
+
permlink: 'bar359',
|
|
813
|
+
last_update: '2021-10-23T09:15:21',
|
|
814
|
+
body: 'this is link <iframe loading="lazy" src="https://aureal-embed.web.app/535939" width="100%" height="200" frameborder="0" data-rocket-lazyload="fitvidscompatible" class="lazyloaded" data-ll-status="loaded"></iframe>'
|
|
815
|
+
}
|
|
816
|
+
const expected = '<p>this is link <iframe src=\"https://aureal-embed.web.app/535939\" frameborder=\"0\" class=\"lazyloaded\"></iframe></p>'
|
|
817
|
+
|
|
818
|
+
expect(markdown2Html(input)).toBe(expected)
|
|
819
|
+
})
|
|
808
820
|
})
|
|
809
821
|
|
|
810
822
|
describe("Rumble support", () => {
|
|
@@ -832,7 +844,7 @@ describe('Markdown2Html', () => {
|
|
|
832
844
|
expect(markdown2Html(input)).toBe(expected)
|
|
833
845
|
})
|
|
834
846
|
|
|
835
|
-
// The following
|
|
847
|
+
// The following cannot be done: Convert URLs to the video page like this one
|
|
836
848
|
// (https://rumble.com/vkhkzl-helping-my-girls-to-cool-down-in-the-heat.html)
|
|
837
849
|
// to its corresponding embedded URL (https://rumble.com/embed/vhveub/?pub=4).
|
|
838
850
|
// The relationship seems to be governed by a table.
|
package/src/methods/a.method.ts
CHANGED
|
@@ -138,7 +138,7 @@ export function a(el: HTMLElement, forApp: boolean, webp: boolean): void {
|
|
|
138
138
|
if (
|
|
139
139
|
(tpostMatch && WHITE_LIST.includes(tpostMatch[1].substring(1))) || (tpostMatch && tpostMatch.length === 4 && tpostMatch[1].indexOf('/') !== 0)
|
|
140
140
|
) {
|
|
141
|
-
if (['wallet', 'feed', 'followers', 'following', 'points', 'communities', 'posts', 'blog', 'comments', 'replies', 'settings'].includes(tpostMatch[3])) {
|
|
141
|
+
if (['wallet', 'feed', 'followers', 'following', 'points', 'communities', 'posts', 'blog', 'comments', 'replies', 'settings', 'engine'].includes(tpostMatch[3])) {
|
|
142
142
|
el.setAttribute('class', 'markdown-profile-link')
|
|
143
143
|
const author = tpostMatch[2].replace('@', '').toLowerCase()
|
|
144
144
|
const section = tpostMatch[3]
|
|
@@ -205,7 +205,7 @@ export function a(el: HTMLElement, forApp: boolean, webp: boolean): void {
|
|
|
205
205
|
if (
|
|
206
206
|
(cpostMatch && cpostMatch.length === 3 && cpostMatch[1].indexOf('@') === 0)
|
|
207
207
|
) {
|
|
208
|
-
if (['wallet', 'feed', 'followers', 'following', 'points', 'communities', 'posts', 'blog', 'comments', 'replies', 'settings'].includes(cpostMatch[2])) {
|
|
208
|
+
if (['wallet', 'feed', 'followers', 'following', 'points', 'communities', 'posts', 'blog', 'comments', 'replies', 'settings', 'engine'].includes(cpostMatch[2])) {
|
|
209
209
|
el.setAttribute('class', 'markdown-profile-link')
|
|
210
210
|
const author = cpostMatch[1].replace('@', '').toLowerCase()
|
|
211
211
|
const section = cpostMatch[2]
|
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
export function cleanReply(s: string): string {
|
|
2
2
|
return (s ? s.split('\n')
|
|
3
|
-
.filter(item => item.includes('
|
|
4
|
-
.filter(item => item.includes('
|
|
5
|
-
.filter(item => item.includes('
|
|
6
|
-
.filter(item => item.includes('
|
|
7
|
-
.filter(item => item.includes('
|
|
8
|
-
.filter(item => item.includes('
|
|
9
|
-
.filter(item => item.includes('<center><sub>[
|
|
10
|
-
.filter(item => item.includes('<center><sub>
|
|
11
|
-
.filter(item => item.includes('<center>
|
|
12
|
-
.filter(item => item.includes('<center><sub>
|
|
13
|
-
.filter(item => item.includes('<center>
|
|
14
|
-
.filter(item => item.includes('<center><sub>
|
|
15
|
-
.filter(item => item.includes('
|
|
16
|
-
.filter(item => item.includes('<center><em>
|
|
17
|
-
.filter(item => item.includes('
|
|
18
|
-
.filter(item => item.includes('
|
|
19
|
-
.filter(item => item.includes('
|
|
3
|
+
.filter(item => item.toLowerCase().includes('posted using [partiko') === false)
|
|
4
|
+
.filter(item => item.toLowerCase().includes('posted using [dapplr') === false)
|
|
5
|
+
.filter(item => item.toLowerCase().includes('posted using [leofinance') === false)
|
|
6
|
+
.filter(item => item.toLowerCase().includes('posted via [neoxian') === false)
|
|
7
|
+
.filter(item => item.toLowerCase().includes('posted with [stemgeeks') === false)
|
|
8
|
+
.filter(item => item.toLowerCase().includes('posted using [bilpcoin') === false)
|
|
9
|
+
.filter(item => item.toLowerCase().includes('<center><sub>[posted using aeneas.blog') === false)
|
|
10
|
+
.filter(item => item.toLowerCase().includes('<center><sub>posted via [proofofbrain.io') === false)
|
|
11
|
+
.filter(item => item.toLowerCase().includes('<center>posted on [hypnochain') === false)
|
|
12
|
+
.filter(item => item.toLowerCase().includes('<center><sub>posted via [weedcash.network') === false)
|
|
13
|
+
.filter(item => item.toLowerCase().includes('<center>posted on [naturalmedicine.io') === false)
|
|
14
|
+
.filter(item => item.toLowerCase().includes('<center><sub>posted via [musicforlife.io') === false)
|
|
15
|
+
.filter(item => item.toLowerCase().includes('if the truvvl embed is unsupported by your current frontend, click this link to view this story') === false)
|
|
16
|
+
.filter(item => item.toLowerCase().includes('<center><em>posted from truvvl') === false)
|
|
17
|
+
.filter(item => item.toLowerCase().includes('view this post <a href="https://travelfeed.io/') === false)
|
|
18
|
+
.filter(item => item.toLowerCase().includes('read this post on travelfeed.io for the best experience') === false)
|
|
19
|
+
.filter(item => item.toLowerCase().includes('posted via <a href="https://www.dporn.co/"') === false)
|
|
20
|
+
.filter(item => item.toLowerCase().includes('▶️ [watch on 3speak](https://3speak') === false)
|
|
20
21
|
.join('\n') : '')
|
|
21
22
|
.replace('Posted via <a href="https://d.buzz" data-link="promote-link">D.Buzz</a>', '')
|
|
22
23
|
.replace('<div class="pull-right"><a href="/@hive.engage"></a></div>', '')
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ARCH_REGEX, DAPPLR_REGEX, LBRY_REGEX, TRUVVL_REGEX, ODYSEE_REGEX, BITCHUTE_REGEX, RUMBLE_REGEX, BRIGHTEON_REGEX, VIMEO_EMBED_REGEX, SPEAK_EMBED_REGEX, VIMM_EMBED_REGEX, D_TUBE_EMBED_REGEX, SPOTIFY_EMBED_REGEX, SOUNDCLOUD_EMBED_REGEX, TWITCH_EMBED_REGEX, YOUTUBE_EMBED_REGEX, BRAND_NEW_TUBE_REGEX, LOOM_EMBED_REGEX } from '../consts'
|
|
1
|
+
import { ARCH_REGEX, DAPPLR_REGEX, LBRY_REGEX, TRUVVL_REGEX, ODYSEE_REGEX, BITCHUTE_REGEX, RUMBLE_REGEX, BRIGHTEON_REGEX, VIMEO_EMBED_REGEX, SPEAK_EMBED_REGEX, VIMM_EMBED_REGEX, D_TUBE_EMBED_REGEX, SPOTIFY_EMBED_REGEX, SOUNDCLOUD_EMBED_REGEX, TWITCH_EMBED_REGEX, YOUTUBE_EMBED_REGEX, BRAND_NEW_TUBE_REGEX, LOOM_EMBED_REGEX, AUREAL_EMBED_REGEX } from '../consts'
|
|
2
2
|
|
|
3
3
|
export function iframe(el: HTMLElement): void {
|
|
4
4
|
const src = el.getAttribute('src')
|
|
@@ -145,6 +145,13 @@ export function iframe(el: HTMLElement): void {
|
|
|
145
145
|
return;
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
+
// Aureal
|
|
149
|
+
if (src.match(AUREAL_EMBED_REGEX)) {
|
|
150
|
+
el.setAttribute('src', src)
|
|
151
|
+
el.setAttribute('frameborder', '0')
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
|
|
148
155
|
const replaceNode = el.ownerDocument.createElement('div')
|
|
149
156
|
replaceNode.setAttribute('class', 'unsupported-iframe')
|
|
150
157
|
replaceNode.textContent = `(Unsupported ${src})`
|
|
@@ -24,6 +24,20 @@ export function markdownToHTML(input: string, forApp: boolean, webp: boolean): s
|
|
|
24
24
|
return str
|
|
25
25
|
}
|
|
26
26
|
}).use(linkify)
|
|
27
|
+
md.core.ruler.enable([
|
|
28
|
+
'abbr'
|
|
29
|
+
]);
|
|
30
|
+
md.block.ruler.enable([
|
|
31
|
+
'footnote',
|
|
32
|
+
'deflist'
|
|
33
|
+
]);
|
|
34
|
+
md.inline.ruler.enable([
|
|
35
|
+
'footnote_inline',
|
|
36
|
+
'ins',
|
|
37
|
+
'mark',
|
|
38
|
+
'sub',
|
|
39
|
+
'sup'
|
|
40
|
+
]);
|
|
27
41
|
const XMLSerializer = new xmldom.XMLSerializer()
|
|
28
42
|
|
|
29
43
|
if (!input) {
|
package/src/post-body-summary.ts
CHANGED
|
@@ -2,26 +2,29 @@ import he from 'he'
|
|
|
2
2
|
import { makeEntryCacheKey } from './helper'
|
|
3
3
|
import { cacheGet, cacheSet } from './cache'
|
|
4
4
|
import { Entry } from './types'
|
|
5
|
+
import { cleanReply } from './methods'
|
|
5
6
|
|
|
6
|
-
const lolight = require('lolight')
|
|
7
7
|
const { Remarkable } = require('remarkable')
|
|
8
|
+
const { linkify } = require('remarkable/linkify')
|
|
8
9
|
|
|
9
10
|
const joint = (arr: string[], limit = 200) => {
|
|
10
11
|
let result = '';
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
result
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
} else {
|
|
20
|
-
// make sure last join doesn't break the limit too much
|
|
21
|
-
if ((result + arr[i]).length < limit + 10) {
|
|
22
|
-
result += arr[i];
|
|
23
|
-
} else {
|
|
12
|
+
if (arr) {
|
|
13
|
+
for (let i = 0; i < arr.length; i++) {
|
|
14
|
+
// join array with space separator
|
|
15
|
+
if (result) {
|
|
16
|
+
result += " ";
|
|
17
|
+
}
|
|
18
|
+
// break with length reaches limit
|
|
19
|
+
if (result.length > limit) {
|
|
24
20
|
break;
|
|
21
|
+
} else {
|
|
22
|
+
// make sure last join doesn't break the limit too much
|
|
23
|
+
if ((result + arr[i]).length < limit + 10) {
|
|
24
|
+
result += arr[i];
|
|
25
|
+
} else {
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
25
28
|
}
|
|
26
29
|
}
|
|
27
30
|
}
|
|
@@ -32,23 +35,35 @@ function postBodySummary(entryBody: string, length?: number): string {
|
|
|
32
35
|
if (!entryBody) {
|
|
33
36
|
return ''
|
|
34
37
|
}
|
|
38
|
+
entryBody = cleanReply(entryBody)
|
|
35
39
|
|
|
36
|
-
const
|
|
40
|
+
const mdd = new Remarkable({
|
|
37
41
|
html: true,
|
|
38
42
|
breaks: true,
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
typographer: false,
|
|
44
|
+
}).use(linkify)
|
|
45
|
+
mdd.core.ruler.enable([
|
|
46
|
+
'abbr'
|
|
47
|
+
]);
|
|
48
|
+
mdd.block.ruler.enable([
|
|
49
|
+
'footnote',
|
|
50
|
+
'deflist'
|
|
51
|
+
]);
|
|
52
|
+
mdd.inline.ruler.enable([
|
|
53
|
+
'footnote_inline',
|
|
54
|
+
'ins',
|
|
55
|
+
'mark',
|
|
56
|
+
'sub',
|
|
57
|
+
'sup'
|
|
58
|
+
]);
|
|
46
59
|
|
|
47
|
-
return str
|
|
48
|
-
}
|
|
49
|
-
})
|
|
50
60
|
// Convert markdown to html
|
|
51
|
-
let text =
|
|
61
|
+
let text = '';
|
|
62
|
+
try {
|
|
63
|
+
text = mdd.render(entryBody)
|
|
64
|
+
} catch (err) {
|
|
65
|
+
console.log(err)
|
|
66
|
+
}
|
|
52
67
|
|
|
53
68
|
text = text
|
|
54
69
|
.replace(/(<([^>]+)>)/gi, '') // Remove html tags
|
|
@@ -62,7 +77,9 @@ function postBodySummary(entryBody: string, length?: number): string {
|
|
|
62
77
|
text = joint(text.split(' '), length)
|
|
63
78
|
}
|
|
64
79
|
|
|
65
|
-
|
|
80
|
+
if (text) {
|
|
81
|
+
text = he.decode(text) // decode html entities
|
|
82
|
+
}
|
|
66
83
|
|
|
67
84
|
return text
|
|
68
85
|
}
|