Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add markdown rendering to HTMX #178

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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