From 98a4ebf2e3ab95d48c6c611bf12a9fea976e16ca Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Thu, 15 Apr 2021 18:25:53 +0200 Subject: [PATCH] Revert "Remove code line numbers in RSS" This reverts commit fc7b14192ce94efe97603fb6db31634eaa3efc9e. --- articles/models.py | 9 ++------- articles/tests/test_api_views.py | 4 ++-- articles/utils.py | 12 ++---------- articles/views/feeds.py | 2 +- 4 files changed, 7 insertions(+), 20 deletions(-) diff --git a/articles/models.py b/articles/models.py index 2407152..3fac804 100644 --- a/articles/models.py +++ b/articles/models.py @@ -15,8 +15,7 @@ from django.utils import timezone from articles.utils import ( build_full_absolute_url, - format_article_content_for_html, - format_article_content_for_rss, + format_article_content, get_html_to_text_converter, truncate_words_after_char_count, ) @@ -95,11 +94,7 @@ class Article(models.Model): @cached_property def get_formatted_content(self): - return format_article_content_for_html(self.content) - - @cached_property - def get_formatted_content_for_rss(self): - return format_article_content_for_rss(self.content) + return format_article_content(self.content) def publish(self): if not self.published_at: diff --git a/articles/tests/test_api_views.py b/articles/tests/test_api_views.py index 9a002f3..87c75dd 100644 --- a/articles/tests/test_api_views.py +++ b/articles/tests/test_api_views.py @@ -3,7 +3,7 @@ from django.test import Client from django.urls import reverse from articles.models import Article -from articles.utils import format_article_content_for_html +from articles.utils import format_article_content @pytest.mark.django_db @@ -42,7 +42,7 @@ def test_render_article_change_content(published_article: Article, client: Clien api_res = post_article(client, published_article, preview_content) assert api_res.status_code == 200 api_content = api_res.content.decode("utf-8") # type: str - html_preview_content = format_article_content_for_html(preview_content) + html_preview_content = format_article_content(preview_content) assert html_preview_content in api_content diff --git a/articles/utils.py b/articles/utils.py index 70673ba..5bfc339 100644 --- a/articles/utils.py +++ b/articles/utils.py @@ -15,20 +15,12 @@ def build_full_absolute_url(request, url): return (settings.BLOG["base_url"] + url)[::-1].replace("//", "/", 1)[::-1] -def format_article_content_for_rss(content): - return _format_article_content(content, linenums=False) - - -def format_article_content_for_html(content): - return _format_article_content(content, linenums=True) - - -def _format_article_content(content, linenums: bool): +def format_article_content(content): md = markdown.Markdown( extensions=[ "extra", "admonition", - CodeHiliteExtension(linenums=linenums, guess_lang=False), + CodeHiliteExtension(linenums=True, guess_lang=False), LazyLoadingImageExtension(), ] ) diff --git a/articles/views/feeds.py b/articles/views/feeds.py index 1512cb0..dcc0479 100644 --- a/articles/views/feeds.py +++ b/articles/views/feeds.py @@ -19,7 +19,7 @@ class CompleteFeed(Feed): return self.get_queryset(obj)[: self.FEED_LIMIT] def item_description(self, item: Article): - return item.get_formatted_content_for_rss + return item.get_formatted_content def item_pubdate(self, item: Article): return item.published_at