Revert "Remove code line numbers in RSS"

This reverts commit fc7b14192c.
This commit is contained in:
Gabriel Augendre 2021-04-15 18:25:53 +02:00
parent 921994d2ad
commit 98a4ebf2e3
4 changed files with 7 additions and 20 deletions

View file

@ -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:

View file

@ -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

View file

@ -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(),
]
)

View file

@ -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