webhooks/freshdesk/doc.md: Remove unescape_rendered_html kludge.

This reverts commit f476ec7fac (#10312)
and replaces it with a proper fix using Jinja2 raw blocks.

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
Anders Kaseorg 2019-07-02 15:21:17 -07:00 committed by Tim Abbott
parent 9f08513acb
commit 5e97e58df3
6 changed files with 24 additions and 60 deletions

View File

@ -1,5 +0,0 @@
header
{{ render_markdown_path("zerver/tests/markdown/test_unicode_decimals.md", {"unescape_rendered_html": unescape_rendered_html}) }}
footer

View File

@ -1 +0,0 @@
&#123;&#125;

View File

@ -1,4 +1,3 @@
from html import unescape
from typing import Any, Dict, List, Optional
import markdown
@ -148,13 +147,4 @@ def render_markdown_path(markdown_file_path: str,
html = md_engine.convert(markdown_string)
rendered_html = jinja.from_string(html).render(context)
if context.get('unescape_rendered_html', False):
# In some exceptional cases (such as our Freshdesk webhook docs),
# code blocks in some of our Markdown templates have characters such
# as '{' encoded as '&#123;' to prevent clashes with Jinja2 syntax,
# but the encoded form never gets decoded because the text ends up
# inside a <pre> tag. So here, we explicitly "unescape" such characters
# if 'unescape_rendered_html' is True.
rendered_html = unescape(rendered_html)
return mark_safe(rendered_html)

View File

@ -295,22 +295,6 @@ footer
self.assertEqual(content_sans_whitespace,
expected_html_sans_whitespace)
def test_encoded_unicode_decimals_in_markdown_template(self) -> None:
template = get_template("tests/test_unicode_decimals.html")
context = {'unescape_rendered_html': False}
content = template.render(context)
content_sans_whitespace = content.replace(" ", "").replace('\n', '')
self.assertEqual(content_sans_whitespace,
'header<p>&#123;&#125;</p>footer')
context = {'unescape_rendered_html': True}
content = template.render(context)
content_sans_whitespace = content.replace(" ", "").replace('\n', '')
self.assertEqual(content_sans_whitespace,
'header<p>{}</p>footer')
def test_markdown_nested_code_blocks(self) -> None:
template = get_template("tests/test_markdown.html")
context = {

View File

@ -194,14 +194,6 @@ def integration_doc(request: HttpRequest, integration_name: str=REQ(default=None
context['hubot_docs_url'] = integration.hubot_docs_url
if isinstance(integration, EmailIntegration):
context['email_gateway_example'] = settings.EMAIL_GATEWAY_EXAMPLE
if integration.name == 'freshdesk':
# In our Freshdesk docs, some nested code blocks have characters such
# as '{' encoded as '&#123;' to prevent clashes with Jinja2 syntax,
# but the encoded form never gets rendered because the text ends up
# inside a <pre> tag. So here, we explicitly set a directive that
# a particular template should be "unescaped" before being displayed.
# Note that this value is used by render_markdown_path.
context['unescape_rendered_html'] = True
doc_html_str = render_markdown_path(integration.doc, context)

View File

@ -28,20 +28,22 @@ integration!
the following JSON into the **Content** box:
```
{% raw %}
{"freshdesk_webhook":
{
"triggered_event":"&#123;&#123;triggered_event&#125;&#125;",
"ticket_id":"&#123;&#123;ticket.id&#125;&#125;",
"ticket_url":"&#123;&#123;ticket.url&#125;&#125;",
"ticket_type":"&#123;&#123;ticket.ticket_type&#125;&#125;",
"ticket_subject":"&#123;&#123;ticket.subject&#125;&#125;",
"ticket_description":"&#123;&#123;ticket.description&#125;&#125;",
"ticket_status":"&#123;&#123;ticket.status&#125;&#125;",
"ticket_priority":"&#123;&#123;ticket.priority&#125;&#125;",
"requester_name":"&#123;&#123;ticket.requester.name&#125;&#125;",
"requester_email":"&#123;&#123;ticket.requester.email&#125;&#125;",
"triggered_event":"{{triggered_event}}",
"ticket_id":"{{ticket.id}}",
"ticket_url":"{{ticket.url}}",
"ticket_type":"{{ticket.ticket_type}}",
"ticket_subject":"{{ticket.subject}}",
"ticket_description":"{{ticket.description}}",
"ticket_status":"{{ticket.status}}",
"ticket_priority":"{{ticket.priority}}",
"requester_name":"{{ticket.requester.name}}",
"requester_email":"{{ticket.requester.email}}",
}
}
{% endraw %}
```
Click **Save**.
@ -74,20 +76,22 @@ integration!
the following JSON into the **Content** box:
```
{% raw %}
{"freshdesk_webhook":
{
"triggered_event":"&#123;&#123;triggered_event&#125;&#125;",
"ticket_id":"&#123;&#123;ticket.id&#125;&#125;",
"ticket_url":"&#123;&#123;ticket.url&#125;&#125;",
"ticket_type":"&#123;&#123;ticket.ticket_type&#125;&#125;",
"ticket_subject":"&#123;&#123;ticket.subject&#125;&#125;",
"ticket_description":"&#123;&#123;ticket.description&#125;&#125;",
"ticket_status":"&#123;&#123;ticket.status&#125;&#125;",
"ticket_priority":"&#123;&#123;ticket.priority&#125;&#125;",
"requester_name":"&#123;&#123;ticket.requester.name&#125;&#125;",
"requester_email":"&#123;&#123;ticket.requester.email&#125;&#125;",
"triggered_event":"{{triggered_event}}",
"ticket_id":"{{ticket.id}}",
"ticket_url":"{{ticket.url}}",
"ticket_type":"{{ticket.ticket_type}}",
"ticket_subject":"{{ticket.subject}}",
"ticket_description":"{{ticket.description}}",
"ticket_status":"{{ticket.status}}",
"ticket_priority":"{{ticket.priority}}",
"requester_name":"{{ticket.requester.name}}",
"requester_email":"{{ticket.requester.email}}",
}
}
{% endraw %}
```
Click **Save**.