def test_markdown_unescape(self): """Testing markdown_unescape""" self.assertEqual(markdown_unescape(self.ESCAPED_TEXT), self.UNESCAPED_TEXT) self.assertEqual(markdown_unescape(' code\n' ' code'), (' code\n' ' code')) self.assertEqual(markdown_unescape(' \tcode\n' ' \tcode'), ('\tcode\n' '\tcode'))
def markdown_unescape_field(obj, field_name): """Unescapes Markdown text in a model or dictionary's field. This is a convenience around markdown_unescape to unescape the contents of a particular field in a model or dictionary. """ if isinstance(obj, Model): setattr(obj, field_name, djblets_markdown.markdown_unescape(getattr(obj, field_name))) elif isinstance(obj, dict): obj[field_name] = djblets_markdown.markdown_unescape(obj[field_name]) else: raise TypeError( 'Unexpected type %r passed to markdown_unescape_field' % obj)
def test_markdown_unescape(self): """Testing markdown_unescape""" self.assertEqual(markdown_unescape(self.ESCAPED_TEXT), self.UNESCAPED_TEXT) self.assertEqual( markdown_unescape(' code\n' ' code'), (' code\n' ' code')) self.assertEqual( markdown_unescape(' \tcode\n' ' \tcode'), ('\tcode\n' '\tcode'))
def markdown_unescape(escaped_text): """Unescapes Markdown-escaped text. This will unescape the provided Markdown-formatted text so that any escaped characters will be unescaped. This is deprecated. Please use djblets.markdown.markdown_unescape instead. """ warnings.warn('reviewboard.reviews.markdown_utils.markdown_unescape is ' 'deprecated. Please use djblets.markdown.markdown_unescape.', DeprecationWarning) return djblets_markdown.markdown_unescape(escaped_text)
def markdown_unescape(escaped_text): """Unescapes Markdown-escaped text. This will unescape the provided Markdown-formatted text so that any escaped characters will be unescaped. This is deprecated. Please use djblets.markdown.markdown_unescape instead. """ warnings.warn('reviewboard.reviews.markdown_utils.markdown_unescape is ' 'deprecated. Please use djblets.markdown.markdown_unescape.', RemovedInReviewBoard40Warning) return djblets_markdown.markdown_unescape(escaped_text)
def _normalize_text(self, text, field_is_rich_text, force_text_type): """Normalizes text to the proper format. This considers the requested text format, and whether or not the value should be set for rich text. """ assert force_text_type if text is not None: if force_text_type == self.TEXT_TYPE_PLAIN and field_is_rich_text: text = markdown_unescape(text) elif (force_text_type == self.TEXT_TYPE_MARKDOWN and not field_is_rich_text): text = markdown_escape(text) elif force_text_type == self.TEXT_TYPE_HTML: if field_is_rich_text: text = render_markdown(text) else: text = escape(text) return text
def markdown_email_text(text, is_rich_text): if not is_rich_text: return text return markdown_unescape(text)