from django.utils.safestring import mark_safe
from django.utils.translation import ugettext as _

from bootstrap4.utils import render_tag

from .text import text_value


def render_alert(content, alert_type=None, dismissible=True):
    """Render a Bootstrap alert."""
    button = ""
    if not alert_type:
        alert_type = "info"
    css_classes = ["alert", "alert-" + text_value(alert_type)]
    if dismissible:
        css_classes.append("alert-dismissible")
        close = _("close")
        button = f'<button type="button" class="close" data-dismiss="alert" aria-label="{close}">&times;</button>'
    button_placeholder = "__BUTTON__"
    return mark_safe(
        render_tag(
            "div",
            attrs={"class": " ".join(css_classes), "role": "alert"},
            content=button_placeholder + text_value(content),
        ).replace(button_placeholder, button)
    )

src/bootstrap4/components.py
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext as _

from bootstrap4.utils import render_tag

from .text import text_value


def render_alert(content, alert_type=None, dismissible=True):
    """Render a Bootstrap alert."""
    button = ""
    if not alert_type:
        alert_type = "info"
    css_classes = ["alert", "alert-" + text_value(alert_type)]
    if dismissible:
        css_classes.append("alert-dismissible")
        close = _("close")
        button = f'<button type="button" class="close" data-dismiss="alert" aria-label="{close}">&times;</button>'
    button_placeholder = "__BUTTON__"
    return mark_safe(
        render_tag(
            "div",
            attrs={"class": " ".join(css_classes), "role": "alert"},
            content=mark_safe(button_placeholder) + text_value(content),
        ).replace(button_placeholder, button)
    )

src/bootstrap4/components.py
diff --git a/src/bootstrap4/components.py b/src/bootstrap4/components.py
index bc4a58b8..2b38fd5a 100644
--- a/src/bootstrap4/components.py
+++ b/src/bootstrap4/components.py
@@ -21,6 +21,6 @@ def render_alert(content, alert_type=None, dismissible=True):
         render_tag(
             "div",
             attrs={"class": " ".join(css_classes), "role": "alert"},
-            content=button_placeholder + text_value(content),
+            content=mark_safe(button_placeholder) + text_value(content),
         ).replace(button_placeholder, button)
     )
diff --git a/tests/test_components.py b/tests/test_components.py
index d7422670..8eb5a4ac 100644
--- a/tests/test_components.py
+++ b/tests/test_components.py
@@ -1,10 +1,11 @@
 from django.test import TestCase
+from django.utils.safestring import mark_safe
 
 from bootstrap4.components import render_alert
 
 
 class ComponentsTest(TestCase):
-    def test_render_alert_with_type(self):
+    def test_render_alert_without_type(self):
         alert = render_alert("content")
         self.assertEqual(
             alert,
@@ -13,3 +14,35 @@ def test_render_alert_with_type(self):
             + 'aria-label="close">'
             + "&times;</button>content</div>",
         )
+
+    def test_render_alert_with_type(self):
+        alert = render_alert("content", alert_type="danger")
+        self.assertEqual(
+            alert,
+            '<div class="alert alert-danger alert-dismissible" role="alert">'
+            + '<button type="button" class="close" data-dismiss="alert" '
+            + 'aria-label="close">'
+            + "&times;</button>content</div>",
+        )
+
+    def test_render_alert_with_safe_content(self):
+        msg = mark_safe('This is <a href="https://example.com" class="alert-link">a safe link</a>!')
+        alert = render_alert(msg)
+        self.assertEqual(
+            alert,
+            '<div class="alert alert-info alert-dismissible" role="alert">'
+            + '<button type="button" class="close" data-dismiss="alert" '
+            + 'aria-label="close">'
+            + '&times;</button>This is <a href="https://example.com" class="alert-link">a safe link</a>!</div>',
+        )
+
+    def test_render_alert_with_unsafe_content(self):
+        msg = "This is <b>unsafe</b>!"
+        alert = render_alert(msg)
+        self.assertEqual(
+            alert,
+            '<div class="alert alert-info alert-dismissible" role="alert">'
+            + '<button type="button" class="close" data-dismiss="alert" '
+            + 'aria-label="close">'
+            + "&times;</button>This is &lt;b&gt;unsafe&lt;/b&gt;!</div>",
+        )

Putting a link in bootstrap_alert
How do I put a link in `bootstrap_alert`?

```
msg=mark_safe('Please visit our forum site <a href="talk.edgle.com" class="alert-link">Edgle Talk</a> as well!')

render_alert(msg)
'<div class="alert alert-info alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>Please visit our forum site &lt;a href=&quot;talk.edgle.com&quot; class=&quot;alert-link&quot;&gt;Edgle Talk&lt;/a&gt; as well!</div>'
```

As seen, html elements are escaped due to the following chain of commands: 

bootstrap_alert -> render_alert -> render_tag ->format_html -> conditional_escape
