@ecency/render-helper 2.2.0 → 2.2.1

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.0",
3
+ "version": "2.2.1",
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": "^5.1.1",
62
+ "lru-cache": "^6.0.0",
63
63
  "multihashes": "0.4.13",
64
64
  "path": "^0.12.7",
65
65
  "querystring": "^0.2.0",
@@ -17,6 +17,7 @@ export function cleanReply(s: string): string {
17
17
  .filter(item => item.includes('View this post <a href="https://travelfeed.io/') === false)
18
18
  .filter(item => item.includes('Read this post on TravelFeed.io for the best experience') === false)
19
19
  .filter(item => item.includes('Posted via <a href="https://www.dporn.co/"') === false)
20
+ .filter(item => item.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">![](https://i.imgur.com/XsrNmcl.png)</a></div>', '')
@@ -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) {
@@ -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
- for (let i = 0; i < arr.length; i++) {
12
- // join array with space separator
13
- if (result) {
14
- result += " ";
15
- }
16
- // break with length reaches limit
17
- if (result.length > limit) {
18
- break;
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 md = new Remarkable({
40
+ const mdd = new Remarkable({
37
41
  html: true,
38
42
  breaks: true,
39
- highlight: function (str: string) {
40
- try {
41
- const tokens = lolight.tok(str);
42
- return tokens.map(
43
- (token: string[]) => `<span class="ll-${token[0]}">${token[1]}</span>`
44
- ).join('')
45
- } catch (err) { console.error(err) }
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 = md.render(entryBody)
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
- text = he.decode(text) // decode html entities
80
+ if (text) {
81
+ text = he.decode(text) // decode html entities
82
+ }
66
83
 
67
84
  return text
68
85
  }