Browse Source

Exclude strikethrough text from comment excerpts

merge-requests/85/head
Deimos 5 years ago
parent
commit
f32c8bbab0
  1. 8
      tildes/tests/test_comment.py
  2. 2
      tildes/tildes/models/comment/comment.py

8
tildes/tests/test_comment.py

@ -130,6 +130,14 @@ def test_comment_excerpt_excludes_blockquote(topic, session_user):
assert comment.excerpt == "Yeah, I agree."
def test_comment_excerpt_excludes_del(topic, session_user):
"""Ensure that comment excerpts don't include text from strikethrough (<del>)."""
markdown = "I really ~~hate~~ love it."
comment = Comment(topic, session_user, markdown)
assert comment.excerpt == "I really love it."
def test_comment_tree(db, topic, session_user):
"""Ensure that building and pruning a comment tree works."""
all_comments = []

2
tildes/tildes/models/comment/comment.py

@ -109,7 +109,7 @@ class Comment(DatabaseModel):
self.rendered_html = convert_markdown_to_safe_html(new_markdown)
extracted_text = extract_text_from_html(
self.rendered_html, skip_tags=["blockquote"]
self.rendered_html, skip_tags=["blockquote", "del"]
)
self.excerpt = truncate_string(
extracted_text, length=200, truncate_at_chars=" "

Loading…
Cancel
Save