Files
zulip/zerver/lib/html_diff.py
Anders Kaseorg 365fe0b3d5 python: Sort imports with isort.
Fixes #2665.

Regenerated by tabbott with `lint --fix` after a rebase and change in
parameters.

Note from tabbott: In a few cases, this converts technical debt in the
form of unsorted imports into different technical debt in the form of
our largest files having very long, ugly import sequences at the
start.  I expect this change will increase pressure for us to split
those files, which isn't a bad thing.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-06-11 16:45:32 -07:00

25 lines
652 B
Python

from typing import Optional
import lxml
from lxml.html.diff import htmldiff
def highlight_with_class(text: str, klass: str) -> str:
return f'<span class="{klass}">{text}</span>'
def highlight_html_differences(s1: str, s2: str, msg_id: Optional[int]=None) -> str:
retval = htmldiff(s1, s2)
fragment = lxml.html.fromstring(retval)
for elem in fragment.cssselect('del'):
elem.tag = 'span'
elem.set('class', 'highlight_text_deleted')
for elem in fragment.cssselect('ins'):
elem.tag = 'span'
elem.set('class', 'highlight_text_inserted')
retval = lxml.html.tostring(fragment)
return retval