Skip to content

Commit

Permalink
Detect links in description texts and enrich them with html
Browse files Browse the repository at this point in the history
  • Loading branch information
matagus committed Mar 6, 2024
1 parent 9f66b9a commit 6dd26a4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
3 changes: 2 additions & 1 deletion matorral/stories/templates/stories/epic_detail.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% extends 'base.html' %}
{% load stories_tags %}

{% block page_title %}[Epic] {{ object.title }} :: {{ current_workspace }}{% endblock %}

Expand Down Expand Up @@ -59,7 +60,7 @@
</div>

<div class="content">
{{ epic.description|default:''|linebreaksbr }}<br/><br/>
{{ epic.description|default:''|to_html }}<br/><br/>
<div class="field is-grouped is-grouped-multiline">
<div class="control">
<div class="tags has-addons">
Expand Down
3 changes: 2 additions & 1 deletion matorral/stories/templates/stories/story_detail.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% extends 'base.html' %}
{% load stories_tags %}

{% block page_title %}[Story] {{ object.title }} :: {{ current_workspace }}{% endblock %}

Expand Down Expand Up @@ -67,7 +68,7 @@
</div>

<div class="content">
{{ story.description|default:''|linebreaksbr }}<br/><br/>
{{ story.description|default:''|to_html }}<br/><br/>
<div class="field is-grouped is-grouped-multiline">
<div class="control">
<div class="tags has-addons">
Expand Down
Empty file.
18 changes: 18 additions & 0 deletions matorral/stories/templatetags/stories_tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from django import template
from django.utils.safestring import mark_safe as safe


register = template.Library()


@register.filter
def to_html(text):
def replace_links_with_html(text):
import re

Check warning on line 11 in matorral/stories/templatetags/stories_tags.py

View check run for this annotation

Codecov / codecov/patch

matorral/stories/templatetags/stories_tags.py#L10-L11

Added lines #L10 - L11 were not covered by tests

url_re = re.compile(r"(https?://\S+)")
return url_re.sub(r'<a target="_blank" href="\1">\1</a>', text)

Check warning on line 14 in matorral/stories/templatetags/stories_tags.py

View check run for this annotation

Codecov / codecov/patch

matorral/stories/templatetags/stories_tags.py#L13-L14

Added lines #L13 - L14 were not covered by tests

html = replace_links_with_html(text)
html = html.replace("\n", "<br>")
return safe(html)

Check warning on line 18 in matorral/stories/templatetags/stories_tags.py

View check run for this annotation

Codecov / codecov/patch

matorral/stories/templatetags/stories_tags.py#L16-L18

Added lines #L16 - L18 were not covered by tests

0 comments on commit 6dd26a4

Please sign in to comment.