def render_change_entry_html(self, info): old_value = '' new_value = '' if 'old' in info: old_value = info['old'][0] or '' if 'new' in info: new_value = info['new'][0] or '' old_value = render_markdown(old_value) new_value = render_markdown(new_value) old_lines = list(iter_markdown_lines(old_value)) new_lines = list(iter_markdown_lines(new_value)) differ = MyersDiffer(old_lines, new_lines) return ('<table class="diffed-text-area">%s</table>' % ''.join( self._render_all_change_lines(differ, old_lines, new_lines)))
def test_markdown_list_start(self): """Testing iteration of Markdown lists with a 'start' parameter""" # In bug 3715, we were treating the 'start' parameter incorrectly. This # checks that said bug is fixed. rendered = '<ul start="2"><li>x</li><li>y</li></ul>' lines = list(iter_markdown_lines(rendered)) self.assertEqual(lines, [ '<ul start="2"><li>x</li></ul>', '<ul start="3"><li>y</li></ul>', ])
def render_change_entry_html(self, info): old_value = '' new_value = '' if 'old' in info: old_value = info['old'][0] or '' if 'new' in info: new_value = info['new'][0] or '' old_value = render_markdown(old_value) new_value = render_markdown(new_value) old_lines = list(iter_markdown_lines(old_value)) new_lines = list(iter_markdown_lines(new_value)) differ = MyersDiffer(old_lines, new_lines) return ('<table class="diffed-text-area">%s</table>' % ''.join(self._render_all_change_lines(differ, old_lines, new_lines)))
def render_change_entry_html(self, info): """Render a change entry to HTML. This will render a diff of the changed text. This function is expected to return safe, valid HTML. Any values coming from a field or any other form of user input must be properly escaped. Args: info (dict): A dictionary describing how the field has changed. This is guaranteed to have ``new`` and ``old`` keys, but may also contain ``added`` and ``removed`` keys as well. Returns: unicode: The HTML representation of the change entry. """ old_value = '' new_value = '' if 'old' in info: old_value = info['old'][0] or '' if 'new' in info: new_value = info['new'][0] or '' old_value = render_markdown(old_value) new_value = render_markdown(new_value) old_lines = list(iter_markdown_lines(old_value)) new_lines = list(iter_markdown_lines(new_value)) differ = MyersDiffer(old_lines, new_lines) return ('<table class="diffed-text-area">%s</table>' % ''.join(self._render_all_change_lines(differ, old_lines, new_lines)))
def generate_render(self): with self.obj.file as f: f.open() rendered = render_markdown_from_file(f) try: for line in iter_markdown_lines(rendered): yield line except Exception as e: logging.error('Failed to parse resulting Markdown XHTML for ' 'file attachment %d: %s', self.obj.pk, e, exc_info=True) yield _('Error while rendering Markdown content: %s') % e
def generate_render(self): with self.obj.file as f: f.open() rendered = render_markdown(f.read()) try: for line in iter_markdown_lines(rendered): yield line except Exception as e: logger.error('Failed to parse resulting Markdown XHTML for ' 'file attachment %d: %s', self.obj.pk, e, exc_info=True) yield _('Error while rendering Markdown content: %s') % e
def iter_markdown_lines(markdown_html): """Iterates over lines of Markdown, normalizing for individual display. Generated Markdown HTML cannot by itself be handled on a per-line-basis. Code blocks, for example, will consist of multiple lines of content contained within a <pre> tag. Likewise, lists will be a bunch of <li> tags inside a <ul> tag, and individually do not form valid lists. This function iterates through the Markdown tree and generates self-contained lines of HTML that can be rendered individually. This is deprecated. Please use djblets.markdown.iter_markdown_lines instead. """ warnings.warn( 'reviewboard.reviews.markdown_utils.iter_markdown_lines is ' 'deprecated. Please use djblets.markdown.iter_markdown_lines.', DeprecationWarning) return djblets_markdown.iter_markdown_lines(markdown_html)
def test_markdown_codehilite_blocks(self): """Testing iteration of Markdown codehilite blocks""" rendered = '\n'.join([ '<div class="codehilite"><pre>Line one', 'Line two', 'Line three', 'Line four', '</pre></div>', ]) lines = list(iter_markdown_lines(rendered)) self.assertEqual(lines, [ ('<div class="codehilite codehilite-multiline-start"><pre>' 'Line one</pre></div>'), ('<div class="codehilite codehilite-multiline-middle"><pre>' 'Line two</pre></div>'), ('<div class="codehilite codehilite-multiline-middle"><pre>' 'Line three</pre></div>'), ('<div class="codehilite codehilite-multiline-end"><pre>' 'Line four</pre></div>'), ])