core.html_diff ============== .. py:module:: core.html_diff .. autoapi-nested-parse:: htmldiff ======== Diffs HTML fragments. Nice to show what changed between two revisions of a document for an arbitrary user. Examples: .. code-block:: pycon >>> from htmldiff import render_html_diff >>> render_html_diff('Foo bar baz', 'Foo bar baz') '
Foo bar baz
' >>> render_html_diff('Foo bar baz', 'Foo baz') '
Foo bar baz
' >>> render_html_diff('Foo baz', 'Foo blah baz') '
Foo blah baz
' :copyright: (c) 2011 by Armin Ronacher :license: BSD Attributes ---------- .. autoapisummary:: core.html_diff.Position core.html_diff._leading_space_re core.html_diff._diff_split_re Classes ------- .. autoapisummary:: core.html_diff.StreamDiffer Functions --------- .. autoapisummary:: core.html_diff.diff_genshi_stream core.html_diff.render_html_diff core.html_diff.parse_html Module Contents --------------- .. py:type:: Position :canonical: tuple[str | None, int, int] .. py:data:: _leading_space_re .. py:data:: _diff_split_re .. py:function:: diff_genshi_stream(old_stream: genshi.core.Stream, new_stream: genshi.core.Stream) -> genshi.core.Stream Renders a creole diff for two texts. .. py:function:: render_html_diff(old: str, new: str, wrapper_element: str = 'div', wrapper_class: str = 'diff') -> markupsafe.Markup Renders the diff between two HTML fragments. .. py:function:: parse_html(html: str, wrapper_element: str = 'div', wrapper_class: str = 'diff') -> genshi.input.ET Parse an HTML fragment into a Genshi stream. .. py:class:: StreamDiffer(old_stream: genshi.input.ET, new_stream: genshi.input.ET) A class that can diff a stream of Genshi events. It will inject ```` and ```` tags into the stream. It probably breaks in very ugly ways if you pass a random Genshi stream to it. I'm not exactly sure if it's correct what creoleparser is doing here, but it appears that it's not using a namespace. That's fine with me so the tags the `StreamDiffer` adds are also unnamespaced. .. py:attribute:: _old :type: list[StreamEvent] .. py:attribute:: _new :type: list[StreamEvent] .. py:attribute:: _result :type: list[StreamEvent] .. py:attribute:: _stack :type: list[str] .. py:attribute:: _context :type: str | None .. py:method:: context(kind: str | None) -> collections.abc.Iterator[None] .. py:method:: inject_class(attrs: genshi.core.Attrs, classname: str) -> genshi.core.Attrs .. py:method:: append(type: genshi.core.StreamEventKind, data: Any, pos: Position) -> None .. py:method:: text_split(text: str) -> list[str] .. py:method:: cut_leading_space(s: str) -> tuple[str, str] .. py:method:: mark_text(pos: Position, text: str, tag: str) -> None .. py:method:: diff_text(pos: Position, old_text: str, new_text: str) -> None .. py:method:: replace(old_start: int, old_end: int, new_start: int, new_end: int) -> None .. py:method:: delete(start: int, end: int) -> None .. py:method:: insert(start: int, end: int) -> None .. py:method:: unchanged(start: int, end: int) -> None .. py:method:: enter(pos: Any, tag: Any, attrs: dict[str, Any]) -> None .. py:method:: enter_mark_replaced(pos: Position, tag: str, attrs: genshi.core.Attrs) -> None .. py:method:: leave(pos: Position, tag: str) -> bool .. py:method:: leave_all() -> None .. py:method:: block_process(events: list[StreamEvent]) -> None .. py:method:: process() -> None .. py:method:: get_diff_stream() -> genshi.core.Stream