Skip to content

Commit 7ea5e83

Browse files
authored
Strip Markdown from og:description (#537)
1 parent ca05a71 commit 7ea5e83

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

blog/tests.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,3 +286,20 @@ def test_draft_items_not_in_feeds(self):
286286
self.assertContains(response6, draft_entry.title)
287287
self.assertContains(response6, draft_blogmark.link_title)
288288
self.assertContains(response6, draft_quotation.source)
289+
290+
def test_og_description_strips_markdown(self):
291+
blogmark = BlogmarkFactory(commentary="This **has** *markdown*", use_markdown=True)
292+
response = self.client.get(blogmark.get_absolute_url())
293+
self.assertContains(
294+
response,
295+
'<meta property="og:description" content="This has markdown"',
296+
html=False,
297+
)
298+
299+
note = NoteFactory(body="A note with **bold** text")
300+
response2 = self.client.get(note.get_absolute_url())
301+
self.assertContains(
302+
response2,
303+
'<meta property="og:description" content="A note with bold text"',
304+
html=False,
305+
)

templates/blogmark.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
{% endblock %}
1010

1111
{% block card_title %}{{ blogmark.link_title|typography }}{% endblock %}
12-
{% block card_description %}{{ blogmark.commentary|truncatewords:30 }}{% endblock %}
12+
{% block card_description %}{{ blogmark.body|striptags|truncatewords:30 }}{% endblock %}
1313

1414
{% block item_content %}
1515
{% include "_draft_warning.html" %}

templates/note.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
{% endblock %}
99

1010
{% block card_title %}{% if note.title %}{{ note.title }}{% else %}Note on {{ note.created|date:"jS F Y" }}{% endif %}{% endblock %}
11-
{% block card_description %}{{ note.body|truncatewords:30 }}{% endblock %}
11+
{% block card_description %}{{ note.body_rendered|striptags|truncatewords:30 }}{% endblock %}
1212

1313
{% load entry_tags %}
1414
{% block item_content %}

0 commit comments

Comments
 (0)