diff --git a/src/sessions/mastodon/compose.py b/src/sessions/mastodon/compose.py index d95cc6c4..b9d9534f 100644 --- a/src/sessions/mastodon/compose.py +++ b/src/sessions/mastodon/compose.py @@ -17,6 +17,11 @@ def compose_post(post, db, settings, relative_times, show_screen_names, safe=Tru text = _("Boosted from @{}: {}").format(post.reblog.account.acct, templates.process_text(post.reblog, safe=safe)) else: text = templates.process_text(post, safe=safe) + # Handle quoted posts + if hasattr(post, 'quote') and post.quote != None and hasattr(post.quote, 'quoted_status') and post.quote.quoted_status != None: + quoted_user = post.quote.quoted_status.account.acct + quoted_text = templates.process_text(post.quote.quoted_status, safe=safe) + text = text + " " + _("Quoting @{}: {}").format(quoted_user, quoted_text) filtered = utils.evaluate_filters(post=post, current_context="home") if filtered != None: text = _("hidden by filter {}").format(filtered) diff --git a/src/sessions/mastodon/templates.py b/src/sessions/mastodon/templates.py index 0c0083f6..2674bea3 100644 --- a/src/sessions/mastodon/templates.py +++ b/src/sessions/mastodon/templates.py @@ -76,6 +76,13 @@ def render_post(post, template, settings, relative_times=False, offset_hours=0): else: text = process_text(post, safe=False) safe_text = process_text(post) + # Handle quoted posts + if hasattr(post, 'quote') and post.quote != None and hasattr(post.quote, 'quoted_status') and post.quote.quoted_status != None: + quoted_user = post.quote.quoted_status.account.acct + quoted_text = process_text(post.quote.quoted_status, safe=False) + quoted_safe_text = process_text(post.quote.quoted_status, safe=True) + text = text + " " + _("Quoting @{}: {}").format(quoted_user, quoted_text) + safe_text = safe_text + " " + _("Quoting @{}: {}").format(quoted_user, quoted_safe_text) filtered = utils.evaluate_filters(post=post, current_context="home") if filtered != None: text = _("hidden by filter {}").format(filtered) diff --git a/src/sessions/mastodon/utils.py b/src/sessions/mastodon/utils.py index 12a8c8fa..05a6303f 100644 --- a/src/sessions/mastodon/utils.py +++ b/src/sessions/mastodon/utils.py @@ -3,23 +3,47 @@ import demoji from html.parser import HTMLParser from datetime import datetime, timezone -url_re = re.compile('') +url_re = re.compile(r'') class HTMLFilter(HTMLParser): + # Classes to ignore when parsing HTML + IGNORED_CLASSES = ["quote-inline"] + text = "" first_paragraph = True + skip_depth = 0 # Track nesting depth of ignored elements def handle_data(self, data): - self.text += data + # Only add data if we're not inside an ignored element + if self.skip_depth == 0: + self.text += data def handle_starttag(self, tag, attrs): - if tag == "br": - self.text = self.text+"\n" - elif tag == "p": - if self.first_paragraph: - self.first_paragraph = False - else: - self.text = self.text+"\n\n" + # Check if this tag has a class that should be ignored + attrs_dict = dict(attrs) + tag_class = attrs_dict.get("class", "") + + # Check if any ignored class is present in this tag + should_skip = any(ignored_class in tag_class for ignored_class in self.IGNORED_CLASSES) + + if should_skip: + self.skip_depth += 1 + elif self.skip_depth == 0: # Only process tags if we're not skipping + if tag == "br": + self.text = self.text+"\n" + elif tag == "p": + if self.first_paragraph: + self.first_paragraph = False + else: + self.text = self.text+"\n\n" + else: + # We're inside a skipped element, increment depth for nested tags + self.skip_depth += 1 + + def handle_endtag(self, tag): + # Decrement skip depth when closing any tag while skipping + if self.skip_depth > 0: + self.skip_depth -= 1 def html_filter(data): f = HTMLFilter()