@ecency/render-helper 2.5.24 → 2.5.25

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.
@@ -1791,6 +1791,9 @@ function linkify(content, forApp, renderOptions) {
1791
1791
  const tag2 = tag.trim().substring(1);
1792
1792
  const tagLower = tag2.toLowerCase();
1793
1793
  if (!forApp) {
1794
+ if (renderOptions?.inertAuthorAndTagChips) {
1795
+ return `${preceding}<span class="er-tag er-tag-link">${tag.trim()}</span>`;
1796
+ }
1794
1797
  return `${preceding}<a class="er-tag er-tag-link" href="/trending/${tagLower}">${tag.trim()}</a>`;
1795
1798
  }
1796
1799
  return `${preceding}<a class="markdown-tag-link" data-tag="${tagLower}">${tag.trim()}</a>`;
@@ -1804,7 +1807,8 @@ function linkify(content, forApp, renderOptions) {
1804
1807
  if (userLower.indexOf("/") === -1 && isValidUsername(user)) {
1805
1808
  if (!forApp) {
1806
1809
  const avatarSrc = `${getProxyBase()}/u/${userLower}/avatar/small`;
1807
- const html = `${preceedings}<a class="er-author er-author-link" href="/@${userLower}"><img class="er-author-link-image" src="${avatarSrc}" alt="${userLower}"/>@${userLower}</a>`;
1810
+ const inner = `<img class="er-author-link-image" src="${avatarSrc}" alt="${userLower}"/>@${userLower}`;
1811
+ const html = renderOptions?.inertAuthorAndTagChips ? `${preceedings}<span class="er-author er-author-link">${inner}</span>` : `${preceedings}<a class="er-author er-author-link" href="/@${userLower}">${inner}</a>`;
1808
1812
  const placeholder = `\u200C${authorPlaceholders.length}\u200C`;
1809
1813
  authorPlaceholders.push({ placeholder, html });
1810
1814
  return placeholder;
@@ -1869,6 +1873,19 @@ function hasAncestor(node, tagNames) {
1869
1873
  }
1870
1874
  return false;
1871
1875
  }
1876
+ var CHIP_CLASSES = ["er-author-link", "er-tag-link"];
1877
+ function hasChipAncestor(node) {
1878
+ let current = node.parentNode;
1879
+ while (current) {
1880
+ const el = current;
1881
+ const className = typeof el.getAttribute === "function" ? el.getAttribute("class") : null;
1882
+ if (className && className.split(/\s+/).some((token) => CHIP_CLASSES.includes(token))) {
1883
+ return true;
1884
+ }
1885
+ current = current.parentNode;
1886
+ }
1887
+ return false;
1888
+ }
1872
1889
  function text(node, forApp, renderOptions) {
1873
1890
  if (!node || !node.parentNode) {
1874
1891
  return;
@@ -1876,8 +1893,11 @@ function text(node, forApp, renderOptions) {
1876
1893
  if (hasAncestor(node, ["a", "code", "pre"])) {
1877
1894
  return;
1878
1895
  }
1896
+ if (renderOptions?.inertAuthorAndTagChips && hasChipAncestor(node)) {
1897
+ return;
1898
+ }
1879
1899
  const nodeValue = node.nodeValue || "";
1880
- const linkified = linkify(nodeValue, forApp);
1900
+ const linkified = linkify(nodeValue, forApp, renderOptions);
1881
1901
  if (linkified !== nodeValue) {
1882
1902
  const doc = DOMParser.parseFromString(
1883
1903
  `<span class="wr">${linkified}</span>`,
@@ -1965,7 +1985,7 @@ function traverse(node, forApp, depth = 0, state = { firstImageFound: false }, p
1965
1985
  iframe(child, parentDomain, forApp, renderOptions);
1966
1986
  }
1967
1987
  if (child.nodeName === "#text") {
1968
- text(child, forApp);
1988
+ text(child, forApp, renderOptions);
1969
1989
  }
1970
1990
  if (child.nodeName.toLowerCase() === "img") {
1971
1991
  img(child, state, forApp);
@@ -2169,7 +2189,7 @@ function markdown2Html(obj, forApp = true, _webp = false, parentDomain = "ecency
2169
2189
  logIfSlow(performance.now() - t02, `body_len=${obj.length}`);
2170
2190
  return res2;
2171
2191
  }
2172
- const key = `${makeEntryCacheKey(obj)}-md-${forApp ? "app" : "site"}-${parentDomain}${seoContext ? `-seo${seoContext.authorReputation ?? ""}-${seoContext.postPayout ?? ""}` : ""}${renderOptions?.embedVideosDirectly ? "-embed" : ""}`;
2192
+ const key = `${makeEntryCacheKey(obj)}-md-${forApp ? "app" : "site"}-${parentDomain}${seoContext ? `-seo${seoContext.authorReputation ?? ""}-${seoContext.postPayout ?? ""}` : ""}${renderOptions?.embedVideosDirectly ? "-embed" : ""}${renderOptions?.inertAuthorAndTagChips ? "-inert" : ""}`;
2173
2193
  const item = cacheGet(key);
2174
2194
  if (item) {
2175
2195
  return item;