mirror of https://github.com/zulip/zulip.git
render_message_backend: Pass realm data into bugdown.
Previously, the way that render_messages was calling bugdown meant that the preview feature didn't have access to realm data like the list of users or streams, resulting in previews for those elements being wrong. Now render_message_backend uses zerver.lib.render_markdown to render messages correctly. [Commit message tweaked and test added by tabbott]
This commit is contained in:
parent
ff1e97603d
commit
e0351948ba
|
@ -843,6 +843,19 @@ class BugdownApiTests(ZulipTestCase):
|
|||
self.assertEqual(data['rendered'],
|
||||
u'<p>That is a <strong>bold</strong> statement</p>')
|
||||
|
||||
def test_render_message_api(self):
|
||||
# type: () -> None
|
||||
content = 'This mentions #**Denmark** and @**King Hamlet**.'
|
||||
result = self.client_get(
|
||||
'/api/v1/messages/render',
|
||||
dict(content=content),
|
||||
**self.api_auth('othello@zulip.com')
|
||||
)
|
||||
self.assert_json_success(result)
|
||||
data = ujson.loads(result.content)
|
||||
self.assertEqual(data['rendered'],
|
||||
u'<p>This mentions <a class="stream" data-stream-id="3" href="/#narrow/stream/Denmark">#Denmark</a> and <span class="user-mention" data-user-email="hamlet@zulip.com">@King Hamlet</span>.</p>')
|
||||
|
||||
class BugdownErrorTests(ZulipTestCase):
|
||||
def test_bugdown_error_handling(self):
|
||||
# type: () -> None
|
||||
|
|
|
@ -29,6 +29,7 @@ from zerver.lib.message import (
|
|||
access_message,
|
||||
MessageDict,
|
||||
extract_message_dict,
|
||||
render_markdown,
|
||||
stringify_message_dict,
|
||||
)
|
||||
from zerver.lib.response import json_success, json_error
|
||||
|
@ -940,7 +941,12 @@ def json_fetch_raw_message(request, user_profile,
|
|||
@has_request_variables
|
||||
def render_message_backend(request, user_profile, content=REQ()):
|
||||
# type: (HttpRequest, UserProfile, text_type) -> HttpResponse
|
||||
rendered_content = bugdown.convert(content, user_profile.realm.domain)
|
||||
message = Message()
|
||||
message.sender = user_profile
|
||||
message.content = content
|
||||
message.sending_client = request.client
|
||||
|
||||
rendered_content = render_markdown(message, content, domain=user_profile.realm.domain)
|
||||
return json_success({"rendered": rendered_content})
|
||||
|
||||
@authenticated_json_post_view
|
||||
|
|
Loading…
Reference in New Issue