Skip to content

Commit

Permalink
Add markdown rendering to HTMX
Browse files Browse the repository at this point in the history
  • Loading branch information
fjsj committed Oct 3, 2024
1 parent c98970d commit 1d6377e
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 2 deletions.
4 changes: 4 additions & 0 deletions example/assets/css/htmx_index.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@
[data-loading] {
display: none;
}

#messages-list li p {
margin-bottom: 0;
}
4 changes: 3 additions & 1 deletion example/demo/templates/demo/chat_thread.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% extends "demo/chat_home.html" %}
{% load markdown %}

{% block message_list %}
<div id="messages-container" class="d-flex flex-column">
Expand All @@ -19,7 +20,8 @@
{% if message.type == "ai" %}AI{% else %}User{% endif %}
</strong>
</span>
<span>{{ message.content }}</span>

<span>{{ message.content|markdown }}</span>
</div>
{% endfor %}
</div>
Expand Down
Empty file.
14 changes: 14 additions & 0 deletions example/demo/templatetags/markdown.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from django import template
from django.utils.safestring import mark_safe

from pycmarkgfm import markdown_to_html


register = template.Library()


@register.filter(name="markdown")
def markdown_filter(value):
if value is None:
return ""
return mark_safe(markdown_to_html(value)) # noqa: S308
74 changes: 73 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ langchain-anthropic = "^0.2.1"
langchain-community = "^0.3.1"
gitpython = "^3.1.43"
scikit-learn = "^1.5.2"
pycmarkgfm = "^1.2.1"

[build-system]
requires = ["poetry-core>=1.2.0"]
Expand Down

0 comments on commit 1d6377e

Please sign in to comment.