Render News.body as Markdown over the public API
Club staff author body as Markdown in the control panel (help_text now explains the syntax); the public API renders it to sanitized HTML on the way out via news/services.py -- markdown for the conversion, nh3 (Rust/ammonia) to strip anything staff's raw Markdown source might smuggle through (script tags, event handler attributes, javascript: URLs) before it reaches someone else's public website. The control panel's own preview is untouched and still shows the raw source. Excerpt is now derived from the rendered HTML's plain text rather than the raw Markdown source, so syntax like ** or [text](url) doesn't leak into what's meant to be a short teaser.
This commit is contained in:
@@ -26,7 +26,14 @@ class News(ClubScopedModel):
|
||||
slug = models.SlugField(_("slug"), max_length=255, blank=True)
|
||||
slug_source = "title"
|
||||
|
||||
body = models.TextField(_("body"))
|
||||
body = models.TextField(
|
||||
_("body"),
|
||||
help_text=_(
|
||||
"Supports Markdown: **bold**, *italic*, [link text](https://example.com), "
|
||||
"# heading, - list item, > quote. Rendered to HTML for the public website; "
|
||||
"shown as plain text here in the control panel."
|
||||
),
|
||||
)
|
||||
teams = models.ManyToManyField(Team, related_name="news_items", blank=True, verbose_name=_("teams"), help_text=_("Leave empty for club-wide news."))
|
||||
|
||||
visibility = models.CharField(_("visibility"), max_length=10, choices=Visibility.choices, default=Visibility.INTERNAL)
|
||||
|
||||
Reference in New Issue
Block a user