Files
zulip/zerver/lib/realm_description.py
Puneeth Chaganti bfc3e3c0c7 html_to_text: Add delimiters between text from different elements.
This module is used to render the HTML of pages like our user documentation 
into text for use in open graph previews of those articles.  It provided somewhat
confusing output in the case that there were paragraph breaks in the original message,
because text with multiple paragraphs and list items does't read very well. This commit
adds `|` as a delimiter between paragraphs, and prefixes list items with a `*`.

Closes #12228
2019-05-01 17:35:20 -07:00

17 lines
847 B
Python

from zerver.models import Realm
from zerver.lib.cache import cache_with_key, realm_rendered_description_cache_key, \
realm_text_description_cache_key
from zerver.lib.bugdown import convert as bugdown_convert
from zerver.lib.html_to_text import html_to_text
@cache_with_key(realm_rendered_description_cache_key, timeout=3600*24*7)
def get_realm_rendered_description(realm: Realm) -> str:
realm_description_raw = realm.description or "The coolest place in the universe."
return bugdown_convert(realm_description_raw, message_realm=realm,
no_previews=True)
@cache_with_key(realm_text_description_cache_key, timeout=3600*24*7)
def get_realm_text_description(realm: Realm) -> str:
html_description = get_realm_rendered_description(realm)
return html_to_text(html_description, {'p': ' | ', 'li': ' * '})