@ecency/render-helper 2.4.31 → 2.4.33

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.
@@ -4,10 +4,10 @@ import multihash from 'multihashes';
4
4
  import querystring from 'querystring';
5
5
  import { Remarkable } from 'remarkable';
6
6
  import { linkify as linkify$1 } from 'remarkable/linkify';
7
- import he2 from 'he';
8
7
  import * as htmlparser2 from 'htmlparser2';
9
8
  import * as domSerializerModule from 'dom-serializer';
10
9
  import { LRUCache } from 'lru-cache';
10
+ import he from 'he';
11
11
 
12
12
  // src/consts/white-list.const.ts
13
13
  var WHITE_LIST = [
@@ -168,17 +168,13 @@ var ALLOWED_ATTRIBUTES = {
168
168
  "del": [],
169
169
  "ins": []
170
170
  };
171
- var lenientErrorHandler = (level, msg, context) => {
172
- if (process.env.NODE_ENV === "development") {
173
- console.warn("[DOMParser]", level, msg);
174
- }
175
- return void 0;
176
- };
177
- var DOMParser = new DOMParser$1({
178
- // Use onError instead of deprecated errorHandler
179
- // By providing a non-throwing error handler, parsing continues despite malformed HTML
180
- onError: lenientErrorHandler
181
- });
171
+ function createParser() {
172
+ return new DOMParser$1({
173
+ onError(level, msg) {
174
+ }
175
+ });
176
+ }
177
+ var DOMParser = createParser();
182
178
 
183
179
  // src/helper.ts
184
180
  function removeDuplicateAttributes(html) {
@@ -256,6 +252,8 @@ function isValidUsername(username) {
256
252
  !label.includes("..");
257
253
  });
258
254
  }
255
+
256
+ // src/methods/get-inner-html.method.ts
259
257
  function getSerializedInnerHTML(node) {
260
258
  const serializer = new XMLSerializer();
261
259
  if (node.childNodes[0]) {
@@ -1592,8 +1590,7 @@ function markdownToHTML(input, forApp, parentDomain = "ecency.com", seoContext,
1592
1590
  traverse(doc, forApp, 0, { firstImageFound: false }, parentDomain, seoContext, renderOptions);
1593
1591
  output = serializer.serializeToString(doc);
1594
1592
  } catch (fallbackError) {
1595
- const escapedContent = he2.encode(output || md.render(input));
1596
- output = `<p dir="auto">${escapedContent}</p>`;
1593
+ output = sanitizeHtml(output || md.render(input));
1597
1594
  }
1598
1595
  }
1599
1596
  if (forApp && output && entityPlaceholders.length > 0) {
@@ -1602,7 +1599,7 @@ function markdownToHTML(input, forApp, parentDomain = "ecency.com", seoContext,
1602
1599
  output = output.split(placeholder).join(entity);
1603
1600
  });
1604
1601
  }
1605
- output = output.replace(/ xmlns="http:\/\/www.w3.org\/1999\/xhtml"/g, "").replace('<body id="root">', "").replace("</body>", "").trim();
1602
+ output = output.replace(/ xmlns="http:\/\/www.w3.org\/1999\/xhtml"/g, "").replace(/^<\?xml[^?]*\?>/, "").replace(/^<!DOCTYPE[^>]*>/i, "").replace(/<\/?html[^>]*>/g, "").replace(/<head[^>]*>[\s\S]*?<\/head>/g, "").replace('<body id="root">', "").replace("</body>", "").trim();
1606
1603
  return sanitizeHtml(output);
1607
1604
  }
1608
1605
  var mdInstance = null;
@@ -1664,7 +1661,7 @@ function getImage(entry, width = 0, height = 0, format = "match") {
1664
1661
  }
1665
1662
  }
1666
1663
  if (meta && typeof meta.image === "string" && meta.image.length > 0) {
1667
- const decodedImage = he2.decode(meta.image);
1664
+ const decodedImage = he.decode(meta.image);
1668
1665
  if (isGifLink(decodedImage)) {
1669
1666
  return proxifyImageSrc(decodedImage, 0, 0, format);
1670
1667
  }
@@ -1672,7 +1669,7 @@ function getImage(entry, width = 0, height = 0, format = "match") {
1672
1669
  }
1673
1670
  if (meta && meta.image && !!meta.image.length && meta.image[0]) {
1674
1671
  if (typeof meta.image[0] === "string") {
1675
- const decodedImage = he2.decode(meta.image[0]);
1672
+ const decodedImage = he.decode(meta.image[0]);
1676
1673
  if (isGifLink(decodedImage)) {
1677
1674
  return proxifyImageSrc(decodedImage, 0, 0, format);
1678
1675
  }
@@ -1694,7 +1691,7 @@ function getImage(entry, width = 0, height = 0, format = "match") {
1694
1691
  if (!src) {
1695
1692
  return null;
1696
1693
  }
1697
- const decodedSrc = he2.decode(src);
1694
+ const decodedSrc = he.decode(src);
1698
1695
  if (isGifLink(decodedSrc)) {
1699
1696
  return proxifyImageSrc(decodedSrc, 0, 0, format);
1700
1697
  }
@@ -1715,7 +1712,7 @@ function catchPostImage(obj, width = 0, height = 0, format = "match") {
1715
1712
  if (!src) {
1716
1713
  return null;
1717
1714
  }
1718
- const decodedSrc = he2.decode(src);
1715
+ const decodedSrc = he.decode(src);
1719
1716
  if (isGifLink(decodedSrc)) {
1720
1717
  return proxifyImageSrc(decodedSrc, 0, 0, format);
1721
1718
  }
@@ -1808,7 +1805,7 @@ function postBodySummary(entryBody, length = 200, platform = "web") {
1808
1805
  text2 = joint(text2.split(" "), length);
1809
1806
  }
1810
1807
  if (text2) {
1811
- text2 = he2.decode(text2);
1808
+ text2 = he.decode(text2);
1812
1809
  }
1813
1810
  return text2;
1814
1811
  }