Class: Docsmith::Diff::Parsers::Html

Inherits:
Renderers::Base show all
Defined in:
lib/docsmith/diff/parsers/html.rb

Overview

HTML-aware diff parser for HTML documents.

Tokenizes so each tag (with its attributes) is one atomic unit and text words are separate units. This keeps the diff engine from splitting <p class="foo"> into angle brackets, attribute names, and values.

"<p>Hello world</p>" → ["<p>", "Hello", "world", "</p>"]

Grouping, offsets, and rendering all come from Renderers::Base — this class only decides where token boundaries fall.

Constant Summary collapse

TAG_OR_WORD =

/<[^>]+>/ any tag:

,

,
,
/[^\s<>]+/ words in text content between tags

/<[^>]+>|[^\s<>]+/

Constants inherited from Renderers::Base

Renderers::Base::NEW_SIDE, Renderers::Base::OLD_SIDE

Instance Method Summary collapse

Methods inherited from Renderers::Base

#compute, #render_html

Instance Method Details

#tokenize(content) ⇒ Array<Array(String, Integer)>

Returns [token, start_offset] pairs.

Parameters:

  • content (String)

Returns:

  • (Array<Array(String, Integer)>)

    [token, start_offset] pairs



25
26
27
# File 'lib/docsmith/diff/parsers/html.rb', line 25

def tokenize(content)
  scan_with_offsets(content, TAG_OR_WORD)
end