Patch: Fix too-long code in comment previews via appropriate truncation (#19540)

* Fix too-long code in comment previews

* Update app/javascript/articles/components/CommentListItem.jsx

---------

Co-authored-by: Ridhwana <Ridhwana.Khan16@gmail.com>
This commit is contained in:
Ben Halpern 2023-05-30 10:02:09 -04:00 committed by GitHub
parent 56414481ba
commit 2fe2c6c6bb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -20,12 +20,13 @@ function contentAwareComments(comment) {
nodes.forEach((node) => {
if (
node.outerHTML &&
node.tagName === 'P' &&
(node.tagName === 'P' || node.className.includes('highlight')) &&
nodesSelected < 2 &&
node.outerHTML.length > 250
&& !node.outerHTML.includes('article-body-image-wrapper')
) {
text = `${text} ${node.outerHTML.substring(0, 230)} ...`;
node.innerHTML = `${node.innerHTML.substring(0, 230)}...`;
text = `${text} ${node.outerHTML}`;
nodesSelected = 2;
} else if (node.outerHTML && nodesSelected < 2) {
text = text + node.outerHTML;